From f963b9cab28b4fc70c3cd9d5a4234baf0aae1c77 Mon Sep 17 00:00:00 2001 From: juko Date: Thu, 30 Apr 2020 01:28:12 +0000 Subject: [PATCH] added a new label on the menu to allow the user to take advantage of the latest updates and make a quick upgrade the button will be available only if a recent version is published and allows more autonomy for the user On branch core_contrib Changes to be committed: new file: .gitignore renamed: logo-t.png -> Imgs/logo-t.png renamed: main.png -> Imgs/main.png renamed: menu.png -> Imgs/menu.png renamed: options.png -> Imgs/options.png modified: README.md modified: bashtop --- .gitignore | 2 + logo-t.png => Imgs/logo-t.png | Bin main.png => Imgs/main.png | Bin menu.png => Imgs/menu.png | Bin options.png => Imgs/options.png | Bin README.md | 16 +-- bashtop | 171 ++++++++++++++++++++++++-------- 7 files changed, 143 insertions(+), 46 deletions(-) create mode 100644 .gitignore rename logo-t.png => Imgs/logo-t.png (100%) rename main.png => Imgs/main.png (100%) rename menu.png => Imgs/menu.png (100%) rename options.png => Imgs/options.png (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63a80a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +DEB/bashtop_* +DEB/usr/* diff --git a/logo-t.png b/Imgs/logo-t.png similarity index 100% rename from logo-t.png rename to Imgs/logo-t.png diff --git a/main.png b/Imgs/main.png similarity index 100% rename from main.png rename to Imgs/main.png diff --git a/menu.png b/Imgs/menu.png similarity index 100% rename from menu.png rename to Imgs/menu.png diff --git a/options.png b/Imgs/options.png similarity index 100% rename from options.png rename to Imgs/options.png diff --git a/README.md b/README.md index c0c3e1e..d4cf218 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# ![bashtop](logo-t.png) +# ![bashtop](Imgs/logo-t.png) -**Usage:** Linux resource monitor -**Language:** Bash +![os](https://img.shields.io/badge/Os-Linux-yellow) +![usage](https://img.shields.io/badge/Usage-Linux%20resource%20monitor-red) +![Bash](https://img.shields.io/badge/Bash-v4.4%5E-blue) +![bashtop_version](https://img.shields.io/badge/BashTop-v0.8.17-brightgreen) ## Index @@ -9,7 +11,7 @@ * [Description](#description) * [Features](#features) * [Themes](#themes) -* [Upcoming](#upcoming-(osx-and-bsd-support)) +* [Upcoming](#upcoming-(osx-and-bsd-support) * [Support and funding](#support-and-funding) (Updated) * [Compatibility](#compatibility) (Updated) * [Dependencies](#dependencies) @@ -100,13 +102,13 @@ Bash version 5 is highly recommended to make use of $EPOCHREALTIME variable inst ## Screenshots Main UI showing details for a selected process. -![Screenshot 1](main.png) +![Screenshot 1](Imgs/main.png) Main menu. -![Screenshot 2](menu.png) +![Screenshot 2](Imgs/menu.png) Options menu. -![Screenshot 3](options.png) +![Screenshot 3](Imgs/options.png) ## Installation diff --git a/bashtop b/bashtop index 0bc439a..f7aa151 100755 --- a/bashtop +++ b/bashtop @@ -44,7 +44,7 @@ if [[ "$system" != "Linux" ]]; then fi #* Fail if Bash version is below 4.4 -bash_version_major="$(echo $BASH_VERSION | cut -d "." -f 1)" +bash_version_major="$(echo $BASH_VERSINFO)" bash_version_minor="$(echo $BASH_VERSION | cut -d "." -f 2)" if [[ "$bash_version_major" -lt 4 ]] || [[ "$bash_version_major" == 4 && "$bash_version_minor" -lt 4 ]]; then echo "ERROR: Bash 4.4 or later is required (you are using Bash $bash_version_major.$bash_version_minor)." @@ -64,7 +64,7 @@ banner=( "██╔══██╗██╔══██║╚════██║██╔══██║ ██║ ██║ ██║██╔═══╝ " "██████╔╝██║ ██║███████║██║ ██║ ██║ ╚██████╔╝██║ " "╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ") -declare version="0.8.16" +declare version="0.8.17" declare banner_width=${#banner[0]} banner_colors=("#E62525" "#CD2121" "#B31D1D" "#9A1919" "#801414") @@ -118,6 +118,11 @@ menu_quit=( "┌─┐ ┬ ┬ ┬┌┬┐" "│─┼┐│ │ │ │ " "└─┘└└─┘ ┴ ┴ ") +menu_update=( +"┬ ┬┌─┐┌┬┐┌─┐┌┬┐┌─┐" +"│ │├─┘ ││├─┤ │ ├┤ " +"└─┘┴ ─┴┘┴ ┴ ┴ └─┘" +) menu_options_selected=( "╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗" @@ -132,6 +137,13 @@ menu_quit_selected=( "║═╬╗║ ║ ║ ║ " "╚═╝╚╚═╝ ╩ ╩ ") +menu_update_selected=( +"*┬ ┬┌─┐┌┬┐┌─┐┌┬┐┌─┐" +" │ │├─┘ ││├─┤ │ ├┤ " +" └─┘┴ ─┴┘┴ ┴ ┴ └─┘" +) + +declare -r remote_src="https://raw.githubusercontent.com/aristocratos/bashtop/master/$(basename $0)" declare -A cpu mem swap proc net box theme declare -a cpu_usage cpu_graph_a cpu_graph_b color_meter color_temp_graph color_cpu color_cpu_graph cpu_history color_mem_graph color_swap_graph declare -a mem_history swap_history net_history_download net_history_upload mem_graph swap_graph proc_array download_graph upload_graph trace_array @@ -144,6 +156,7 @@ declare time_left timestamp_start timestamp_end timestamp_input_start timestamp_ declare no_epoch proc_det proc_misc2 sleeping=0 detail_mem_graph proc_det2 proc_out curled git_version declare esc_character tab backspace sleepy late_update skip_process_draw winches quitting theme_int declare -a disks_free disks_total disks_name disks_free_percent saved_key themes +declare -a menus=("options" "help" "quit") color printf -v esc_character "\u1b" printf -v tab "\u09" printf -v backspace "\u7F" @@ -226,6 +239,12 @@ init_() { #? Collect needed information and set options before startig main loop proc[pid_len]=${#proc[pid_max]} if [[ ${proc[pid_len]} -lt 5 ]]; then proc[pid_len]=5; fi + #* Wait for resize if terminal size is smaller then 80x24 + if (($tty_width<80 | $tty_height<24)); then resized; fi + + #* Calculate sizes of boxes + calc_sizes + #* Call init for cpu data collection collect_cpu init @@ -260,8 +279,13 @@ init_() { #? Collect needed information and set options before startig main loop ((++y)) done print -v banner_out[y] -rs -fg cc -b "← esc" - if [[ -n $git_version && $git_version != "$version" ]]; then print -v banner_out[y] -rs -fg "#80cc80" -r 15 "[${git_version} available!]" -r $((9-${#git_version})) - else print -v banner_out[y] -r 37; fi + [[ -n $git_version && $git_version != "$version" ]] && { + # toggle update label menu only if new version is available + menus+=("update") + print -v banner_out[y] -rs -fg "#80cc80" -r 15 "[${git_version} available!]" -r $((9-${#git_version})) + }||{ + print -v banner_out[y] -r 37; + } print -v banner_out[y] -fg cc -i -b "Version: ${version}" -rs unset 'banner[@]' banner=("${banner_out[@]}") @@ -287,13 +311,6 @@ init_() { #? Collect needed information and set options before startig main loop unset 'proc[reverse]' fi - #* Wait for resize if terminal size is smaller then 80x25 - if (($tty_width<80 | $tty_height<25)); then resized; fi - - #* Calculate sizes of boxes - calc_sizes - - #* Call init for processes data collection proc[selected]=0 proc[page]=1 @@ -426,6 +443,40 @@ quit_() { #? Clean exit exit 0 } +update_ () { # update label menu to upgrade to new version + + local -a root_binary_path=("/bin/" "/usr/bin/") + local src=$(basename $0) + local path + + # the update menu is also availabe inside cloned repository + # if bashtop is installed in the system the update menu will be also available + #+ to get the lastest feature or new update version + if [[ ! -d .git ]] ; then + for xbin in ${root_binary_path[@]} ; do + [[ -x ${xbin}${src} ]]&& path=${xbin}${src} + done + else + path=${src} + fi + + [[ -n ${path} ]] && { + curl ${remote_src} -o ${path} + test $? -eq 0 && { + [[ -x ${root_binary_path[1]}notify-send ]] && { + notify-send --urgency=normal "${src} updated to v${version}" + } + # remove update label from the menu if it's in recent version + unset 'menus[${#menus[@]}-1]' + }|| { + [[ -x ${root_binary_path[1]}notify-send ]] && { + notify-send --urgency=critical "UPDATE FAILED : try to run as root to make update !" + } + } + } + +} + sleep_() { #? Restore terminal options, stop and send to background if caught SIGTSTP (ctrl+z) tput rmcup stty echo @@ -470,7 +521,7 @@ resized() { #? Get new terminal size if terminal is resized unset winches while ((++winches<5)); do read tty_height tty_width < <(stty size) - if (($tty_width<80 | $tty_height<25)); then + if (($tty_width<80 | $tty_height<24)); then size_error_msg winches=0 else @@ -488,7 +539,7 @@ size_error_msg() { #? Shows error message if terminal size is below 80x25 tput clear create_box -full -lc "#EE2020" -title "resize window" print -rs -m $((tty_height/2-1)) 2 -fg ${theme[title]} -c -l 11 "Current size: " -bg "#00" -fg dd2020 -d 1 -c "${tty_width}x${tty_height}" -rs - print -d 1 -fg ${theme[title]} -c -l 15 "Need to be atleast:" -bg "#00" -fg 30dd50 -d 1 -c "80x25" -rs + print -d 1 -fg ${theme[title]} -c -l 15 "Need to be atleast:" -bg "#00" -fg 30dd50 -d 1 -c "80x24" -rs while [[ $(stty size) == "$tty_height $tty_width" ]]; do sleep 0.2; done } @@ -722,6 +773,8 @@ get_value() { #? Get a value from a file, variable or array by searching for a n shift done + found="" + if [[ -z $input ]]; then return 1; fi if [[ -z $line_nr && -z $key ]]; then line_nr=1; fi @@ -1404,28 +1457,71 @@ collect_cpu() { #? Collects cpu stats from /proc/stat and compares with previous } collect_cpu_temps() { #? Collect cpu temperatures - local unit i it c div threads=${cpu[threads]} sens_var + local unit c div threads=${cpu[threads]} sens_var i it ccd_value breaking core_value + local -a ccd_array core_array #* Fetch output from "sensors" command to a variable sens_var="$(sensors)" - #* Get CPU package temp - if get_value -v 'cpu[temp_0]' -sv "sens_var" -k "Package*:" -mk 1; then - - #* If successful get temperature unit, convert temp to integer and get high, crit and core temps + #* Get CPU package temp for intel cpus + if get_value -v 'cpu[temp_0]' -sv "sens_var" -k "Package*:" -mk 1 || get_value -v 'cpu[temp_0]' -sv "sens_var" -k "Core 0:" -mk 1; then + #* If successful get temperature unit, convert temp to integer and get high and crit cpu[temp_unit]=${cpu[temp_0]:(-2)}; cpu[temp_0]=${cpu[temp_0]%.*}; if [[ ${cpu[temp_0]::1} == "+" ]]; then cpu[temp_0]=${cpu[temp_0]#+}; fi if [[ -z ${cpu[temp_high]} ]]; then - get_value -v 'cpu[temp_high]' -sv "sens_var" -k "Package*high =" -m 2 -r "[^0-9.]" -b -i - get_value -v 'cpu[temp_crit]' -sv "sens_var" -k "Package*crit =" -m 2 -r "[^0-9.]" -b -i + if ! get_value -v 'cpu[temp_high]' -sv "sens_var" -k "Package*high =" -m 2 -r "[^0-9.]" -b -i; then cpu[temp_high]="85"; cpu[temp_crit]=$((cpu[temp_high]+10)) + else get_value -v 'cpu[temp_crit]' -sv "sens_var" -k "Package*crit =" -m 2 -r "[^0-9.]" -b -i; fi fi - for((i=0,it=1;i15)); then @@ -1434,11 +1530,6 @@ collect_cpu_temps() { #? Collect cpu temperatures cpu_temp_history+=("$(( (${cpu[temp_${i}]}-15)*100/(cpu[temp_high]-15) ))") fi done - - - #* If unsuccessful turn off temperature checking - else - check_temp="false" fi } @@ -1448,7 +1539,7 @@ collect_mem() { #? Collect memory information from "/proc/meminfo" if ((mem[counter]<5)); then return; fi mem[counter]=0 - local i tmp value array mem_info + local i tmp value array mem_info height=$((box[mem_height]-2)) local -a mem_array swap_array available=("mem") #* Get memory and swap information from "/proc/meminfo" and calculate percentages @@ -1503,10 +1594,9 @@ collect_mem() { #? Collect memory information from "/proc/meminfo" disks_free+=("$(floating_humanizer -s 1 -B ${line_array[3]})") disks_free_percent+=("$((100-${line_array[4]%'%'}))") + if ((${#disks_name[@]}>=height/2)); then break; fi done - - } collect_processes() { #? Collect process information and calculate accurate cpu usage @@ -2007,7 +2097,7 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages if [[ $check_temp == true ]]; then for((i=0;i<=threads;i++)); do - create_mini_graph -o "cpu_temp_graph_$i" -w 5 -c color_temp_graph "cpu_temp_history_$i" + if [[ -n ${cpu[temp_${i}]} ]]; then create_mini_graph -o "cpu_temp_graph_$i" -w 5 -c color_temp_graph "cpu_temp_history_$i"; fi done fi ((resized++)) @@ -2023,8 +2113,10 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages done if [[ $check_temp == true ]]; then for((i=0;i<=threads;i++)); do - declare -n temp_hist="cpu_temp_history_${i}[-1]" - create_mini_graph -w 5 -c color_temp_graph -add-value "cpu_temp_graph_$i" ${temp_hist} + if [[ -n ${cpu[temp_${i}]} ]]; then + declare -n temp_hist="cpu_temp_history_${i}[-1]" + create_mini_graph -w 5 -c color_temp_graph -add-value "cpu_temp_graph_$i" ${temp_hist} + fi done fi fi @@ -2067,7 +2159,7 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages print -v cpu_out_var -m $((pt_line+y)) $pt_col -rs -fg $p_normal_color -jl 7 -t "$name" -fg ${theme[inactive_fg]} "⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀" -l 10 -t "$meter"\ -fg $cpu_p_color -jr 4 -t "${cpu_usage[i]}" -fg $p_normal_color -t "%" - if [[ $check_temp == true ]]; then + if [[ $check_temp == true && -n ${cpu[temp_${i}]} ]]; then print -v cpu_out_var -fg ${theme[inactive_fg]} " ⡀⡀⡀⡀⡀" -l 7 -t " ${!temp_name}" -fg $temp_color -jr 4 -t ${cpu[temp_${i}]} -fg $p_normal_color -t ${cpu[temp_unit]} fi @@ -2551,7 +2643,7 @@ unpause_() { #? Unpause menu_() { #? Shows the main menu overlay local menu i count keypress selected_int=0 selected up local_rez d_banner=1 menu_out bannerd skipped menu_pause out_out wait_string trans - local -a menus=("options" "help" "quit") color +# local -a menus=("options" "help" "quit") color until false; do @@ -2619,6 +2711,7 @@ menu_() { #? Shows the main menu overlay options) options_ ;; help) help_ ;; quit) quit_ ;; + update)update_;; esac ;; m|M|escape|backspace) break ;;