ANOTHER LINUX SYSTEM STATUS BANNER SCRIPT

Code:
ย 


#!/bin/bash

  # Copyright ยฉ 2019 hads0m <[email protected]>
  # Distributed under terms of the GNU GPLv3 license.

COLOR_RESET='\e[0m'     # Color definitions
COLOR=(
'\e[38;5;154m'  # Green
'\e[1m'         # White
'\e[91m'        # Red
'\e[96m'        # Blue
)

check_deps() {  # If there are missing dependencies, do not run this script
        installed() {
                type -p "$1" 2>&1 > /dev/null
        }

        for PACKAGE in date cat awk hostname df free uptime sensors ifconfig curl grep uname echo systemctl sudo pacman checkupdates
                do
                        if ! installed ${PACKAGE}; then
                                MISSING_DEPS+=" $PACKAGE"
                        fi
                done

        if [ $(echo $MISSING_DEPS |egrep -v ^$ |wc -l) -ge 1 ]; then
                echo "You need to install the following dependencies to run this script successfully:"
                echo -e $MISSING_DEPS |tr " " \\n
                exit 1
        fi
}

line() {        # Print a separator line
        echo -e " ${COLOR[0]}โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€$COLOR_RESET"
}

motd() {        # Print header and MOTD
        line
        MESSAGE=" $(date "+%d %B %Y") ยท $USER on $(hostname -s) ยท beyond the cloud"
        echo -e "${COLOR[1]} $MESSAGE"
        line
}

display() {     # Get the elements list to display
        ELEMENTS=$(for element in "${DESCRIPTION[@]}"; do echo $element; done |wc -l)
        ITEM=0
        echo -e "\t\t   ${COLOR[3]} ${BLOCK_TITLE}${COLOR_RESET}"
        line
        until [ $ITEM -eq $ELEMENTS ]
        do echo -e "   ${COLOR[1]}${DESCRIPTION[$ITEM]}${COLOR[2]} โ–ถ ${COLOR_RESET}${COLOR[1]}${COMMAND[$ITEM]}"
                let ITEM+=1
        done
        line
}

hardware() {    # Process the elements present in the "Hardware info" block
        BLOCK_TITLE="Hardware info"
        DESCRIPTION=(
                "Motherboard${COLOR_RESET}${COLOR[1]}........."
                "RAM usage${COLOR_RESET}${COLOR[1]}..........."
                "Disk usage${COLOR_RESET}${COLOR[1]}.........."
                "System uptime${COLOR_RESET}${COLOR[1]}......."
                "CPU temperature${COLOR_RESET}${COLOR[1]}....."
                "Load average${COLOR_RESET}${COLOR[1]}........"
        )

        COMMAND=(
                "$(cat /sys/devices/virtual/dmi/id/board_vendor |awk '{print $1}') $(cat /sys/devices/virtual/dmi/id/board_name |cut -d\- -f1)"
                "$(free -m | awk '/Mem/ { printf("%3.1f%%", $3/$2*100) }')"
                "$(df -h / |tail -1 |awk '{print $4"B / "$2"B free ยท "$5" used"}')"
                "$(uptime -p)"
                "$(sensors |grep high |grep -v id | cut -d\: -f2 |awk '{print $1}' |head -1)"
                "$(cat /proc/loadavg | awk {'print $1", "$2", "$3'})"
        )

display
}

network() {     # Process the elements present in the "Network info" block
        BLOCK_TITLE="Network info"
        DESCRIPTION=(
                "LAN ipv4 address${COLOR_RESET}${COLOR[1]}...."
                "LAN ipv6 address${COLOR_RESET}${COLOR[1]}...."
                "WAN ipv4 address${COLOR_RESET}${COLOR[1]}...."
        )

        COMMAND=(
                "$(ip a |grep $(ip route |grep default |awk '{print $5}') |grep inet |awk '{print $2}' |grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")"
                "$(ip a |grep -v "::1" |grep inet6 |awk '{print $2}' |head -1 |egrep "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))")"
                "$(curl -s ip.me)"
        )

display
}

system() {      # Process the elements present in the "System info" block
        BLOCK_TITLE="System info"
        DESCRIPTION=(
                "Linux distro${COLOR_RESET}${COLOR[1]}........"
                "Kernel version${COLOR_RESET}${COLOR[1]}......"
                "BASH version${COLOR_RESET}${COLOR[1]}........"
                "Full hostname${COLOR_RESET}${COLOR[1]}......."
                "Running services${COLOR_RESET}${COLOR[1]}...."
                "Installed packages${COLOR_RESET}${COLOR[1]}.."
                "Available updates${COLOR_RESET}${COLOR[1]}..."
        )

        COMMAND=(
                "$(grep PRETTY_NAME /etc/os-release |tr \" " " |awk '{print $2" "$3}')"
                "$(uname -r)"
                "$(echo ${BASH_VERSION})"
                "$(hostname -f)"
                "$(systemctl list-units | grep running|sort| wc -l)"
                "$(sudo pacman -Qqe |wc -l)"
                "$(checkupdates |wc -l)"
        )

display
}

check_deps
printf '\ec' # Clear screen

# Display the existing information blocks in the desired order
motd
hardware
network
system