diff --git a/README.md b/README.md index 69fc0f7..26a5033 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![synth-shell](doc/synth-shell-status.jpg) -**synth-shell-status** shows a summary of your system's current health. +**synth-shell-greeter** shows a summary of your system's current health. - Automatically printed in new terminal sessions (local, SSH, ...). - Monitor your servers, RaspberryPis, and workstations. All system info you need at a glance (e.g. external IP address, CPU temperature, etc.). @@ -18,36 +18,33 @@ # Setup -### Automatic setup + +### Arch Linux + +You may install `synth-shell-greeter` from AUR: +https://aur.archlinux.org/packages/synth-shell-greeter-git/ + + + +### Manual setup The included [setup script](setup.sh) will guide you step by step through the -process and let you choose what features to install. During this setup, you can -choose to install synth-shell for your user only (recommended) or system-wide -(superuser privileges required). To proceed, -[open and play this link in a separate tab](https://www.youtube.com/embed/MpN91wHAr1k) -and enter the following into your terminal: +installatioj process. Just clone this repository and run it: ``` -git clone --recursive https://github.com/andresgongora/synth-shell.git -chmod +x synth-shell/setup.sh -synth-shell/setup.sh +git clone --recursive https://github.com/andresgongora/synth-shell-greeter.git +synth-shell-greeter/setup.sh ``` -Note that for `fancy-bash-prompt.sh` you might also need -[power-line fonts](https://github.com/powerline/fonts). You can instal it -as follows (the exact name of the package varies from distro to distro): - -* ArchLinux: `sudo pacman -S powerline-fonts` -* Debian/Ubuntu: `sudo apt install fonts-powerline` +You can then test your script by running it from wherever you installed it. +Usually this is to your user's `.config` folder, so you should run: +``` +~/.config/synth-shell/synth-shell-greeter.sh +``` -Finally, open up a new terminal and test that everything works. Sometimes, -despite power-line fonts being properly installed, the triangle separator -for `fancy-bash-prompt.sh` (if installed) might still not show. In this case, -make sure that your `locale` is set to UTF-8 by editing `/etc/locale.conf` file -(select your language but in UTF-8 format) and running `sudo locale-gen`. -[More info on locale](https://wiki.archlinux.org/index.php/locale). -Alternatively, try a different font in your terminal emulator. Some fonts -do not support special characters. We get the best results with -[hack-ttf](https://sourcefoundry.org/hack/). +If you want it to appear everytime you open a new terminal, run +``` +echo "~/.config/synth-shell/synth-shell-greeter.sh" >> ~/.bashrc +``` @@ -61,11 +58,6 @@ folders depending on how you installed **synth-shell**: -### Uninstallation -Run the setup script again (like during the installation), but choose -`uninstall` when prompted. - -

