From a11873b09962a6ddc85200d76ae0e8b766ae9f29 Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Fri, 28 Oct 2022 19:34:31 +0000 Subject: [PATCH] Update dotfiles/.local/motd.sh, dotfiles/.local/dockerfunc.sh, dotfiles/.local/antigen.zsh --- dotfiles/.local/antigen.zsh | 76 ++-- dotfiles/.local/dockerfunc.sh | 2 +- dotfiles/.local/motd.sh | 772 +++++++++++++++++----------------- 3 files changed, 426 insertions(+), 424 deletions(-) diff --git a/dotfiles/.local/antigen.zsh b/dotfiles/.local/antigen.zsh index e8132076..b39c8dd7 100644 --- a/dotfiles/.local/antigen.zsh +++ b/dotfiles/.local/antigen.zsh @@ -151,7 +151,7 @@ antigen () { # String if record is found -antigen-find-record () { local bundle=$1 - + if [[ $# -eq 0 ]]; then return 1 fi @@ -255,7 +255,7 @@ antigen () { return 0 } -# This function check ZSH_EVAL_CONTEXT to determine if running in interactive shell. +# This function check ZSH_EVAL_CONTEXT to determine if running in interactive shell. # # Usage # -antigen-interactive-mode @@ -283,7 +283,7 @@ antigen () { # Branch name -antigen-parse-branch () { local url="$1" branch="$2" branches - + local match mbegin mend MATCH MBEGIN MEND if [[ "$branch" =~ '\*' ]]; then @@ -466,7 +466,7 @@ antigen () { # Compatibility with oh-my-zsh themes. -antigen-set-default _ANTIGEN_THEME_COMPAT true - + # Add default built-in extensions to load at start up -antigen-set-default _ANTIGEN_BUILTIN_EXTENSIONS 'lock parallel defer cache' @@ -555,7 +555,7 @@ antigen () { if [[ $#list == 0 ]]; then return 1 fi - + # Using a for rather than `source $list` as we need to check for zsh-themes # In order to create antigen-compat file. This is only needed for interactive-mode # theme switching, for static loading (cache) there is no need. @@ -643,7 +643,7 @@ antigen () { shift done - + # Check if url is just the plugin name. Super short syntax. if [[ "${args[url]}" != */* ]]; then case "$ANTIGEN_DEFAULT_REPO_URL" in @@ -728,13 +728,13 @@ antigen () { # if it's local then path is just the "url" argument, loc remains the same args[dir]=${args[url]} fi - + # Escape url and branch (may contain semver-like and pipe characters) args[url]="${(qq)args[url]}" if [[ -n "${args[branch]}" ]]; then args[branch]="${(qq)args[branch]}" fi - + # Escape bundle name (may contain semver-like characters) args[name]="${(qq)args[name]}" @@ -821,7 +821,7 @@ antigen-bundle () { printf "Seems %s is already installed!\n" ${bundle[name]} return 1 fi - + # Clone bundle if we haven't done do already. if [[ ! -d "${bundle[dir]}" ]]; then if ! -antigen-bundle-install ${(kv)bundle}; then @@ -835,7 +835,7 @@ antigen-bundle () { printf "Antigen: Failed to load %s.\n" ${bundle[btype]} >&2 return 1 fi - + # Only add it to the record if it could be installed and loaded. _ANTIGEN_BUNDLE_RECORD+=("$record") } @@ -1326,7 +1326,7 @@ antigen-update () { local url="" local make_local_clone="" local start=$(date +'%s') - + if [[ $# -eq 0 ]]; then printf "Antigen: Missing argument.\n" >&2 return 1 @@ -1340,14 +1340,14 @@ antigen-update () { url="$(echo "$record" | cut -d' ' -f1)" make_local_clone=$(echo "$record" | cut -d' ' -f4) - + local branch="master" if [[ $url == *\|* ]]; then branch="$(-antigen-parse-branch ${url%|*} ${url#*|})" fi printf "Updating %s... " $(-antigen-bundle-short-name "$url" "$branch") - + if [[ $make_local_clone == "false" ]]; then printf "Bundle has no local clone. Will not be updated.\n" >&2 return 1 @@ -1358,7 +1358,7 @@ antigen-update () { printf "Error! Activate logging and try again.\n" >&2 return 1 fi - + local took=$(( $(date +'%s') - $start )) printf "Done. Took %ds.\n" $took } @@ -1410,7 +1410,7 @@ typeset -g _ANTIGEN_EXTENSIONS; _ANTIGEN_EXTENSIONS=() # -antigen-add-hook antigen-apply antigen-apply-hook ["replace"|"pre"|"post"] ["once"|"repeat"] antigen-add-hook () { local target="$1" hook="$2" type="$3" mode="${4:-repeat}" - + if (( ! $+functions[$target] )); then printf "Antigen: Function %s doesn't exist.\n" $target return 1 @@ -1428,7 +1428,7 @@ antigen-add-hook () { fi _ANTIGEN_HOOKS_META[$hook]="target $target type $type mode $mode called 0" - + # Do shadow for this function if there is none already local hook_function="${_ANTIGEN_HOOK_PREFIX}$target" if (( ! $+functions[$hook_function] )); then @@ -1441,7 +1441,7 @@ antigen-add-hook () { return \$? }" fi - + return 0 } @@ -1454,7 +1454,7 @@ antigen-add-hook () { typeset -a pre_hooks replace_hooks post_hooks; typeset -a hooks; hooks=(${(s|:|)_ANTIGEN_HOOKS[$target]}) - + typeset -A meta; for hook in $hooks; do meta=(${(s: :)_ANTIGEN_HOOKS_META[$hook]}) @@ -1500,7 +1500,7 @@ antigen-add-hook () { [[ $? == -1 ]] && WARN "$hook shortcircuited" && return $ret fi done - + if [[ $replace_hook == 0 ]]; then WARN "${_ANTIGEN_HOOK_PREFIX}$target $args" noglob ${_ANTIGEN_HOOK_PREFIX}$target $args @@ -1514,7 +1514,7 @@ antigen-add-hook () { noglob $hook $args [[ $? == -1 ]] && WARN "$hook shortcircuited" && return $ret done - + LOG "Return from hook ${target} with ${ret}" return $ret @@ -1533,7 +1533,7 @@ antigen-remove-hook () { hooks[$hooks[(I)$hook]]=() fi _ANTIGEN_HOOKS[${target}]="${(j|:|)hooks}" - + if [[ $#hooks == 0 ]]; then # Destroy base hook eval "function $(functions -- ${_ANTIGEN_HOOK_PREFIX}$target | sed s/${_ANTIGEN_HOOK_PREFIX}//)" @@ -1554,7 +1554,7 @@ antigen-remove-hook () { eval "function $(functions -- ${_ANTIGEN_HOOK_PREFIX}$target | sed s/${_ANTIGEN_HOOK_PREFIX}//)" unfunction -- "${_ANTIGEN_HOOK_PREFIX}$target" 2> /dev/null done - + _ANTIGEN_HOOKS=() _ANTIGEN_HOOKS_META=() _ANTIGEN_EXTENSIONS=() @@ -1570,14 +1570,14 @@ antigen-ext () { eval $func local ret=$? WARN "$func return code was $ret" - if (( $ret == 0 )); then + if (( $ret == 0 )); then LOG "LOADED EXTENSION $ext" EXT -antigen-$ext-execute && _ANTIGEN_EXTENSIONS+=($ext) else WARN "IGNORING EXTENSION $func" EXT return 1 fi - + else printf "Antigen: No extension defined or already loaded: %s\n" $func >&2 return 1 @@ -1617,7 +1617,7 @@ antigen-ext-init () { return -1 # Stop right there } antigen-add-hook antigen-bundle antigen-bundle-defer replace - + # Hooks antigen-apply in order to release hooked functions antigen-apply-defer () { WARN "Defer pre-apply" DEFER PRE-APPLY @@ -1639,14 +1639,14 @@ antigen-ext-init () { # Default lock path. -antigen-set-default ANTIGEN_LOCK $ADOTDIR/.lock typeset -g _ANTIGEN_LOCK_PROCESS=false - + # Use env variable to determine if we should load this extension -antigen-set-default ANTIGEN_MUTEX true # Set ANTIGEN_MUTEX to false to avoid loading this extension if [[ $ANTIGEN_MUTEX == true ]]; then return 0; fi - + # Do not use mutex return 1; } @@ -1714,7 +1714,7 @@ antigen-ext-init () { else WARN "Bundle ${bundle[name]} already cloned locally." PARALLEL fi - + repositories+=(${bundle[url]}) done @@ -1734,7 +1734,7 @@ antigen-ext-init () { for bundle in ${_PARALLEL_BUNDLE[@]}; do antigen-bundle $bundle done - + WARN "Parallel install done" PARALLEL } @@ -1751,7 +1751,7 @@ antigen-ext-init () { antigen-add-hook antigen-bundle antigen-bundle-parallel replace } antigen-add-hook antigen-apply antigen-apply-parallel pre once - + antigen-apply-parallel-execute () { WARN "Parallel replace-apply" PARALLEL REPLACE-APPLY antigen-remove-hook antigen-bundle-parallel @@ -1872,14 +1872,14 @@ EOC # Cache auto config files to check for changes (.zshrc, .antigenrc etc) -antigen-set-default ANTIGEN_AUTO_CONFIG true - + # Default cache path. -antigen-set-default ANTIGEN_CACHE $ADOTDIR/init.zsh -antigen-set-default ANTIGEN_RSRC $ADOTDIR/.resources if [[ $ANTIGEN_CACHE == false ]]; then return 1 fi - + return 0 } @@ -1911,21 +1911,21 @@ EOC antigen-remove-hook -antigen-load-source-cached antigen-remove-hook antigen-bundle-cached } - + antigen-add-hook antigen-apply antigen-apply-cached post once - + # Defer antigen-bundle. antigen-bundle-cached () { _ZCACHE_CAPTURE_BUNDLE+=("${(j: :)${@}}") } antigen-add-hook antigen-bundle antigen-bundle-cached pre - + # Defer loading. -antigen-load-env-cached () { local bundle typeset -A bundle; bundle=($@) local location=${bundle[dir]}/${bundle[loc]} - + # Load to path if there is no sourceable if [[ ${bundle[loc]} == "/" ]]; then _ZCACHE_BUNDLE_SOURCE+=("${location}") @@ -1935,13 +1935,13 @@ EOC _ZCACHE_BUNDLE_SOURCE+=("${location}") } antigen-add-hook -antigen-load-env -antigen-load-env-cached replace - + # Defer sourcing. -antigen-load-source-cached () { _ZCACHE_BUNDLE_SOURCE+=($@) } antigen-add-hook -antigen-load-source -antigen-load-source-cached replace - + return 0 } diff --git a/dotfiles/.local/dockerfunc.sh b/dotfiles/.local/dockerfunc.sh index 1bb01402..cbe5fb5d 100644 --- a/dotfiles/.local/dockerfunc.sh +++ b/dotfiles/.local/dockerfunc.sh @@ -1,5 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash # Bash wrappers for docker run commands # Source: https://github.com/jessfraz/dotfiles/blob/master/.dockerfunc diff --git a/dotfiles/.local/motd.sh b/dotfiles/.local/motd.sh index aaf33d06..473879ef 100644 --- a/dotfiles/.local/motd.sh +++ b/dotfiles/.local/motd.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # shellcheck disable=SC1090,SC1091 BAR_ELEMENT="-" @@ -76,536 +76,538 @@ LOGIN_IP_ICON="ﯱ" INCLUDE_FILE="ownscript.sh" generate_unit_byte() { - # 1 - unit in M + # 1 - unit in M - if [ "$1" -ge 1024 ]; then - unit_symbol="G" - unit_value=$(echo "$1/1024" | bc -l | LANG=C xargs printf "%.1f\n") - else - unit_symbol="M" - unit_value=$1 - fi + if [ "$1" -ge 1024 ]; then + unit_symbol="G" + unit_value=$(echo "$1/1024" | bc -l | LANG=C xargs printf "%.1f\n") + else + unit_symbol="M" + unit_value=$1 + fi - echo "$unit_value$unit_symbol" + echo "$unit_value$unit_symbol" } generate_space() { - # 1 - already used - # 2 - total + # 1 - already used + # 2 - total - space_fill=$(( $2 - ${#1} )) - space_chars="" + space_fill=$(($2 - ${#1})) + space_chars="" - while [ $space_fill -ge 0 ]; do - space_chars="$space_chars " - space_fill=$(( space_fill - 1 )) - done + while [ $space_fill -ge 0 ]; do + space_chars="$space_chars " + space_fill=$((space_fill - 1)) + done - echo "$space_chars" + echo "$space_chars" } generate_bar() { - # 1 - icon - # 2 - total - # 3 - used_1 - # 4 - [ used_2 ] + # 1 - icon + # 2 - total + # 3 - used_1 + # 4 - [ used_2 ] - bar_percent=$(( $3 * 100 / $2 )) - bar_separator=$(( $3 * 100 * 10 / $2 / 25 )) + bar_percent=$(($3 * 100 / $2)) + bar_separator=$(($3 * 100 * 10 / $2 / 25)) - if [ $bar_percent -ge "$BAR_WARNING_THRESHOLD" ]; then - bar_color=$BAR_WARNING_COLOR - elif [ $bar_percent -ge "$BAR_CRITICAL_THRESHOLD" ]; then - bar_color=$BAR_CRITICAL_COLOR - else - bar_color=$BAR_HEALTHY_COLOR - fi + if [ $bar_percent -ge "$BAR_WARNING_THRESHOLD" ]; then + bar_color=$BAR_WARNING_COLOR + elif [ $bar_percent -ge "$BAR_CRITICAL_THRESHOLD" ]; then + bar_color=$BAR_CRITICAL_COLOR + else + bar_color=$BAR_HEALTHY_COLOR + fi - printf " %s \\033[%dm" "$1" "$bar_color" + printf " %s \\033[%dm" "$1" "$bar_color" - if [ -z "$4" ] ; then - bar_piece=0 - while [ $bar_piece -le 40 ]; do - if [ "$bar_piece" -ne "$bar_separator" ]; then - printf "%s" "$BAR_ELEMENT" - else - printf "%s\\033[1;30m" "$BAR_ELEMENT" - fi + if [ -z "$4" ]; then + bar_piece=0 + while [ $bar_piece -le 40 ]; do + if [ "$bar_piece" -ne "$bar_separator" ]; then + printf "%s" "$BAR_ELEMENT" + else + printf "%s\\033[1;30m" "$BAR_ELEMENT" + fi - bar_piece=$(( bar_piece + 1 )) - done - else - bar_cached_val=$(( $3 + $4 )) - bar_cached_separator=$(( bar_cached_val * 100 * 10 / $2 / 25 )) + bar_piece=$((bar_piece + 1)) + done + else + bar_cached_val=$(($3 + $4)) + bar_cached_separator=$((bar_cached_val * 100 * 10 / $2 / 25)) - bar_piece=0 - while [ $bar_piece -le 40 ]; do - if [ $bar_piece -eq $bar_separator ]; then - printf "%s\\033[1;36m" "$BAR_ELEMENT" - elif [ $bar_piece -eq $bar_cached_separator ]; then - printf "%s\\033[1;30m" "$BAR_ELEMENT" - else - printf "%s" "$BAR_ELEMENT" - fi + bar_piece=0 + while [ $bar_piece -le 40 ]; do + if [ $bar_piece -eq $bar_separator ]; then + printf "%s\\033[1;36m" "$BAR_ELEMENT" + elif [ $bar_piece -eq $bar_cached_separator ]; then + printf "%s\\033[1;30m" "$BAR_ELEMENT" + else + printf "%s" "$BAR_ELEMENT" + fi - bar_piece=$(( bar_piece + 1 )) - done - fi + bar_piece=$((bar_piece + 1)) + done + fi - printf "\\033[0m\\n" + printf "\\033[0m\\n" } generate_bar_memory() { - # 1 - icon - # 2 - total memory in M - # 3 - used memory in M - # 4 - cached memory in M + # 1 - icon + # 2 - total memory in M + # 3 - used memory in M + # 4 - cached memory in M - bar_memory_used=$(generate_unit_byte "$3") - bar_memory_cached=$(generate_unit_byte "$4") - bar_memory_available=$(generate_unit_byte $(( $2 - $3 )) ) + bar_memory_used=$(generate_unit_byte "$3") + bar_memory_cached=$(generate_unit_byte "$4") + bar_memory_available=$(generate_unit_byte $(($2 - $3))) - printf " %s used / %s cached / %s available\\n" "$bar_memory_used" "$bar_memory_cached" "$bar_memory_available" - generate_bar "$1" "$2" "$3" "$4" + printf " %s used / %s cached / %s available\\n" "$bar_memory_used" "$bar_memory_cached" "$bar_memory_available" + generate_bar "$1" "$2" "$3" "$4" } generate_bar_swap() { - # 1 - icon - # 2 - total swap in M - # 3 - used swap in M + # 1 - icon + # 2 - total swap in M + # 3 - used swap in M - bar_swap_used=$(generate_unit_byte "$3") + bar_swap_used=$(generate_unit_byte "$3") - bar_swap_available=$(( $2 - $3 )) - bar_swap_available=$(generate_unit_byte "$bar_swap_available") + bar_swap_available=$(($2 - $3)) + bar_swap_available=$(generate_unit_byte "$bar_swap_available") - printf " %s used / %s available\\n" "$bar_swap_used" "$bar_swap_available" - generate_bar "$1" "$2" "$3" + printf " %s used / %s available\\n" "$bar_swap_used" "$bar_swap_available" + generate_bar "$1" "$2" "$3" } generate_bar_disk() { - # 1 - icon - # 2 - total size in M - # 3 - used space in M - # 4 - mount path + # 1 - icon + # 2 - total size in M + # 3 - used space in M + # 4 - mount path - bar_disk_mount="$4$(generate_space "$4" 10)" + bar_disk_mount="$4$(generate_space "$4" 10)" - bar_disk_used=$(generate_unit_byte "$3") - bar_disk_used="$(generate_space "$bar_disk_used" 5)$bar_disk_used used" + bar_disk_used=$(generate_unit_byte "$3") + bar_disk_used="$(generate_space "$bar_disk_used" 5)$bar_disk_used used" - bar_disk_available=$(( $2 - $3 )) - bar_disk_available="$(generate_unit_byte "$bar_disk_available") available" + bar_disk_available=$(($2 - $3)) + bar_disk_available="$(generate_unit_byte "$bar_disk_available") available" - printf " %s%s / %s\\n" "$bar_disk_mount" "$bar_disk_used" "$bar_disk_available" + printf " %s%s / %s\\n" "$bar_disk_mount" "$bar_disk_used" "$bar_disk_available" - generate_bar "$1" "$2" "$3" + generate_bar "$1" "$2" "$3" } print_banner() { - if [ -e lolcat ]; then - /usr/bin/env figlet "$(hostname)" | /usr/bin/env lolcat -f + if [ -e lolcat ]; then + /usr/bin/env figlet "$(hostname)" | /usr/bin/env lolcat -f + else + printf "\\n%s\\n" "$(figlet -t -f "$BANNER_FONTPATH" " $BANNER_TEXT")" + fi + + if [ -f /etc/os-release ]; then + . /etc/os-release + + if [ "$ID" = "debian" ]; then + banner_distro_icon=$BANNER_DEBIAN_ICON + banner_distro_color=$BANNER_DEBIAN_COLOR + banner_distro_name="Debian" + banner_distro_version=$(cat /etc/debian_version) + elif [ "$ID" = "fedora" ]; then + banner_distro_icon=$BANNER_FEDORA_ICON + banner_distro_color=$BANNER_FEDORA_COLOR + banner_distro_name="Fedora" + banner_distro_version=$VERSION_ID else - printf "\\n%s\\n" "$(figlet -t -f "$BANNER_FONTPATH" " $BANNER_TEXT")" + banner_distro_icon="?" + banner_distro_color="0" + banner_distro_name="Unknown" + banner_distro_version="?" fi - if [ -f /etc/os-release ]; then - . /etc/os-release + banner_distro_space=$(generate_space "$banner_distro_name" 13) - if [ "$ID" = "debian" ]; then - banner_distro_icon=$BANNER_DEBIAN_ICON - banner_distro_color=$BANNER_DEBIAN_COLOR - banner_distro_name="Debian" - banner_distro_version=$(cat /etc/debian_version) - elif [ "$ID" = "fedora" ]; then - banner_distro_icon=$BANNER_FEDORA_ICON - banner_distro_color=$BANNER_FEDORA_COLOR - banner_distro_name="Fedora" - banner_distro_version=$VERSION_ID - else - banner_distro_icon="?" - banner_distro_color="0" - banner_distro_name="Unknown" - banner_distro_version="?" - fi - - banner_distro_space=$(generate_space "$banner_distro_name" 13) - - printf " \\033[%sm%s %s\\033[0m%s%s\\n" "$banner_distro_color" "$banner_distro_icon" "$banner_distro_name" "$banner_distro_space" "$banner_distro_version" - printf " \\033[%sm%s Linux\\033[0m %s\\n\\n" "$BANNER_KERNEL_COLOR" "$BANNER_KERNEL_ICON" "$(cut -d ' ' -f 3 < /proc/version)" - printf " \\033[%sm%s Uptime\\033[0m %s\\n" "$BANNER_UPTIME_COLOR" "$BANNER_UPTIME_ICON" "$(uptime -p | cut -d ' ' -f 2-)" - fi + printf " \\033[%sm%s %s\\033[0m%s%s\\n" "$banner_distro_color" "$banner_distro_icon" "$banner_distro_name" "$banner_distro_space" "$banner_distro_version" + printf " \\033[%sm%s Linux\\033[0m %s\\n\\n" "$BANNER_KERNEL_COLOR" "$BANNER_KERNEL_ICON" "$(cut -d ' ' -f 3 < /proc/version)" + printf " \\033[%sm%s Uptime\\033[0m %s\\n" "$BANNER_UPTIME_COLOR" "$BANNER_UPTIME_ICON" "$(uptime -p | cut -d ' ' -f 2-)" + fi } print_processor() { - printf "\\n" - printf " \\033[1;37mProcessor:\\033[0m\\n" + printf "\\n" + printf " \\033[1;37mProcessor:\\033[0m\\n" - processor_loadavg="$(cut -d " " -f 1,2,3 < /proc/loadavg)" - if [ "$(echo "$processor_loadavg" | cut -d "." -f 1)" -ge "$PROCESSOR_LOADAVG_CRITICAL_THRESHOLD" ]; then - processor_loadavg_color=$PROCESSOR_LOADAVG_CRITICAL_COLOR - elif [ "$(echo "$processor_loadavg" | cut -d "." -f 1)" -ge "$PROCESSOR_LOADAVG_WARNING_THRESHOLD" ]; then - processor_loadavg_color=$PROCESSOR_LOADAVG_WARNING_COLOR + processor_loadavg="$(cut -d " " -f 1,2,3 < /proc/loadavg)" + if [ "$(echo "$processor_loadavg" | cut -d "." -f 1)" -ge "$PROCESSOR_LOADAVG_CRITICAL_THRESHOLD" ]; then + processor_loadavg_color=$PROCESSOR_LOADAVG_CRITICAL_COLOR + elif [ "$(echo "$processor_loadavg" | cut -d "." -f 1)" -ge "$PROCESSOR_LOADAVG_WARNING_THRESHOLD" ]; then + processor_loadavg_color=$PROCESSOR_LOADAVG_WARNING_COLOR + else + processor_loadavg_color=$PROCESSOR_LOADAVG_HEALTHY_COLOR + fi + + processor_info=$(cat /proc/cpuinfo) + + processor_arch=$(uname -m) + + if [ "$processor_arch" = "x86_64" ]; then + processor_model="$(echo "$processor_info" | grep "model name" | sort -u | cut -d ':' -f 2)" + processor_count=$(echo "$processor_info" | grep "physical id" | sort -u | wc -l) + processor_cores=$(echo "$processor_info" | grep "cpu cores" | sort -u | cut -d ':' -f 2) + processor_threads=$(($(echo "$processor_info" | grep "siblings" | tail -n 1 | cut -d ':' -f 2))) + + if [ ! "$processor_cores" -eq $processor_threads ]; then + processor_threads=", $processor_threads Threads" else - processor_loadavg_color=$PROCESSOR_LOADAVG_HEALTHY_COLOR + processor_threads="" fi + elif [ "$processor_arch" = "mips64" ]; then + processor_model="$(echo "$processor_info" | grep "cpu model" | sort -u | cut -d ':' -f 2)" + processor_count=$(echo "$processor_info" | grep "package" | sort -u | wc -l) + processor_cores=$(echo "$processor_info" | grep -c processor) + processor_threads="" + else + processor_model="?" + processor_count=0 + processor_cores=0 + processor_threads=0 + fi - processor_info=$(cat /proc/cpuinfo) + processor_model=$(echo "$processor_model" | sed "s/(R)//g") + processor_model=$(echo "$processor_model" | sed "s/(tm)//g") + processor_model=$(echo "$processor_model" | sed "s/ @/,/") + processor_model=$(echo "$processor_model" | sed "s/ CPU//") + processor_model=$(echo "$processor_model" | sed "s/ / /") + processor_model=$(echo "$processor_model" | sed "s/^ //g") - processor_arch=$(uname -m) + processor_cores=$((processor_cores * processor_count)) - if [ "$processor_arch" = "x86_64" ]; then - processor_model="$(echo "$processor_info" | grep "model name" | sort -u | cut -d ':' -f 2)" - processor_count=$(echo "$processor_info" | grep "physical id" | sort -u | wc -l) - processor_cores=$(echo "$processor_info" | grep "cpu cores" | sort -u | cut -d ':' -f 2) - processor_threads=$(( $(echo "$processor_info" | grep "siblings" | tail -n 1 | cut -d ':' -f 2) )) + if [ "$processor_count" -gt 1 ]; then + processor_count="$processor_count""x " + else + processor_count="" + fi - if [ ! "$processor_cores" -eq $processor_threads ]; then - processor_threads=", $processor_threads Threads" - else - processor_threads="" - fi - elif [ "$processor_arch" = "mips64" ]; then - processor_model="$(echo "$processor_info" | grep "cpu model" | sort -u | cut -d ':' -f 2)" - processor_count=$(echo "$processor_info" | grep "package" | sort -u | wc -l) - processor_cores=$(echo "$processor_info" | grep -c processor) - processor_threads="" - else - processor_model="?" - processor_count=0 - processor_cores=0 - processor_threads=0 - fi - - processor_model=$(echo "$processor_model" | sed "s/(R)//g") - processor_model=$(echo "$processor_model" | sed "s/(tm)//g") - processor_model=$(echo "$processor_model" | sed "s/ @/,/") - processor_model=$(echo "$processor_model" | sed "s/ CPU//") - processor_model=$(echo "$processor_model" | sed "s/ / /") - processor_model=$(echo "$processor_model" | sed "s/^ //g") - - processor_cores=$(( processor_cores * processor_count )) - - if [ "$processor_count" -gt 1 ]; then - processor_count="$processor_count""x " - else - processor_count="" - fi - - printf " %s \\033[%dm%s\\033[0m\\n" "$PROCESSOR_LOADAVG_ICON" "$processor_loadavg_color" "$processor_loadavg" - printf " %s %s%s = %s Cores%s\\n" "$PROCESSOR_MODEL_ICON" "$processor_count" "$processor_model" "$processor_cores" "$processor_threads" + printf " %s \\033[%dm%s\\033[0m\\n" "$PROCESSOR_LOADAVG_ICON" "$processor_loadavg_color" "$processor_loadavg" + printf " %s %s%s = %s Cores%s\\n" "$PROCESSOR_MODEL_ICON" "$processor_count" "$processor_model" "$processor_cores" "$processor_threads" } print_memory() { - printf "\\n" - printf " \\033[1;37mMemory:\\033[0m\\n" + printf "\\n" + printf " \\033[1;37mMemory:\\033[0m\\n" - memory_usage=$(LANG=C free --mega | grep "Mem:") - memory_total=$(echo "$memory_usage" | awk '{ print $2 }') - memory_used=$(echo "$memory_usage" | awk '{ print $3 }') - memory_cached=$(echo "$memory_usage" | awk '{ print $6 }') + memory_usage=$(LANG=C free --mega | grep "Mem:") + memory_total=$(echo "$memory_usage" | awk '{ print $2 }') + memory_used=$(echo "$memory_usage" | awk '{ print $3 }') + memory_cached=$(echo "$memory_usage" | awk '{ print $6 }') - generate_bar_memory "$MEMORY_ICON" "$memory_total" "$memory_used" "$memory_cached" + generate_bar_memory "$MEMORY_ICON" "$memory_total" "$memory_used" "$memory_cached" } print_swap() { - swap_usage=$(LANG=C free --mega | grep "Swap:") + swap_usage=$(LANG=C free --mega | grep "Swap:") - swap_total=$(echo "$swap_usage" | awk '{ print $2 }') - swap_used=$(echo "$swap_usage" | awk '{ print $3 }') + swap_total=$(echo "$swap_usage" | awk '{ print $2 }') + swap_used=$(echo "$swap_usage" | awk '{ print $3 }') - if [ "$swap_total" -ne 0 ]; then - printf "\\n" - printf " \\033[1;37mSwap:\\033[0m\\n" + if [ "$swap_total" -ne 0 ]; then + printf "\\n" + printf " \\033[1;37mSwap:\\033[0m\\n" - generate_bar_swap "$SWAP_ICON" "$swap_total" "$swap_used" - fi + generate_bar_swap "$SWAP_ICON" "$swap_total" "$swap_used" + fi } print_diskspace() { + if type jq > /dev/null; then printf "\\n" printf " \\033[1;37mDiskspace:\\033[0m\\n" - diskspace_devices=$(lsblk -Jlo NAME,MOUNTPOINT | jq -c '.blockdevices | sort_by(.mountpoint) | .[] | select( .mountpoint != null and .mountpoint != "[SWAP]" )') + diskspace_devices=$(lsblk -Jlo NAME,MOUNTPOINT | jq -c '.blockdevices | sort_by(.mountpoint) | .[] | select( .mountpoint != null and .mountpoint != "[SWAP]" )') diskspace_partitions=$(df -B M | sed -e "s/M//g") diskspace_index=0 echo "$diskspace_devices" | while read -r line; do - diskspace_disk_name="$(echo "$line" | jq -r '.name')" - diskspace_disk_mount="$(echo "$line" | jq -r '.mountpoint')" + diskspace_disk_name="$(echo "$line" | jq -r '.name')" + diskspace_disk_mount="$(echo "$line" | jq -r '.mountpoint')" - diskspace_disk_size="$(echo "$diskspace_partitions" | grep "$diskspace_disk_name " | awk '{ print $2 }')" - diskspace_disk_used="$(echo "$diskspace_partitions" | grep "$diskspace_disk_name " | awk '{ print $3 }')" + diskspace_disk_size="$(echo "$diskspace_partitions" | grep "$diskspace_disk_name " | awk '{ print $2 }')" + diskspace_disk_used="$(echo "$diskspace_partitions" | grep "$diskspace_disk_name " | awk '{ print $3 }')" - if [ -z "$diskspace_disk_size" ]; then - diskspace_disk_size="$(echo "$diskspace_partitions" | grep "$diskspace_disk_mount" | awk '{ print $2 }')" - fi + if [ -z "$diskspace_disk_size" ]; then + diskspace_disk_size="$(echo "$diskspace_partitions" | grep "$diskspace_disk_mount" | awk '{ print $2 }')" + fi - if [ -z "$diskspace_disk_used" ]; then - diskspace_disk_used="$(echo "$diskspace_partitions" | grep "$diskspace_disk_mount" | awk '{ print $3 }')" - fi + if [ -z "$diskspace_disk_used" ]; then + diskspace_disk_used="$(echo "$diskspace_partitions" | grep "$diskspace_disk_mount" | awk '{ print $3 }')" + fi - if [ "$diskspace_index" -ne 0 ]; then - printf "\\n" - fi + if [ "$diskspace_index" -ne 0 ]; then + printf "\\n" + fi - diskspace_index=$(( diskspace_index + 1 )) + diskspace_index=$((diskspace_index + 1)) - generate_bar_disk "$DISKSPACE_ICON" "$diskspace_disk_size" "$diskspace_disk_used" "$diskspace_disk_mount" + generate_bar_disk "$DISKSPACE_ICON" "$diskspace_disk_size" "$diskspace_disk_used" "$diskspace_disk_mount" done + fi } print_services() { - if [ -f $SERVICES_FILE ] && [ "$(wc -l < $SERVICES_FILE )" != 0 ]; then - printf "\\n" - printf " \\033[1;37mServices:\\033[0m \\033[1;37mVersion:\\033[0m\\n" + if [ -f $SERVICES_FILE ] && [ "$(wc -l < $SERVICES_FILE)" != 0 ]; then + printf "\\n" + printf " \\033[1;37mServices:\\033[0m \\033[1;37mVersion:\\033[0m\\n" - while read -r line; do - service_description=$(echo "$line" | cut -d ';' -f 1) + while read -r line; do + service_description=$(echo "$line" | cut -d ';' -f 1) - service_name=$(echo "$line" | cut -d ';' -f 2) + service_name=$(echo "$line" | cut -d ';' -f 2) - service_package=$(echo "$line" | cut -d ';' -f 3) + service_package=$(echo "$line" | cut -d ';' -f 3) - if [ -n "$service_description" ] && [ -n "$service_name" ]; then - if systemctl is-active --quiet "$service_name".service; then - service_icon=$SERVICES_UP_ICON - service_color=$SERVICES_UP_COLOR - else - service_icon=$SERVICES_DOWN_ICON - service_color=$SERVICES_DOWN_COLOR - fi + if [ -n "$service_description" ] && [ -n "$service_name" ]; then + if systemctl is-active --quiet "$service_name".service; then + service_icon=$SERVICES_UP_ICON + service_color=$SERVICES_UP_COLOR + else + service_icon=$SERVICES_DOWN_ICON + service_color=$SERVICES_DOWN_COLOR + fi - service_space=$(generate_space "$service_description" 34) + service_space=$(generate_space "$service_description" 34) - if [ -n "$service_package" ]; then - if [ -f /usr/bin/apt ]; then - package_version=$(dpkg -s "$service_package" | grep '^Version:' | cut -d ' ' -f 2 | cut -d ':' -f 2 | cut -d '-' -f 1) - elif [ -f /usr/bin/rpm ]; then - package_version=$(rpm -q --queryformat '%{VERSION}' "$service_package") - else - package_version="?" - fi - else - package_version="--" - fi - fi + if [ -n "$service_package" ]; then + if [ -f /usr/bin/apt ]; then + package_version=$(dpkg -s "$service_package" | grep '^Version:' | cut -d ' ' -f 2 | cut -d ':' -f 2 | cut -d '-' -f 1) + elif [ -f /usr/bin/rpm ]; then + package_version=$(rpm -q --queryformat '%{VERSION}' "$service_package") + else + package_version="?" + fi + else + package_version="--" + fi + fi - printf " \\033[%sm%s\\033[0m %s%s%s\\n" "$service_color" "$service_icon" "$service_description" "$service_space" "$package_version" - done < $SERVICES_FILE | grep -v '#' - fi + printf " \\033[%sm%s\\033[0m %s%s%s\\n" "$service_color" "$service_icon" "$service_description" "$service_space" "$package_version" + done < $SERVICES_FILE | grep -v '#' + fi } print_podman() { - printf "\\n" - printf " \\033[1;37mPodman:\\033[0m\\n" + printf "\\n" + printf " \\033[1;37mPodman:\\033[0m\\n" - podman_version=$(sudo podman version --format json | jq -r '.Client.Version') - podman_space=$(generate_space "$podman_version" 23) - podman_images=$(sudo podman images --format json | jq '. | length') + podman_version=$(sudo podman version --format json | jq -r '.Client.Version') + podman_space=$(generate_space "$podman_version" 23) + podman_images=$(sudo podman images --format json | jq '. | length') - printf " %s Version %s%s%s %s Images\\n\\n" "$PODMAN_VERSION_ICON" "$podman_version" "$podman_space" "$PODMAN_IMAGES_ICON" "$podman_images" + printf " %s Version %s%s%s %s Images\\n\\n" "$PODMAN_VERSION_ICON" "$podman_version" "$podman_space" "$PODMAN_IMAGES_ICON" "$podman_images" - podman_list=$(sudo podman pod ls --sort name --format json) - podman_pods=$(echo "$podman_list" | jq -r '.[] .Name') + podman_list=$(sudo podman pod ls --sort name --format json) + podman_pods=$(echo "$podman_list" | jq -r '.[] .Name') - echo "$podman_pods" | while read -r pod; do - if [ "$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Status")" = "Running" ]; then - pod_space=$(generate_space "$pod" 34) + echo "$podman_pods" | while read -r pod; do + if [ "$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Status")" = "Running" ]; then + pod_space=$(generate_space "$pod" 34) - pod_container_running="$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Containers[] | select(.Status == \"running\") | .Status" | wc -l)" + pod_container_running="$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Containers[] | select(.Status == \"running\") | .Status" | wc -l)" - if [ "$pod_container_running" -ne 0 ]; then - pod_container_running=$(printf "\\033[%um%u Running\\033[0m" "$PODMAN_RUNNING_COLOR" "$pod_container_running") - fi + if [ "$pod_container_running" -ne 0 ]; then + pod_container_running=$(printf "\\033[%um%u Running\\033[0m" "$PODMAN_RUNNING_COLOR" "$pod_container_running") + fi - pod_container_other="$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Containers[] | select(.Status != \"running\") | .Status" | wc -l)" + pod_container_other="$(echo "$podman_list" | jq -r ".[] | select(.Name == \"$pod\") | .Containers[] | select(.Status != \"running\") | .Status" | wc -l)" - if [ "$pod_container_other" -ne 0 ]; then - pod_container_other=$(printf ", \\033[%um%u Other\\033[0m" "$PODMAN_OTHER_COLOR" "$pod_container_other") - else - pod_container_other="" - fi + if [ "$pod_container_other" -ne 0 ]; then + pod_container_other=$(printf ", \\033[%um%u Other\\033[0m" "$PODMAN_OTHER_COLOR" "$pod_container_other") + else + pod_container_other="" + fi - pod_status="$pod_container_running$pod_container_other" + pod_status="$pod_container_running$pod_container_other" - printf " \\033[%um%s\\033[0m %s%s%s\\n" "$PODMAN_RUNNING_COLOR" "$PODMAN_RUNNING_ICON" "$pod" "$pod_space" "$pod_status" - else - printf " \\033[%um%s\\033[0m \\033[%um%s\\033[0m\\n" "$PODMAN_OTHER_COLOR" "$PODMAN_OTHER_ICON" "$PODMAN_OTHER_COLOR" "$pod" - fi - done + printf " \\033[%um%s\\033[0m %s%s%s\\n" "$PODMAN_RUNNING_COLOR" "$PODMAN_RUNNING_ICON" "$pod" "$pod_space" "$pod_status" + else + printf " \\033[%um%s\\033[0m \\033[%um%s\\033[0m\\n" "$PODMAN_OTHER_COLOR" "$PODMAN_OTHER_ICON" "$PODMAN_OTHER_COLOR" "$pod" + fi + done } print_docker() { - if [ "$(systemctl is-active docker.service)" = "active" ]; then - printf "\\n" - printf " \\033[1;37mDocker:\\033[0m\\n" + if [ "$(systemctl is-active docker.service)" = "active" ]; then + printf "\\n" + printf " \\033[1;37mDocker:\\033[0m\\n" - docker_info=$(sudo curl -sf --unix-socket /var/run/docker.sock http:/v1.40/info) + docker_info=$(sudo curl -sf --unix-socket /var/run/docker.sock http:/v1.40/info) - docker_version=$(echo "$docker_info" | jq -r '.ServerVersion') + docker_version=$(echo "$docker_info" | jq -r '.ServerVersion') - docker_space=$(generate_space "$docker_version" 23) + docker_space=$(generate_space "$docker_version" 23) - docker_images=$(echo "$docker_info" | jq -r '.Images') + docker_images=$(echo "$docker_info" | jq -r '.Images') - printf " %s Version %s%s%s %s Images\\n\\n" "$DOCKER_VERSION_ICON" "$docker_version" "$docker_space" "$DOCKER_IMAGES_ICON" "$docker_images" + printf " %s Version %s%s%s %s Images\\n\\n" "$DOCKER_VERSION_ICON" "$docker_version" "$docker_space" "$DOCKER_IMAGES_ICON" "$docker_images" - docker_list=$(sudo curl -sf --unix-socket /var/run/docker.sock "http://v1.40/containers/json?all=true" | jq -c ' .[]') + docker_list=$(sudo curl -sf --unix-socket /var/run/docker.sock "http://v1.40/containers/json?all=true" | jq -c ' .[]') - echo "$docker_list" | while read -r line; do - container_name="$(echo "$line" | jq -r '.Names[]' | sed 's/\///')" + echo "$docker_list" | while read -r line; do + container_name="$(echo "$line" | jq -r '.Names[]' | sed 's/\///')" - container_status="$(echo "$line" | jq -r '.Status' | sed 's/.*/\l&/')" + container_status="$(echo "$line" | jq -r '.Status' | sed 's/.*/\l&/')" - container_space=$(generate_space "$container_name" 34) + container_space=$(generate_space "$container_name" 34) - if [ "$(echo "$line" | jq -r '.State')" = "running" ]; then - printf " \\033[%um%s\\033[0m %s%s%s\\n" "$DOCKER_RUNNING_COLOR" "$DOCKER_RUNNING_ICON" "$container_name" "$container_space" "$container_status" - else - printf " \\033[%um%s\\033[0m \\033[%um%s\\033[0m%s\\033[%um%s\\033[0m\\n" "$DOCKER_OTHER_COLOR" "$DOCKER_OTHER_ICON" "$DOCKER_OTHER_COLOR" "$container_name" "$container_space" "$DOCKER_OTHER_COLOR" "$container_status" - fi - done - fi + if [ "$(echo "$line" | jq -r '.State')" = "running" ]; then + printf " \\033[%um%s\\033[0m %s%s%s\\n" "$DOCKER_RUNNING_COLOR" "$DOCKER_RUNNING_ICON" "$container_name" "$container_space" "$container_status" + else + printf " \\033[%um%s\\033[0m \\033[%um%s\\033[0m%s\\033[%um%s\\033[0m\\n" "$DOCKER_OTHER_COLOR" "$DOCKER_OTHER_ICON" "$DOCKER_OTHER_COLOR" "$container_name" "$container_space" "$DOCKER_OTHER_COLOR" "$container_status" + fi + done + fi } print_updates() { - if [ -f /usr/bin/apt ]; then - printf "\\n" - printf " \\033[1;37mUpdates:\\033[0m\\n" + if [ -f /usr/bin/apt ]; then + printf "\\n" + printf " \\033[1;37mUpdates:\\033[0m\\n" - updates_count_regular=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c -v Security) - updates_count_security=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c Security) + updates_count_regular=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c -v Security) + updates_count_security=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c Security) - if [ "$updates_count_regular" -ne 0 ]; then - if [ -n "$updates_count_security" ] && [ "$updates_count_security" -ne 0 ]; then - updates_icon=$UPDATES_SECURITY_ICON - updates_color=$UPDATES_SECURITY_COLOR - updates_message="$updates_count_regular packages can be updated, $updates_count_security are security updates." - else - updates_icon=$UPDATES_AVAILIABLE_ICON - updates_color=$UPDATES_AVAILIABLE_COLOR - updates_message="$updates_count_regular packages can be updated." - fi - else - updates_icon=$UPDATES_ZERO_ICON - updates_color=$UPDATES_ZERO_COLOR - updates_message="Everything is up to date!" - fi - - printf " \\033[%sm%s\\033[0m %s\\n" "$updates_color" "$updates_icon" "$updates_message" - elif [ -f /usr/bin/dnf ]; then - printf "\\n" - printf " \\033[1;37mUpdates:\\033[0m\\n" - - updates_count=$(dnf updateinfo -C -q --list) - updates_count_regular=$(echo "$updates_count" | wc -l) - updates_count_security=$(echo "$updates_count" | grep -c "Important/Sec") - - if [ -n "$updates_count_regular" ] && [ "$updates_count_regular" -ne 0 ]; then - if [ -n "$updates_count_security" ] && [ "$updates_count_security" -ne 0 ]; then - updates_icon=$UPDATES_SECURITY_ICON - updates_color=$UPDATES_SECURITY_COLOR - updates_message="$updates_count_regular packages can be updated, $updates_count_security are security updates." - else - updates_icon=$UPDATES_AVAILIABLE_ICON - updates_color=$UPDATES_AVAILIABLE_COLOR - updates_message="$updates_count_regular packages can be updated." - fi - else - updates_icon=$UPDATES_ZERO_ICON - updates_color=$UPDATES_ZERO_COLOR - updates_message="Everything is up to date!" - fi - - printf " \\033[%sm%s\\033[0m %s\\n" "$updates_color" "$updates_icon" "$updates_message" + if [ "$updates_count_regular" -ne 0 ]; then + if [ -n "$updates_count_security" ] && [ "$updates_count_security" -ne 0 ]; then + updates_icon=$UPDATES_SECURITY_ICON + updates_color=$UPDATES_SECURITY_COLOR + updates_message="$updates_count_regular packages can be updated, $updates_count_security are security updates." + else + updates_icon=$UPDATES_AVAILIABLE_ICON + updates_color=$UPDATES_AVAILIABLE_COLOR + updates_message="$updates_count_regular packages can be updated." + fi + else + updates_icon=$UPDATES_ZERO_ICON + updates_color=$UPDATES_ZERO_COLOR + updates_message="Everything is up to date!" fi + + printf " \\033[%sm%s\\033[0m %s\\n" "$updates_color" "$updates_icon" "$updates_message" + elif [ -f /usr/bin/dnf ]; then + printf "\\n" + printf " \\033[1;37mUpdates:\\033[0m\\n" + + updates_count=$(dnf updateinfo -C -q --list) + updates_count_regular=$(echo "$updates_count" | wc -l) + updates_count_security=$(echo "$updates_count" | grep -c "Important/Sec") + + if [ -n "$updates_count_regular" ] && [ "$updates_count_regular" -ne 0 ]; then + if [ -n "$updates_count_security" ] && [ "$updates_count_security" -ne 0 ]; then + updates_icon=$UPDATES_SECURITY_ICON + updates_color=$UPDATES_SECURITY_COLOR + updates_message="$updates_count_regular packages can be updated, $updates_count_security are security updates." + else + updates_icon=$UPDATES_AVAILIABLE_ICON + updates_color=$UPDATES_AVAILIABLE_COLOR + updates_message="$updates_count_regular packages can be updated." + fi + else + updates_icon=$UPDATES_ZERO_ICON + updates_color=$UPDATES_ZERO_COLOR + updates_message="Everything is up to date!" + fi + + printf " \\033[%sm%s\\033[0m %s\\n" "$updates_color" "$updates_icon" "$updates_message" + fi } print_letsencrypt() { - if [ -d $LETSENCRYPT_CERTPATH ] && [ "$(ls -a $LETSENCRYPT_CERTPATH)" ]; then - printf "\\n" - printf " \\033[1;37mSSL / let’s encrypt:\\033[0m\\n" + if [ -d $LETSENCRYPT_CERTPATH ] && [ "$(ls -a $LETSENCRYPT_CERTPATH)" ]; then + printf "\\n" + printf " \\033[1;37mSSL / let’s encrypt:\\033[0m\\n" - cert_list=$(sudo find $LETSENCRYPT_CERTPATH -name cert.pem) + cert_list=$(sudo find $LETSENCRYPT_CERTPATH -name cert.pem) - for cert_file in $cert_list; do - sudo openssl x509 -checkend $((25 * 86400)) -noout -in "$cert_file" >> /dev/null - result=$? + for cert_file in $cert_list; do + sudo openssl x509 -checkend $((25 * 86400)) -noout -in "$cert_file" >> /dev/null + result=$? - cert_name=$(echo "$cert_file" | rev | cut -d '/' -f 2 | rev) + cert_name=$(echo "$cert_file" | rev | cut -d '/' -f 2 | rev) - if [ "$result" -eq 0 ]; then - printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_VALID_COLOR" "$LETSENCRYPT_VALID_ICON" "$cert_name" - else - sudo openssl x509 -checkend $((0 * 86400)) -noout -in "$cert_file" >> /dev/null - result=$? + if [ "$result" -eq 0 ]; then + printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_VALID_COLOR" "$LETSENCRYPT_VALID_ICON" "$cert_name" + else + sudo openssl x509 -checkend $((0 * 86400)) -noout -in "$cert_file" >> /dev/null + result=$? - if [ "$result" -eq 0 ]; then - printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_WARNING_COLOR" "$LETSENCRYPT_WARNING_ICON" "$cert_name" - else - printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_INVALID_COLOR" "$LETSENCRYPT_INVALID_ICON" "$cert_name" - fi - fi - done - fi + if [ "$result" -eq 0 ]; then + printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_WARNING_COLOR" "$LETSENCRYPT_WARNING_ICON" "$cert_name" + else + printf " \\033[%sm%s\\033[0m %s\\n" "$LETSENCRYPT_INVALID_COLOR" "$LETSENCRYPT_INVALID_ICON" "$cert_name" + fi + fi + done + fi } print_login() { - login_last=$(last -n 2 -a -d --time-format iso "$(whoami)" | head -n 2 | tail -n 1) + login_last=$(last -n 2 -a -d --time-format iso "$(whoami)" | head -n 2 | tail -n 1) - if [ "$( echo "$login_last" | awk '{ print $1 }')" = "$(whoami)" ]; then - login_ip=$(echo "$login_last" | awk '{ print $7 }') + if [ "$(echo "$login_last" | awk '{ print $1 }')" = "$(whoami)" ]; then + login_ip=$(echo "$login_last" | awk '{ print $7 }') - login_login=$(date -d "$(echo "$login_last" | awk '{ print $3 }' | cut -d '+' -f 1 | sed "s/T/ /")" "+%a, %d.%m.%y %H:%M") + login_login=$(date -d "$(echo "$login_last" | awk '{ print $3 }' | cut -d '+' -f 1 | sed "s/T/ /")" "+%a, %d.%m.%y %H:%M") - login_space=$(generate_space "$login_login" 25) + login_space=$(generate_space "$login_login" 25) - if [ "$(echo "$login_last" | awk '{ print $4 }')" = "still" ]; then - login_logout="still connected" - else - login_logout=$(date -d "$(echo "$login_last" | awk '{ print $5 }' | cut -d '+' -f 1 | sed "s/T/ /")" "+%a, %d.%m.%y %H:%M") - fi - - printf "\\n" - printf " \\033[1;37mLast login for %s:\\033[0m\\n" "$(echo "$login_last" | awk '{ print $1 }')" - printf " %s %s%s%s %s\\n" "$LOGIN_LOGIN_ICON" "$login_login" "$login_space" "$LOGIN_LOGOUT_ICON" "$login_logout" - printf " %s %s\\n" "$LOGIN_IP_ICON" "$login_ip" + if [ "$(echo "$login_last" | awk '{ print $4 }')" = "still" ]; then + login_logout="still connected" + else + login_logout=$(date -d "$(echo "$login_last" | awk '{ print $5 }' | cut -d '+' -f 1 | sed "s/T/ /")" "+%a, %d.%m.%y %H:%M") fi + + printf "\\n" + printf " \\033[1;37mLast login for %s:\\033[0m\\n" "$(echo "$login_last" | awk '{ print $1 }')" + printf " %s %s%s%s %s\\n" "$LOGIN_LOGIN_ICON" "$login_login" "$login_space" "$LOGIN_LOGOUT_ICON" "$login_logout" + printf " %s %s\\n" "$LOGIN_IP_ICON" "$login_ip" + fi } print_include() { - . $INCLUDE_FILE + . $INCLUDE_FILE } bash_motd() { - for module in "$@"; do - if [ "$module" = "--banner" ]; then - print_banner - elif [ "$module" = "--processor" ]; then - print_processor - elif [ "$module" = "--memory" ]; then - print_memory - elif [ "$module" = "--swap" ]; then - print_swap - elif [ "$module" = "--diskspace" ]; then - print_diskspace - elif [ "$module" = "--services" ]; then - print_services - elif [ "$module" = "--podman" ]; then - print_podman - elif [ "$module" = "--docker" ]; then - print_docker - elif [ "$module" = "--updates" ]; then - print_updates - elif [ "$module" = "--letsencrypt" ]; then - print_letsencrypt - elif [ "$module" = "--login" ]; then - print_login - elif [ "$module" = "--include" ]; then - print_include - fi - done + for module in "$@"; do + if [ "$module" = "--banner" ]; then + print_banner + elif [ "$module" = "--processor" ]; then + print_processor + elif [ "$module" = "--memory" ]; then + print_memory + elif [ "$module" = "--swap" ]; then + print_swap + elif [ "$module" = "--diskspace" ]; then + print_diskspace + elif [ "$module" = "--services" ]; then + print_services + elif [ "$module" = "--podman" ]; then + print_podman + elif [ "$module" = "--docker" ]; then + print_docker + elif [ "$module" = "--updates" ]; then + print_updates + elif [ "$module" = "--letsencrypt" ]; then + print_letsencrypt + elif [ "$module" = "--login" ]; then + print_login + elif [ "$module" = "--include" ]; then + print_include + fi + done - printf "\\n" + printf "\\n" }