@@ -83,9 +75,10 @@ prints a user-configurable ASCII logo to impress your crush from the library with how awesome you are. Feel free to customize your status report through the many available options -in `~/.config/synth-shell/status.config` (user-only install) or -`/etc/synth-shell/status.config` (system-wide install),or by replacing their -content with the examples files you can find under the same directory. +in `~/.config/synth-shell/synth-shell-greeter.config` (user-only install) or +`/etc/synth-shell/synth-shell-greeter.config` (system-wide install), or by +replacing their content with the examples files you can find under the same +directory. ![status configuration options](doc/status_config_preview.png) diff --git a/bash-tools b/bash-tools index a965bca..32fde20 160000 --- a/bash-tools +++ b/bash-tools @@ -1 +1 @@ -Subproject commit a965bca403844ea7f1d8d8179b215a594d426b16 +Subproject commit 32fde20cdca37d54baeb1ab441f20e830d0147d1 diff --git a/config/examples/synth-shell-greeter.org.uma.scbi.config b/config/examples/synth-shell-greeter.org.uma.scbi.config index a8777e7..b7f155e 100644 --- a/config/examples/synth-shell-greeter.org.uma.scbi.config +++ b/config/examples/synth-shell-greeter.org.uma.scbi.config @@ -54,8 +54,8 @@ print_info=" ##============================================================================== ## STATUS BARS ##============================================================================== -memory_units="GB" -swap_units="GB" -hdd_units="GB" -home_units="TB" +bar_memory_units="GB" +bar_swap_units="GB" +bar_hdd_units="GB" +bar_home_units="TB" diff --git a/config/os/synth-shell-greeter.archlinux.config b/config/os/synth-shell-greeter.archlinux.config index d89b6fd..18c7a9a 100644 --- a/config/os/synth-shell-greeter.archlinux.config +++ b/config/os/synth-shell-greeter.archlinux.config @@ -6,25 +6,25 @@ ## - https://wiki.archlinux.org/index.php/ASCII_art ## - https://bbs.archlinux.org/viewtopic.php?id=24208&p=6 -logo=" . +logo="\e[0;94m . \e[0;94m # \e[0;94m ### \e[0;94m ##### -\e[0;94m ###### -\e[0;94m ; #####; -\e[0;94m +##.##### -\e[0;94m +########## +\e[0;94m '###### +\e[0;94m .. #####: +\e[0;94m ###.##### +\e[0;94m ########### \e[0;94m ######\e[0;34m#####\e[0;94m##; -\e[0;94m ###\e[0;34m############\e[0;94m+ +\e[0;94m ###\e[0;34m############\e[0;94m \e[0;94m #\e[0;34m###### ####### -\e[0;34m .######; ;###;\`\". -\e[0;34m .#######; ;#####. -\e[0;34m #########. .########\` -\e[0;34m ######\' \'###### -\e[0;34m ;#### ####; -\e[0;34m ##\' \'## -\e[0;34m #\' \`# -\e[0;34m ' \` " +\e[0;34m ######: :###.\`\". +\e[0;34m #######: :####:. +\e[0;34m :########. .######## +\e[0;34m :#####' '#####: +\e[0;34m :#### ####: +\e[0;34m ##' '## +\e[0;34m #' '# +\e[0;34m ' ' " diff --git a/config/synth-shell-greeter.config.default b/config/synth-shell-greeter.config.default index 6695f3f..79d6c69 100644 --- a/config/synth-shell-greeter.config.default +++ b/config/synth-shell-greeter.config.default @@ -117,31 +117,38 @@ format_logo=" -c blue -e bold" ##============================================================================== ## STATUS BARS ## -## This option controls the behaviour of the visual status bars that are plotted -## for CPU, Memory, Swap and HDD usage. You can set the percentage that +## These option controls the behaviour of the visual status bars that are +## plotted for CPU, Memory, Swap and HDD usage. You can set the percentage that ## determines when the current usage is deemed critical. If said percentage ## is surpassed, the color of the bars will change and extra information ## might be plotted in addition (e.g. if the CPU usage is too high, the most ## demanding processes are printed to terminal). ##============================================================================== -crit_cpu_percent=40 -print_cpu_hogs_num=3 # Num processes to show if CPU usage is high -crit_ram_percent=75 -print_memory_hogs=3 # Num processes to show if memory usage is high -crit_swap_percent=25 -crit_hdd_percent=85 -crit_home_percent=85 +bar_cpu_crit_percent=40 +bar_ram_crit_percent=75 +bar_swap_crit_percent=25 +bar_hdd_crit_percent=85 +bar_home_crit_percent=85 -memory_units="MB" -swap_units="MB" -hdd_units="GB" -home_units="GB" +bar_ram_units="MB" +bar_swap_units="MB" +bar_hdd_units="GB" +bar_home_units="GB" + +cpu_crit_print=true +cpu_crit_print_num=3 +ram_crit_print=true +ram_crit_print_num=3 bar_length=9 # Number of characters that comprise a bar bar_num_digits=5 # Control num digits next to bar +bar_padding_after=0 # Extra spaces after bar info_label_width=16 # Desired length of the info labels - +bar_bracket_char_left='[' +bar_bracket_char_right=']' +bar_fill_char='|' +bar_background_char=' ' ##============================================================================== @@ -158,3 +165,4 @@ print_extra_new_line_top=true # Extra line before logo and info print_extra_new_line_bot=true # Extra line after logo and info + diff --git a/setup.sh b/setup.sh index 8aea7bd..2705f93 100755 --- a/setup.sh +++ b/setup.sh @@ -28,63 +28,41 @@ ##============================================================================== ## -setup() -{ - include() { source "$( cd $( dirname "${BASH_SOURCE[0]}" ) >/dev/null 2>&1 && pwd )/$1" ; } - include 'bash-tools/bash-tools/user_io.sh' - include 'bash-tools/bash-tools/hook_script.sh' - include 'bash-tools/bash-tools/assemble_script.sh' - - - ## SWITCH BETWEEN AUTOMATIC AND USER INSTALLATION - if [ "$#" -eq 0 ]; then - local output_script="$HOME/.config/synth-shell/synth-shell-greeter.sh" - local output_config_dir="$HOME/.config/synth-shell" - cp "$output_config_dir/synth-shell-greeter.config" "$output_config_dir/synth-shell-greeter.config.backup" - printInfo "Installing script as $output_script" - local action=$(promptUser "Add hook your .bashrc file or equivalent?\n\tRequired for autostart on new terminals" "[Y]/[n]?" "yYnN" "y") - case "$action" in - ""|y|Y ) hookScript $output_script ;; - n|N ) ;; - *) printError "Invalid option"; exit 1 - esac +include(){ { [ -z "$_IR" ]&&_IR="$PWD"&&cd "$(dirname "$PWD/$0")"&&include "$1"&&cd "$_IR"&&unset _IR;}||{ local d=$PWD&&cd "$(dirname "$PWD/$1")"&&. "$(basename "$1")"&&cd "$d";}||{ echo "Include failed $PWD->$1"&&exit 1;};} + +include 'bash-tools/bash-tools/user_io.sh' +include 'bash-tools/bash-tools/hook_script.sh' +include 'bash-tools/bash-tools/assemble_script.sh' + + +## SWITCH BETWEEN AUTOMATIC AND USER INSTALLATION +if [ "$#" -eq 0 ]; then + OUTPUT_SCRIPT="$HOME/.config/synth-shell/synth-shell-greeter.sh" + OUTPUT_CONFIG_DIR="$HOME/.config/synth-shell" + cp "$OUTPUT_CONFIG_DIR/synth-shell-greeter.config" \ + "$OUTPUT_CONFIG_DIR/synth-shell-greeter.config.backup" + printInfo "Installing script as $OUTPUT_SCRIPT" + USER_CHOICE=$(promptUser "Add hook your .bashrc file or equivalent?\n\tRequired for autostart on new terminals" "[Y]/[n]?" "yYnN" "y") + case "$USER_CHOICE" in + ""|y|Y ) hookScript $OUTPUT_SCRIPT ;; + n|N ) ;; + *) printError "Invalid option"; exit 1 + esac - else - local output_script="$1" - local output_config_dir="$2" - fi - - - ## DEFINE LOCAL VARIABLES - local dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) - local input_script="$dir/synth-shell-greeter/synth-shell-greeter.sh" - local input_config_dir="$dir/config/" - - - ## HEADER TO BE ADDED AT THE TOP OF THE ASSEMBLED SCRIPT - local output_script_header=$(printf '%s'\ - "##!/bin/bash\n"\ - "\n"\ - "## +-----------------------------------+-----------------------------------+\n"\ - "## | |\n"\ - "## | Copyright (c) 2014-2020, Andres Gongora |\n"\ - "## | https://github.com/andresgongora/synth-shell-greeter |\n"\ - "## | Visit the above URL for details of license and authorship. |\n"\ - "## | |\n"\ - "## | This program is free software: you can redistribute it and/or modify |\n"\ - "## | it under the terms of the GNU General Public License as published by |\n"\ - "## | the Free Software Foundation, either version 3 of the License, or |\n"\ - "## | (at your option) any later version. |\n"\ - "## | |\n"\ - "## | This program is distributed in the hope that it will be useful, |\n"\ - "## | but WITHOUT ANY WARRANTY; without even the implied warranty of |\n"\ - "## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |\n"\ - "## | GNU General Public License for more details. |\n"\ - "## | |\n"\ - "## | You should have received a copy of the GNU General Public License |\n"\ - "## | along with this program. If not, see . |\n"\ - "## | |\n"\ - "## +-----------------------------------------------------------------------+\n"\ +else + OUTPUT_SCRIPT="$1" + OUTPUT_CONFIG_DIR="$2" +fi + + +## DEFINE LOCAL VARIABLES +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) +INPUT_SCRIPT="$DIR/synth-shell-greeter/synth-shell-greeter.sh" +INPUT_CONFIG_DIR="$DIR/config/" + + +## HEADER TO BE ADDED AT THE TOP OF THE ASSEMBLED SCRIPT +OUTPUT_SCRIPT_HEADER=$(printf '%s'\ "##\n"\ "##\n"\ "## =======================\n"\ @@ -93,43 +71,31 @@ setup() "## =======================\n"\ "##\n"\ "## This file was generated by an installation script.\n"\ - "## If you edit this file, it might be overwritten without warning\n"\ - "## and you might lose all your changes.\n"\ + "## It might be overwritten without warning at any time\n"\ + "## and you will lose all your changes.\n"\ "##\n"\ "## Visit for instructions and more information:\n"\ "## https://github.com/andresgongora/synth-shell/\n"\ + "##\n"\ "##\n\n\n") - ## SETUP SCRIPT - assembleScript "$input_script" "$output_script" "$output_script_header" - - - ## SETUP CONFIGURATION FILES - [ -d "$output_config_dir" ] || mkdir -p "$output_config_dir" - cp -r "$input_config_dir/." "$output_config_dir/" - +## SETUP SCRIPT +assembleScript "$INPUT_SCRIPT" "$OUTPUT_SCRIPT" "$OUTPUT_SCRIPT_HEADER" - ## SETUP DEFAULT SYNTH-SHELL-GREETER CONFIG FILE - local config_file="$output_config_dir/synth-shell-greeter.config" - if [ ! -f "$config_file" ]; then - local distro=$(cat /etc/os-release | grep "ID=" | sed 's/ID=//g' | head -n 1) - case "$distro" in - 'arch' ) cp "$output_config_dir/os/synth-shell-greeter.archlinux.config" "$config_file" ;; - 'manjaro' ) cp "$output_config_dir/os/synth-shell-greeter.manjaro.config" "$config_file" ;; - *) cp "$output_config_dir/synth-shell-greeter.config.default" "$config_file" ;; - esac - fi -} +## SETUP CONFIGURATION FILES +[ -d "$OUTPUT_CONFIG_DIR" ] || mkdir -p "$OUTPUT_CONFIG_DIR" +cp -r "$INPUT_CONFIG_DIR/." "$OUTPUT_CONFIG_DIR/" - - - -##============================================================================== -## SCRIPT -##============================================================================== - -setup $@ - +## SETUP DEFAULT SYNTH-SHELL-GREETER CONFIG FILE +CONFIG_FILE="$OUTPUT_CONFIG_DIR/synth-shell-greeter.config" +if [ ! -f "$CONFIG_FILE" ]; then + DISTRO=$(cat /etc/os-release | grep "ID=" | sed 's/ID=//g' | head -n 1) + case "$DISTRO" in + 'arch' ) cp "$OUTPUT_CONFIG_DIR/os/synth-shell-greeter.archlinux.config" "$CONFIG_FILE" ;; + 'manjaro' ) cp "$OUTPUT_CONFIG_DIR/os/synth-shell-greeter.manjaro.config" "$CONFIG_FILE" ;; + *) cp "$OUTPUT_CONFIG_DIR/synth-shell-greeter.config.default" "$CONFIG_FILE" ;; + esac +fi diff --git a/synth-shell-greeter/info.sh b/synth-shell-greeter/info.sh new file mode 100755 index 0000000..34328c0 --- /dev/null +++ b/synth-shell-greeter/info.sh @@ -0,0 +1,444 @@ +#!/bin/bash + +## +-----------------------------------+-----------------------------------+ +## | | +## | Copyright (c) 2019-2020, Andres Gongora . | +## | | +## | This program is free software: you can redistribute it and/or modify | +## | it under the terms of the GNU General Public License as published by | +## | the Free Software Foundation, either version 3 of the License, or | +## | (at your option) any later version. | +## | | +## | This program is distributed in the hope that it will be useful, | +## | but WITHOUT ANY WARRANTY; without even the implied warranty of | +## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +## | GNU General Public License for more details. | +## | | +## | You should have received a copy of the GNU General Public License | +## | along with this program. If not, see . | +## | | +## +-----------------------------------------------------------------------+ + + +## +## DESCRIPTION: +## +## +## + + + +##============================================================================== +## GENERAL DEPENDENCIES +##============================================================================== + +include(){ [ -z "$_IR" ]&&_IR="$PWD"&&cd $( dirname "$PWD/$0" )&&. "$1"&&cd "$_IR"&&unset _IR||. $1;} +include 'info_print_info.sh' +include 'info_about_os.sh' +include 'info_about_hardware.sh' +include 'info_about_network.sh' + + + +##============================================================================== +## ONE LINERS +##============================================================================== + + +printInfoOS() { printInfoLine "OS" "$(getNameOS)" ; } +printInfoKernel() { printInfoLine "Kernel" "$(getNameKernel)" ; } +printInfoShell() { printInfoLine "Shell" "$(getNameShell)" ; } +printInfoDate() { printInfoLine "Date" "$(getDate)" ; } +printInfoUptime() { printInfoLine "Uptime" "$(getUptime)" ; } +printInfoUser() { printInfoLine "User" "$(getUserHost)" ; } +printInfoNumLoggedIn() { printInfoLine "Logged in" "$(getNumberLoggedInUsers)" ; } +printInfoNameLoggedIn() { printInfoLine "Logged in" "$(getNameLoggedInUsers)" ; } + +printInfoCPU() { printInfoLine "CPU" "$(getNameCPU)" ; } +printInfoCPULoad() { printInfoLine "Sys load" "$(getCPULoad)" ; } + +printInfoLocalIPv4() { printInfoLine "Local IPv4" "$(getLocalIPv4)" ; } +printInfoExternalIPv4() { printInfoLine "External IPv4" "$(getExternalIPv4)" ; } + +printInfoSpacer() { printInfoLine "" "" ; } + + + + + + + +##============================================================================== +## +##============================================================================== + +printInfoGPU() +{ + # DETECT GPU(s)set + local gpu_ids=($(lspci 2>/dev/null | grep ' VGA ' | cut -d" " -f 1)) + + # FOR ALL DETECTED IDs + # Get the GPU name, but trim all buzzwords away + for id in "${gpu_ids[@]}"; do + local gpu=$(lspci -v -s "$id" 2>/dev/null |\ + head -n 1 |\ + sed 's/^.*: //g;s/(.*$//g; + s/Generation Core Processor Family Integrated Graphics Controller /gen IGC/g; + s/Corporation//g; + s/Core Processor//g; + s/Series//g; + s/Chipset//g; + s/Graphics//g; + s/processor//g; + s/Controller//g; + s/Family//g; + s/Inc.//g; + s/,//g; + s/Technology//g; + s/Mobility/M/g; + s/Advanced Micro Devices/AMD/g; + s/\[AMD\/ATI\]/ATI/g; + s/Integrated Graphics Controller/HD Graphics/g; + s/Integrated Controller/IC/g; + s/ */ /g' + ) + # If GPU name still to long, remove anything between [] + if [ "${#gpu}" -gt 30 ]; then + local gpu=$(printf "$gpu" | sed 's/\[.*\]//g' ) + fi + + printInfoLine "GPU" "$gpu" + done +} + + + + + + +##============================================================================== +## +##============================================================================== + +##------------------------------------------------------------------------------ +## +printInfoSystemctl() +{ + local systcl_num_failed=$(systemctl --failed |\ + grep "loaded units listed" |\ + head -c 1) + + if [ "$systcl_num_failed" -eq "0" ]; then + local sysctl="All services OK" + local state="nominal" + elif [ "$systcl_num_failed" -eq "1" ]; then + local sysctl="1 service failed!" + local state="error" + else + local sysctl="$systcl_num_failed services failed!" + local state="error" + fi + + printInfoLine "Services" "$sysctl" "$state" +} + + + +##------------------------------------------------------------------------------ +## +printInfoColorpaletteSmall() +{ + local char="▀▀" + + local palette=$(printf '%s'\ + "$(formatText "$char" -c black -b dark-gray)"\ + "$(formatText "$char" -c red -b light-red)"\ + "$(formatText "$char" -c green -b light-green)"\ + "$(formatText "$char" -c yellow -b light-yellow)"\ + "$(formatText "$char" -c blue -b light-blue)"\ + "$(formatText "$char" -c magenta -b light-magenta)"\ + "$(formatText "$char" -c cyan -b light-cyan)"\ + "$(formatText "$char" -c light-gray -b white)") + + printInfoLine "Color palette" "$palette" +} + + + +##------------------------------------------------------------------------------ +## +printInfoColorpaletteFancy() +{ + ## Line 1: ▄▄█ ▄▄█ ▄▄█ ▄▄█ ▄▄█ ▄▄█ ▄▄█ ▄▄█ + ## Line 2: ██▀ ██▀ ██▀ ██▀ ██▀ ██▀ ██▀ ██▀ + + local palette_top=$(printf '%s'\ + "$(formatText "▄" -c dark-gray)$(formatText "▄" -c dark-gray -b black)$(formatText "█" -c black) "\ + "$(formatText "▄" -c light-red)$(formatText "▄" -c light-red -b red)$(formatText "█" -c red) "\ + "$(formatText "▄" -c light-green)$(formatText "▄" -c light-green -b green)$(formatText "█" -c green) "\ + "$(formatText "▄" -c light-yellow)$(formatText "▄" -c light-yellow -b yellow)$(formatText "█" -c yellow) "\ + "$(formatText "▄" -c light-blue)$(formatText "▄" -c light-blue -b blue)$(formatText "█" -c blue) "\ + "$(formatText "▄" -c light-magenta)$(formatText "▄" -c light-magenta -b magenta)$(formatText "█" -c magenta) "\ + "$(formatText "▄" -c light-cyan)$(formatText "▄" -c light-cyan -b cyan)$(formatText "█" -c cyan) "\ + "$(formatText "▄" -c white)$(formatText "▄" -c white -b light-gray)$(formatText "█" -c light-gray) ") + + local palette_bot=$(printf '%s'\ + "$(formatText "██" -c dark-gray)$(formatText "▀" -c black) "\ + "$(formatText "██" -c light-red)$(formatText "▀" -c red) "\ + "$(formatText "██" -c light-green)$(formatText "▀" -c green) "\ + "$(formatText "██" -c light-yellow)$(formatText "▀" -c yellow) "\ + "$(formatText "██" -c light-blue)$(formatText "▀" -c blue) "\ + "$(formatText "██" -c light-magenta)$(formatText "▀" -c magenta) "\ + "$(formatText "██" -c light-cyan)$(formatText "▀" -c cyan) "\ + "$(formatText "██" -c white)$(formatText "▀" -c light-gray) ") + + printInfoLine "" "$palette_top" + printInfoLine "Color palette" "$palette_bot" +} + + + +##------------------------------------------------------------------------------ +## +printInfoCPUTemp() +{ + if ( which sensors > /dev/null 2>&1 ); then + + ## GET VALUES + local temp_line=$(sensors 2>/dev/null |\ + grep Core |\ + head -n 1 |\ + sed 's/^.*:[ \t]*//g;s/[\(\),]//g') + local units=$(echo $temp_line |\ + sed -n 's/.*\(°[[CF]]*\).*/\1/p') + local current=$(echo $temp_line |\ + sed -n 's/^.*+\(.*\)°[[CF]]*[ \t]*h.*/\1/p') + local high=$(echo $temp_line |\ + sed -n 's/^.*high = +\(.*\)°[[CF]]*[ \t]*c.*/\1/p') + local max=$(echo $temp_line |\ + sed -n 's/^.*crit = +\(.*\)°[[CF]]*[ \t]*.*/\1/p') + + + ## DETERMINE STATE + if (( $(echo "$current < $high" |bc -l) )); then + local state="nominal" + elif (( $(echo "$current < $max" |bc -l) )); then + local state="critical"; + else + local state="error"; + fi + + + ## PRINT MESSAGE + local temp="$current$units" + printInfoLine "CPU temp" "$temp" "$state" + else + printInfoLine "CPU temp" "lm-sensors not installed" + fi + + +} + + + +printResourceMonitor() +{ + local label=$1 + local value=$2 + local max=$3 + local units=$4 + local format=$5 + local crit_percent=$6 + local error_percent=${7:-99} + + + ## CHECK STATE + local percent=$('bc' <<< "$value*100/$max") + local state="nominal" + if [ $percent -gt $error_percent ]; then + local state="error" + elif [ $percent -gt $crit_percent ]; then + local state="critical" + fi + + + printInfoMonitor "$label" "$current_value" "$max" "$units" "$format" "$state" +} + + + + +##------------------------------------------------------------------------------ +## +printMonitorCPU() +{ + assert_is_set $bar_cpu_crit_percent + + local format=$1 + local label="Sys load avg" + local units="" + local current_value=$(awk '{avg_1m=($1)} END {printf "%3.2f", avg_1m}' /proc/loadavg) + local max=$(nproc --all) + local crit_percent=$bar_cpu_crit_percent + + printResourceMonitor "$label" "$current_value" "$max" "$units" "$format" "$crit_percent" +} + + + +##------------------------------------------------------------------------------ +## +printMonitorRAM() +{ + assert_is_set $bar_ram_units + assert_is_set $bar_ram_crit_percent + + local format=$1 + local label="Memory" + + case "$bar_ram_units" in + "MB") local units="MB"; local option="--mega" ;; + "TB") local units="TB"; local option="--tera" ;; + "PB") local units="PB"; local option="--peta" ;; + *) local units="GB"; local option="--giga" ;; + esac + + local mem_info=$('free' "$option" | head -n 2 | tail -n 1) + local current_value=$(echo "$mem_info" | awk '{mem=($2-$7)} END {printf mem}') + local max=$(echo "$mem_info" | awk '{mem=($2)} END {printf mem}') + local crit_percent=$bar_ram_crit_percent + + printResourceMonitor "$label" "$current_value" "$max" "$units" "$format" "$crit_percent" +} + + + +##------------------------------------------------------------------------------ +## +printMonitorSwap() +{ + assert_is_set $bar_swap_units + assert_is_set $bar_swap_crit_percent + + local format=$1 + local label="Swap" + + case "$bar_swap_units" in + "MB") local units="MB"; local option="--mega" ;; + "TB") local units="TB"; local option="--tera" ;; + "PB") local units="PB"; local option="--peta" ;; + *) local units="GB"; local option="--giga" ;; + esac + + ## CHECK IF SYSTEM HAS SWAP + ## Count number of lines in /proc/swaps, excluding the header (-1) + ## This is not fool-proof, but if num_swap_devs>=1, there should be swap + local num_swap_devs=$(($(wc -l /proc/swaps | awk '{print $1;}') -1)) + + if [ "$num_swap_devs" -lt 1 ]; then + printInfoLine "$label" "N/A" + + else + local swap_info=$('free' "$option" | tail -n 1) + local current_value=$(echo "$swap_info" | awk '{SWAP=($3)} END {printf SWAP}') + local max=$(echo "$swap_info" | awk '{SWAP=($2)} END {printf SWAP}') + local crit_percent=$bar_swap_crit_percent + + printResourceMonitor "$label" "$current_value" "$max" "$units" "$format" "$crit_percent" + fi +} + + +##------------------------------------------------------------------------------ +## +printStorageMonitor() +{ + local label=$1 + local device=$2 + local units=$3 + local format=$4 + local crit_percent=$5 + local error_percent=${6:-99} + + case "$units" in + "MB") local units="MB"; local option="M" ;; + "TB") local units="TB"; local option="T" ;; + "PB") local units="PB"; local option="P" ;; + *) local units="GB"; local option="G" ;; + esac + + local current_value=$(df "-B1${option}" "${device}" | grep / | awk '{key=($3)} END {printf key}') + local max=$(df "-B1${option}" "${device}" | grep / | awk '{key=($2)} END {printf key}') + printResourceMonitor "$label" "$current_value" "$max" "$units" "$format" "$crit_percent" "$error_percent" + +} + + +##------------------------------------------------------------------------------ +## +printMonitorHDD() +{ + assert_is_set $bar_hdd_units + assert_is_set $bar_hdd_crit_percent + + local format=$1 + local label="Storage /" + local device="/" + local units=$bar_hdd_units + local crit_percent=$bar_hdd_crit_percent + + printStorageMonitor "$label" "$device" "$units" "$format" "$crit_percent" +} + + + +##------------------------------------------------------------------------------ +## +printMonitorHome() +{ + assert_is_set $bar_home_units + assert_is_set $bar_home_crit_percent + + local format=$1 + local label="Storage /home" + local device=$HOME + local units=$bar_home_units + local crit_percent=$bar_home_crit_percent + + printStorageMonitor "$label" "$device" "$units" "$format" "$crit_percent" +} + + + +##------------------------------------------------------------------------------ +## +printMonitorCPUTemp() +{ + if ( which sensors > /dev/null 2>&1 ); then + + ## GET VALUES + local temp_line=$(sensors |\ + grep Core |\ + head -n 1 |\ + sed 's/^.*:[ \t]*//g;s/[\(\),]//g') + local units=$(echo $temp_line |\ + sed -n 's/.*\(°[[CF]]*\).*/\1/p' ) + local current=$(echo $temp_line |\ + sed -n 's/^.*+\(.*\)°[[CF]]*[ \t]*h.*/\1/p' ) + local high=$(echo $temp_line |\ + sed -n 's/^.*high = +\(.*\)°[[CF]]*[ \t]*c.*/\1/p' ) + local max=$(echo $temp_line |\ + sed -n 's/^.*crit = +\(.*\)°[[CF]]*[ \t]*.*/\1/p' ) + local crit_percent=$(bc <<< "$high*100/$max") + + + ## PRINT MONITOR + printResourceMonitor $current $max $crit_percent \ + false $units "CPU temp" + else + printInfoLine "CPU temp" "lm-sensors not installed" + fi +} + + + diff --git a/synth-shell-greeter/info_hardware.sh b/synth-shell-greeter/info_about_hardware.sh similarity index 68% rename from synth-shell-greeter/info_hardware.sh rename to synth-shell-greeter/info_about_hardware.sh index 0d72e63..0f5aa96 100755 --- a/synth-shell-greeter/info_hardware.sh +++ b/synth-shell-greeter/info_about_hardware.sh @@ -60,46 +60,7 @@ getNameCPU() ##============================================================================== ## -getNameGPU() -{ - ## DETECT GPU(s)set - local gpu_id=$(lspci 2>/dev/null | grep ' VGA ' | cut -d" " -f 1) - - ## FOR ALL DETECTED IDs - ## Get the GPU name, but trim all buzzwords away - echo -e "$gpu_id" | while read line ; do - local gpu=$(lspci -v -s "$line" 2>/dev/null |\ - head -n 1 |\ - sed 's/^.*: //g;s/(.*$//g; - s/Corporation//g; - s/Core Processor//g; - s/Series//g; - s/Chipset//g; - s/Graphics//g; - s/processor//g; - s/Controller//g; - s/Family//g; - s/Inc.//g; - s/,//g; - s/Technology//g; - s/Mobility/M/g; - s/Advanced Micro Devices/AMD/g; - s/\[AMD\/ATI\]/ATI/g; - s/Integrated Graphics Controller/HD Graphics/g; - s/Integrated Controller/IC/g; - s/Generation Integrated/Gen IC/g; - s/ */ /g' - ) - - ## If GPU name still to long, remove anything between [] - if [ "${#gpu}" -gt 30 ]; then - local gpu=$(echo "$gpu" | sed 's/\[.*\]//g' ) - fi - - - printf "$gpu" - done -} + diff --git a/synth-shell-greeter/info_network.sh b/synth-shell-greeter/info_about_network.sh similarity index 100% rename from synth-shell-greeter/info_network.sh rename to synth-shell-greeter/info_about_network.sh diff --git a/synth-shell-greeter/info_os.sh b/synth-shell-greeter/info_about_os.sh similarity index 100% rename from synth-shell-greeter/info_os.sh rename to synth-shell-greeter/info_about_os.sh diff --git a/synth-shell-greeter/info_print_info.sh b/synth-shell-greeter/info_print_info.sh new file mode 100755 index 0000000..5adfdfa --- /dev/null +++ b/synth-shell-greeter/info_print_info.sh @@ -0,0 +1,204 @@ +#!/bin/bash + +## +-----------------------------------+-----------------------------------+ +## | | +## | Copyright (c) 2019-2020, Andres Gongora . | +## | | +## | This program is free software: you can redistribute it and/or modify | +## | it under the terms of the GNU General Public License as published by | +## | the Free Software Foundation, either version 3 of the License, or | +## | (at your option) any later version. | +## | | +## | This program is distributed in the hope that it will be useful, | +## | but WITHOUT ANY WARRANTY; without even the implied warranty of | +## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +## | GNU General Public License for more details. | +## | | +## | You should have received a copy of the GNU General Public License | +## | along with this program. If not, see . | +## | | +## +-----------------------------------------------------------------------+ + + +## +## DESCRIPTION: +## +## +## + + + +##============================================================================== +## DEPENDENCIES +##============================================================================== + +include(){ [ -z "$_IR" ]&&_IR="$PWD"&&cd $( dirname "$PWD/$0" )&&. "$1"&&cd "$_IR"&&unset _IR||. $1;} +include '../bash-tools/bash-tools/print_bar.sh' +include '../bash-tools/bash-tools/assert.sh' + + + + + + +##============================================================================== +## HELPERS +##============================================================================== + + + +##============================================================================== +## _getStateColor() +## Select color formating code according to state: +## nominal/critical/error +## +_getStateColor() +{ + assert_is_set $fc_ok + assert_is_set $fc_info + assert_is_set $fc_deco + assert_is_set $fc_crit + assert_is_set $fc_error + + local state=$1 + local E_PARAM_ERR=98 + local fc_none="\e[0m" + + case $state in + nominal) echo $fc_ok ;; + critical) echo $fc_crit ;; + error) echo $fc_error ;; + *) echo $fc_none ; exit $E_PARAM_ERR + esac + +} + + + + + + + +##============================================================================== +## FUNCTIONS +##============================================================================== + + + +##============================================================================== +## printInfoLine() +## Print a formatted message comprised of a label and a value +## +## Arguments: +## 1. LABEL +## 2. VALUE +## +## Optional arguments: +## 3. STATE Determines the color (nominal/critical/error) +## +printInfoLine() +{ + assert_is_set $info_label_width + + + ## ARGUMENTS + local label=$1 + local value=$2 + local state=${3:-nominal} + + + ## FORMAT + local fc_label=${fc_info} + local fc_value=$(_getStateColor $state) + local fc_none="\e[0m" + local padding_label=$info_label_width + + + ## PRINT LABEL AND VALUE + printf "${fc_label}%-${padding_label}s${fc_value}${value}${fc_none}\n" "$label" +} + + + + + + +##============================================================================== +## printMonitor() +## +## Prints a resource utilization monitor, comprised of a bar and a fraction. +## +## 1. CURRENT: current resource utilization (e.g. occupied GB in HDD) +## 2. MAX: max resource utilization (e.g. HDD size) +## 3. CRIT_PERCENT: point at which to warn the user (e.g. 80 for 80%) +## 4. PRINT_AS_PERCENTAGE: whether to print a simple percentage after +## the utilization bar (true), or to print a fraction (false). +## 5. UNITS: units of the resource, for display purposes only. This are +## not shown if PRINT_AS_PERCENTAGE=true, but must be set nonetheless. +## 6. LABEL: A description of the resource that will be printed in front +## of the utilization bar. +## +printInfoMonitor() +{ + assert_is_set $info_label_width + assert_is_set $bar_num_digits + assert_is_set $bar_length + assert_is_set $bar_padding_after + + + ## ARGUMENTS + local label=$1 + local value=$2 + local max=$3 + local units=$4 + local format=${5:-fraction} + local state=${6:-nominal} + + + ## FORMAT OPTIONS + local fc_label=${fc_info} + local fc_value=$(_getStateColor $state) + local fc_units=$fc_info + local fc_fill_color=$fc_value + local fc_bracket_color=$fc_deco + local fc_none="\e[0m" + local padding_label=$info_label_width + local padding_value=$bar_num_digits + local padding_bar=$bar_padding_after + + + ## COMPOSE CHARACTERS FOR BAR + local bracket_left=$fc_bracket_color$bar_bracket_char_left + local fill=$fc_fill_color$bar_fill_char + local background=$fc_none$bar_background_char + local bracket_right=$fc_bracket_color$bar_bracket_char_right$fc_none + + + ## PRINT LABEL + printf "${fc_label}%-${padding_label}s" "$label" + + + ## PRINT BAR + printBar "$value" "$max" "$bar_length" \ + "$bracket_left" "$fill" "$background" "$bracket_right" + printf "%${bar_padding_after}s" "" + + + ## PRINT VALUE + case $format in + "a/b") printf "${fc_value}%${padding_value}s" $value + printf "${fc_deco}/" + printf "${fc_value}%-${padding_value}s" $max + printf "${fc_units} ${units}${fc_none}" + ;; + + '0/0') local percent=$('bc' <<< "$value*100/$max") + printf "${fc_value}%${padding_value}s${fc_units}%%%%${fc_none}" $percent + ;; + + *) echo "Invalid format option $format" + esac +} + + + diff --git a/synth-shell-greeter/synth-shell-greeter.sh b/synth-shell-greeter/synth-shell-greeter.sh index 40b6558..befed05 100755 --- a/synth-shell-greeter/synth-shell-greeter.sh +++ b/synth-shell-greeter/synth-shell-greeter.sh @@ -30,212 +30,65 @@ -greeter() -{ ## INCLUDE EXTERNAL DEPENDENCIES -include() { source "$( cd $( dirname "${BASH_SOURCE[0]}" ) >/dev/null 2>&1 && pwd )/$1" ; } +include(){ { [ -z "$_IR" ]&&_IR="$PWD"&&cd "$(dirname "$PWD/$0")"&&include "$1"&&cd "$_IR"&&unset _IR;}||{ local d=$PWD&&cd "$(dirname "$PWD/$1")"&&. "$(basename "$1")"&&cd "$d";}||{ echo "Include failed $PWD->$1"&&exit 1;};} + include '../bash-tools/bash-tools/color.sh' include '../bash-tools/bash-tools/print_utils.sh' -include '../config/synth-shell-greeter.config.default' -include 'info_os.sh' -include 'info_hardware.sh' -include 'info_network.sh' - - - -##============================================================================== -## INFO AND MONITOR PRINTING HELPERS -##============================================================================== +include 'info.sh' -##------------------------------------------------------------------------------ -## -## printInfo(LABEL, VALUE) -## Print a formatted message comprised of a label and a value -## 1. LABEL will be printed with info color -## 2. VALUE will be printed with highlight color -## -printInfo() -{ - label=$1 - value=$2 - pad=$info_label_width - printf "${fc_info}%-${pad}s${fc_highlight}${value}${fc_none}\n" "$label" -} - - - -##------------------------------------------------------------------------------ -## -## printBar(CURRENT, MAX, SIZE, COLOR, COLOR) -## -## Prints a bar that is filled depending on the relation between -## CURRENT and MAX -## -## 1. CURRENT: amount to display on the bar. -## 2. MAX: amount that means that the bar should be printed -## completely full. -## 3. SIZE: length of the bar as number of characters. -## 4. BRACKET_COLOR: Color for the brackets. May be empty for not colored. -## 5. BAR_COLOR: Color for the bars. May be empty for not colored. -## -printBar() +greeter() { - ## VARIABLES - local current=$1 - local max=$2 - local size=$3 - local bracket_color=$4 - local bar_color=$5 - - - ## COMPUTE VARIABLES - local num_bars=$(bc <<< "$size * $current / $max") - if [ $num_bars -gt $size ]; then - num_bars=$size - fi - - - ## PRINT BAR - ## - Opening bracket - ## - Full bars - ## - Remaining empty space - ## - Closing bracket - printf "${bracket_color}[${bar_color}" - i=0 - while [ $i -lt $num_bars ]; do - printf "|" - i=$[$i+1] - done - while [ $i -lt $size ]; do - printf " " - i=$[$i+1] - done - printf "${bracket_color}]${fc_none}" -} - - -##------------------------------------------------------------------------------ -## -## printFraction(NUMERATOR, DENOMINATOR, PADDING_DIGITS, UNITS) -## -## Prints a color-formatted fraction with padding to reach MAX_DIGITS. -## -## 1. NUMERATOR: first shown number -## 2. DENOMINATOR: second shown number -## 3. PADDING_DIGITS: determines the minimum length of NUMERATOR and -## DENOMINATOR. If they have less digits than this, -## then extra spaces are appended for padding. -## 4. UNITS: a string that is attached to the end of the fraction, -## meant to include optional units (e.g. MB) for display purposes. -## If "none", no units are displayed. -## 5,6,7. COLORS: of decoration (/), numbers, and units. -## -printFraction() -{ - local a=$1 - local b=$2 - local padding=$3 - local units=$4 - local deco_color=$5 - local num_color=$6 - local units_color=$7 - - if [ $units == "none" ]; then local units=""; fi - - printf "${num_color}%${padding}s" $a - printf "${deco_color}/" - printf "${num_color}%-${padding}s" $b - printf "${units_color} ${units}${fc_none}" -} +##============================================================================== +## CONFIGURATION +##============================================================================== -##------------------------------------------------------------------------------ +## LOAD CONFIGURATION +## Load default configuration file with all arguments, then try to load any of +## following in order, until first match, to override some or all config params. +## 1. Apply specific configuration file if specified as argument. +## 2. User specific configuration if in user's home folder. +## 3. If root, apply root configuration file if it exists in the system. +## 4. System wide configuration file if it exists. +## 5. Fall back to defaults. ## -## printMonitor() -## -## Prints a resource utilization monitor, comprised of a bar and a fraction. -## -## 1. CURRENT: current resource utilization (e.g. occupied GB in HDD) -## 2. MAX: max resource utilization (e.g. HDD size) -## 3. CRIT_PERCENT: point at which to warn the user (e.g. 80 for 80%) -## 4. PRINT_AS_PERCENTAGE: whether to print a simple percentage after -## the utilization bar (true), or to print a fraction (false). -## 5. UNITS: units of the resource, for display purposes only. This are -## not shown if PRINT_AS_PERCENTAGE=true, but must be set nonetheless. -## 6. LABEL: A description of the resource that will be printed in front -## of the utilization bar. -## -printMonitor() -{ - ## CHECK EXTERNAL CONFIGURATION - if [ -z $bar_num_digits ]; then exit 1; fi - if [ -z $fc_deco ]; then exit 1; fi - if [ -z $fc_ok ]; then exit 1; fi - if [ -z $fc_info ]; then exit 1; fi - if [ -z $fc_crit ]; then exit 1; fi - - - ## VARIABLES - local current=$1 - local max=$2 - local crit_percent=$3 - local print_as_percentage=$4 - local units=$5 - local label=${@:6} - local pad=$info_label_width - - - ## CHECK VARIABLES - ## If max is empty, assign 0 - ## If crit percent is empty, assign 100 - ## If crit_percent > 100, assign 100 - if [ -z $max ]; then local max=0; fi - if [ -z $crit_percent ]; then local local crit_percent=100; fi - if [ "$crit_percent" -gt 100 ]; then local crit_percent=100; fi - - - ## COMPUTE PERCENT - ## If max=0, then avoid division - ## Otherwise compute as usual - if [ "$max" -eq 0 ]; then - local percent=100 - else - local percent=$(bc <<< "$current*100/$max") - fi +include '../config/synth-shell-greeter.config.default' +local target_config_file="$1" +local user_config_file="~/.config/synth-shell/synth-shell-greeter.config" +local root_config_file="/etc/synth-shell/os/synth-shell-greeter.root.config" +local sys_config_file="/etc/synth-shell/synth-shell-greeter.config" +if [ -f "$target_config_file" ]; then source "$target_config_file" ; +elif [ -f "$user_config_file" ]; then source "$user_config_file" ; +elif [ -f $root_config_file -a "$USER" == "root" ]; then source "$root_config_file" ; +elif [ -f "$sys_config_file" ]; then source "$sys_config_file" ; +else : # Default config already "included" ; +fi - ## SET COLORS DEPENDING ON LOAD - local fc_bar_1=$fc_deco - local fc_bar_2=$fc_ok - local fc_txt_1=$fc_info - local fc_txt_2=$fc_ok - local fc_txt_3=$fc_ok - if [ $percent -gt 99 ]; then - local fc_bar_2=$fc_error - local fc_txt_2=$fc_crit - elif [ $percent -gt $crit_percent ]; then - local fc_bar_2=$fc_crit - local fc_txt_2=$fc_crit - fi - ## PRINT BAR - printf "${fc_info}%-${pad}s" "$label" - printBar $current $max $bar_length $fc_bar_1 $fc_bar_2 +## COLOR AND TEXT FORMAT CODE +local fc_info=$(getFormatCode $format_info) +local fc_highlight=$(getFormatCode $format_highlight) +local fc_crit=$(getFormatCode $format_crit) +local fc_deco=$(getFormatCode $format_deco) +local fc_ok=$(getFormatCode $format_ok) +local fc_error=$(getFormatCode $format_error) +local fc_logo=$(getFormatCode $format_logo) +local fc_none=$(getFormatCode -e reset) +#fc_logo +#fc_ok +#fc_crit +#fc_error +#fc_none +local fc_label="$fc_info" +local fc_text="$fc_highlight" - ## PRINT NUMERIC VALUE - if $print_as_percentage; then - printf "${fc_txt_2}%${bar_num_digits}s${fc_txt_1} %%%%${fc_none}" $percent - else - printf " " - printFraction $current $max $bar_num_digits $units \ - $fc_txt_1 $fc_txt_2 $fc_txt_3 - fi -} @@ -245,329 +98,6 @@ printMonitor() ## INFO ##============================================================================== -printInfoOS() { printInfo "OS" "$(getNameOS)" ; } -printInfoKernel() { printInfo "Kernel" "$(getNameKernel)" ; } -printInfoShell() { printInfo "Shell" "$(getNameShell)" ; } -printInfoDate() { printInfo "Date" "$(getDate)" ; } -printInfoUptime() { printInfo "Uptime" "$(getUptime)" ; } -printInfoUser() { printInfo "User" "$(getUserHost)" ; } -printInfoNumLoggedIn() { printInfo "Logged in" "$(getNumberLoggedInUsers)" ; } -printInfoNameLoggedIn() { printInfo "Logged in" "$(getNameLoggedInUsers)" ; } - -printInfoCPU() { printInfo "CPU" "$(getNameCPU)" ; } -printInfoGPU() { printInfo "GPU" "$(getNameGPU)" ; } -printInfoCPULoad() { printInfo "Sys load" "$(getCPULoad)" ; } - -printInfoLocalIPv4() { printInfo "Local IPv4" "$(getLocalIPv4)" ; } -printInfoExternalIPv4() { printInfo "External IPv4" "$(getExternalIPv4)" ; } - -printInfoSpacer() { printInfo "" "" ; } - - - - -##============================================================================== -## -##============================================================================== - - - -##------------------------------------------------------------------------------ -## -printInfoSystemctl() -{ - local systcl_num_failed=$(systemctl --failed |\ - grep "loaded units listed" |\ - head -c 1) - - if [ "$systcl_num_failed" -eq "0" ]; then - local sysctl="All services OK" - elif [ "$systcl_num_failed" -eq "1" ]; then - local sysctl="${fc_error}1 service failed!${fc_none}" - else - local sysctl="${fc_error}$systcl_num_failed services failed!${fc_none}" - fi - - printInfo "Services" "$sysctl" -} - - - -##------------------------------------------------------------------------------ -## -printInfoColorpaletteSmall() -{ - local char="▀▀" - - local palette=$(printf '%s'\ - "$(formatText "$char" -c black -b dark-gray)"\ - "$(formatText "$char" -c red -b light-red)"\ - "$(formatText "$char" -c green -b light-green)"\ - "$(formatText "$char" -c yellow -b light-yellow)"\ - "$(formatText "$char" -c blue -b light-blue)"\ - "$(formatText "$char" -c magenta -b light-magenta)"\ - "$(formatText "$char" -c cyan -b light-cyan)"\ - "$(formatText "$char" -c light-gray -b white)") - - printInfo "Color palette" "$palette" -} - - - -##------------------------------------------------------------------------------ -## -printInfoColorpaletteFancy() -{ - local palette_top=$(printf '%s'\ - "$(formatText "▄" -c dark-gray)$(formatText "▄" -c dark-gray -b black)$(formatText "█" -c black) "\ - "$(formatText "▄" -c light-red)$(formatText "▄" -c light-red -b red)$(formatText "█" -c red) "\ - "$(formatText "▄" -c light-green)$(formatText "▄" -c light-green -b green)$(formatText "█" -c green) "\ - "$(formatText "▄" -c light-yellow)$(formatText "▄" -c light-yellow -b yellow)$(formatText "█" -c yellow) "\ - "$(formatText "▄" -c light-blue)$(formatText "▄" -c light-blue -b blue)$(formatText "█" -c blue) "\ - "$(formatText "▄" -c light-magenta)$(formatText "▄" -c light-magenta -b magenta)$(formatText "█" -c magenta) "\ - "$(formatText "▄" -c light-cyan)$(formatText "▄" -c light-cyan -b cyan)$(formatText "█" -c cyan) "\ - "$(formatText "▄" -c white)$(formatText "▄" -c white -b light-gray)$(formatText "█" -c light-gray) ") - - local palette_bot=$(printf '%s'\ - "$(formatText "██" -c dark-gray)$(formatText "▀" -c black) "\ - "$(formatText "██" -c light-red)$(formatText "▀" -c red) "\ - "$(formatText "██" -c light-green)$(formatText "▀" -c green) "\ - "$(formatText "██" -c light-yellow)$(formatText "▀" -c yellow) "\ - "$(formatText "██" -c light-blue)$(formatText "▀" -c blue) "\ - "$(formatText "██" -c light-magenta)$(formatText "▀" -c magenta) "\ - "$(formatText "██" -c light-cyan)$(formatText "▀" -c cyan) "\ - "$(formatText "██" -c white)$(formatText "▀" -c light-gray) ") - - printInfo "Color palette" "$palette_top" - printInfo "" "$palette_bot" -} - - - -##------------------------------------------------------------------------------ -## -printInfoCPUTemp() -{ - if ( which sensors > /dev/null 2>&1 ); then - - ## GET VALUES - local temp_line=$(sensors 2>/dev/null |\ - grep Core |\ - head -n 1 |\ - sed 's/^.*:[ \t]*//g;s/[\(\),]//g') - local units=$(echo $temp_line |\ - sed -n 's/.*\(°[[CF]]*\).*/\1/p') - local current=$(echo $temp_line |\ - sed -n 's/^.*+\(.*\)°[[CF]]*[ \t]*h.*/\1/p') - local high=$(echo $temp_line |\ - sed -n 's/^.*high = +\(.*\)°[[CF]]*[ \t]*c.*/\1/p') - local max=$(echo $temp_line |\ - sed -n 's/^.*crit = +\(.*\)°[[CF]]*[ \t]*.*/\1/p') - - - ## COMPOSE MESSAGE - if (( $(echo "$current < $high" |bc -l) )); then - local temp="$current$units"; - elif (( $(echo "$current < $max" |bc -l) )); then - local temp="$fc_crit$current$units"; - else - local temp="$fc_error$current$units"; - fi - - - ## PRINT MESSAGE - printInfo "CPU temp" "$temp" - else - printInfo "CPU temp" "lm-sensors not installed" - fi - - -} - - - -##------------------------------------------------------------------------------ -## -printMonitorCPU() -{ - local message="Sys load avg" - local units="none" - local current=$(awk '{avg_1m=($1)} END {printf "%3.2f", avg_1m}' /proc/loadavg) - local max=$(nproc --all) - - - local as_percentage=$1 - if [ -z "$as_percentage" ]; then local as_percentage=false; fi - - - printMonitor $current $max $crit_cpu_percent \ - $as_percentage $units $message -} - - - -##------------------------------------------------------------------------------ -## -printMonitorRAM() -{ - ## CHOOSE UNITS - case "$memory_units" in - "MB") local units="MB"; local option="--mega" ;; - "TB") local units="TB"; local option="--tera" ;; - "PB") local units="PB"; local option="--peta" ;; - *) local units="GB"; local option="--giga" ;; - esac - - - local message="Memory" - local mem_info=$('free' "$option" | head -n 2 | tail -n 1) - local current=$(echo "$mem_info" | awk '{mem=($2-$7)} END {printf mem}') - local max=$(echo "$mem_info" | awk '{mem=($2)} END {printf mem}') - - - local as_percentage=$1 - if [ -z "$as_percentage" ]; then local as_percentage=false; fi - - - printMonitor $current $max $crit_ram_percent \ - $as_percentage $units $message -} - - - -##------------------------------------------------------------------------------ -## -printMonitorSwap() -{ - ## CHOOSE UNITS - case "$swap_units" in - "MB") local units="MB"; local option="--mebi" ;; - "TB") local units="TB"; local option="--tebi" ;; - "PB") local units="PB"; local option="--pebi" ;; - *) local units="GB"; local option="--gibi" ;; - esac - - - local message="Swap" - local as_percentage=$1 - if [ -z "$as_percentage" ]; then local as_percentage=false; fi - - - ## CHECK IF SYSTEM HAS SWAP - ## Count number of lines in /proc/swaps, excluding the header (-1) - ## This is not fool-proof, but if num_swap_devs>=1, there should be swap - local num_swap_devs=$(($(wc -l /proc/swaps | awk '{print $1;}') -1)) - - if [ "$num_swap_devs" -lt 1 ]; then ## NO SWAP - - - local pad=${info_label_width} - printf "${fc_info}%-${pad}s${fc_highlight}N/A${fc_none}" "${message}" - - else ## HAS SWAP - local swap_info=$('free' "$option" | tail -n 1) - local current=$(echo "$swap_info" |\ - awk '{SWAP=($3)} END {printf SWAP}') - local max=$(echo "$swap_info" |\ - awk '{SWAP=($2)} END {printf SWAP}') - - printMonitor $current $max $crit_swap_percent \ - $as_percentage $units $message - fi -} - - - -##------------------------------------------------------------------------------ -## -printMonitorHDD() -{ - local as_percentage=$1 - if [ -z "$as_percentage" ]; then local as_percentage=false; fi - - - ## CHOOSE UNITS - case "$hdd_units" in - "MB") local units="MB"; local option="M" ;; - "TB") local units="TB"; local option="T" ;; - "PB") local units="PB"; local option="P" ;; - *) local units="GB"; local option="G" ;; - esac - - - local message="Storage /" - local units="GB" - local current=$(df "-B1${option}" / | grep "/" |awk '{key=($3)} END {printf key}') - local max=$(df "-B1${option}" / | grep "/" | awk '{key=($2)} END {printf key}') - - - printMonitor $current $max $crit_hdd_percent \ - $as_percentage $units $message -} - - - -##------------------------------------------------------------------------------ -## -printMonitorHome() -{ - local as_percentage=$1 - if [ -z "$as_percentage" ]; then local as_percentage=false; fi - - - ## CHOOSE UNITS - case "$home_units" in - "MB") local units="MB"; local option="M" ;; - "TB") local units="TB"; local option="T" ;; - "PB") local units="PB"; local option="P" ;; - *) local units="GB"; local option="G" ;; - esac - - - local message="Storage /home" - local current=$(df "-B1${option}" ~ | grep "/" |awk '{key=($3)} END {printf key}') - local max=$(df "-B1${option}" ~ | grep "/" | awk '{key=($2)} END {printf key}') - - - printMonitor $current $max $crit_home_percent \ - $as_percentage $units $message -} - - - -##------------------------------------------------------------------------------ -## -printMonitorCPUTemp() -{ - if ( which sensors > /dev/null 2>&1 ); then - - ## GET VALUES - local temp_line=$(sensors |\ - grep Core |\ - head -n 1 |\ - sed 's/^.*:[ \t]*//g;s/[\(\),]//g') - local units=$(echo $temp_line |\ - sed -n 's/.*\(°[[CF]]*\).*/\1/p' ) - local current=$(echo $temp_line |\ - sed -n 's/^.*+\(.*\)°[[CF]]*[ \t]*h.*/\1/p' ) - local high=$(echo $temp_line |\ - sed -n 's/^.*high = +\(.*\)°[[CF]]*[ \t]*c.*/\1/p' ) - local max=$(echo $temp_line |\ - sed -n 's/^.*crit = +\(.*\)°[[CF]]*[ \t]*.*/\1/p' ) - local crit_percent=$(bc <<< "$high*100/$max") - - - ## PRINT MONITOR - printMonitor $current $max $crit_percent \ - false $units "CPU temp" - else - printInfo "CPU temp" "lm-sensors not installed" - fi -} - - - - @@ -601,24 +131,24 @@ printStatusInfo() PALETTE_SMALL) printInfoColorpaletteSmall;; PALETTE) printInfoColorpaletteFancy;; SPACER) printInfoSpacer;; - CPULOAD) printInfoCPULoad;; + CPULOAD) printInfoCPULoad;; CPUTEMP) printInfoCPUTemp;; ## USAGE MONITORS (BARS) ## NAME FUNCTION AS % - SYSLOAD_MON) printMonitorCPU;; - SYSLOAD_MON%) printMonitorCPU true;; - MEMORY_MON) printMonitorRAM;; - MEMORY_MON%) printMonitorRAM true;; - SWAP_MON) printMonitorSwap;; - SWAP_MON%) printMonitorSwap true;; - HDDROOT_MON) printMonitorHDD;; - HDDROOT_MON%) printMonitorHDD true;; - HDDHOME_MON) printMonitorHome;; - HDDHOME_MON%) printMonitorHome true;; + SYSLOAD_MON) printMonitorCPU 'a/b';; + SYSLOAD_MON%) printMonitorCPU '0/0';; + MEMORY_MON) printMonitorRAM 'a/b';; + MEMORY_MON%) printMonitorRAM '0/0';; + SWAP_MON) printMonitorSwap 'a/b';; + SWAP_MON%) printMonitorSwap '0/0';; + HDDROOT_MON) printMonitorHDD 'a/b';; + HDDROOT_MON%) printMonitorHDD '0/0';; + HDDHOME_MON) printMonitorHome 'a/b';; + HDDHOME_MON%) printMonitorHome '0/0';; CPUTEMP_MON) printMonitorCPUTemp;; - *) printInfo "Unknown" "Check your config";; + *) printInfoLine "Unknown" "Check your config";; esac } @@ -718,21 +248,15 @@ printHogsCPU() { export LC_NUMERIC="C" - ## CHECK GLOBAL PARAMETERS - if [ -z $crit_cpu_percent ]; then return ; fi - if [ -z $print_cpu_hogs_num ]; then local print_cpu_hogs_num=3 ; fi - if [ -z $print_cpu_hogs ]; then return ; fi - - ## EXIT IF NOT ENABLED - if [ "$print_cpu_hogs"==true] ; then + if [ "$cpu_crit_print"==true ]; then ## CHECK CPU LOAD local current=$(awk '{avg_1m=($1)} END {printf "%3.2f", avg_1m}' /proc/loadavg) local max=$(nproc --all) local percent=$(bc <<< "$current*100/$max") - if [ $percent -gt $crit_cpu_percent ]; then + if [ "$percent" -gt "$bar_cpu_crit_percent" ]; then ## CALL TOP IN BATCH MODE ## Check if "%Cpus(s)" is shown, otherwise, call "top -1" ## Escape all '%' characters @@ -753,13 +277,13 @@ printHogsCPU() local header=$(echo "$top" | grep "%CPU" ) local procs=$(echo "$top" |\ sed '/top - /,/%CPU/d' |\ - head -n "$print_cpu_hogs_num" ) + head -n "$cpu_crit_print_num" ) ## PRINT WITH FORMAT printf "\n${fc_crit}SYSTEM LOAD:${fc_info} ${load}\n" printf "${fc_crit}$header${fc_none}\n" - printf "${fc_info}${procs}${fc_none}\n" + printf "${fc_text}${procs}${fc_none}\n" fi fi } @@ -770,21 +294,15 @@ printHogsCPU() ## printHogsMemory() { - ## CHECK GLOBAL PARAMETERS - if [ -z $crit_ram_percent ]; then return; fi - if [ -z $crit_swap_percent ]; then return; fi - if [ -z $print_memory_hogs ]; then local print_memory_hogs=3 ; fi - - ## EXIT IF NOT ENABLED - if [ "$print_memory_hogs"==true ]; then + if [ "$ram_crit_print"==true ]; then ## CHECK RAM local ram_is_crit=false local mem_info=$('free' -m | head -n 2 | tail -n 1) local current=$(echo "$mem_info" | awk '{mem=($2-$7)} END {printf mem}') local max=$(echo "$mem_info" | awk '{mem=($2)} END {printf mem}') local percent=$(bc <<< "$current*100/$max") - if [ $percent -gt $crit_ram_percent ]; then + if [ $percent -gt $bar_ram_crit_percent ]; then local ram_is_crit=true fi @@ -799,7 +317,7 @@ printHogsMemory() local current=$(echo "$swap_info" | awk '{SWAP=($3)} END {printf SWAP}') local max=$(echo "$swap_info" | awk '{SWAP=($2)} END {printf SWAP}') local percent=$(bc <<< "$current*100/$max") - if [ $percent -gt $crit_swap_percent ]; then + if [ $percent -gt $bar_swap_crit_percent ]; then local swap_is_crit=true fi fi @@ -808,7 +326,8 @@ printHogsMemory() if $ram_is_crit || $swap_is_crit ; then local available=$(echo $mem_info | awk '{print $NF}') local procs=$(ps --cols=80 -eo pmem,size,pid,cmd --sort=-%mem |\ - head -n 4 | tail -n 3 |\ + head -n $(($ram_crit_print_num + 1)) |\ + tail -n $ram_crit_print_num |\ awk '{$2=int($2/1024)"MB";} {printf("%5s%8s%8s\t%s\n", $1, $2, $3, $4)}') @@ -826,40 +345,9 @@ printHogsMemory() ##============================================================================== -## MAIN FUNCTION +## MAIN ##============================================================================== - - - - - -## LOAD USER CONFIGURATION -local target_config_file=$1 -local user_config_file="$HOME/.config/synth-shell/synth-shell-greeter.config" -local root_config_file="/etc/synth-shell/os/synth-shell-greeter.root.config" -local sys_config_file="/etc/synth-shell/synth-shell-greeter.config" -if [ -f "$target_config_file" ]; then source "$target_config_file" ; -elif [ -f "$user_config_file" ]; then source "$user_config_file" ; -elif [ -f $root_config_file -a "$USER" == "root" ]; then source "$root_config_file" ; -elif [ -f "$sys_config_file" ]; then source "$sys_config_file" ; -else : # Default config already "included" ; -fi - - - -## COLOR AND TEXT FORMAT CODE -local fc_info=$(getFormatCode $format_info) -local fc_highlight=$(getFormatCode $format_highlight) -local fc_crit=$(getFormatCode $format_crit) -local fc_deco=$(getFormatCode $format_deco) -local fc_ok=$(getFormatCode $format_ok) -local fc_error=$(getFormatCode $format_error) -local fc_logo=$(getFormatCode $format_logo) -local fc_none=$(getFormatCode -e reset) - - - ## PRINT TOP SPACER if $clear_before_print; then clear; fi if $print_extra_new_line_top; then echo ""; fi @@ -888,5 +376,3 @@ if $print_extra_new_line_bot; then echo ""; fi unset greeter - -### EOF ###