103 lines
3.1 KiB
Bash
103 lines
3.1 KiB
Bash
#!/bin/bash
|
|
|
|
LABEL="\033[0;32m"
|
|
SUBLB="\033[0;36m"
|
|
RESET="\033[0m"
|
|
BLINK="\033[5m"
|
|
|
|
. /etc/os-release
|
|
|
|
# Environment
|
|
|
|
PRO="\033[1;5;31m"
|
|
LAB="\033[0;35m"
|
|
VN="\033[0;32m"
|
|
UNKNOWN="\033[0;33m"
|
|
|
|
FQDN=$(hostname --fqdn)
|
|
case "$FQDN" in
|
|
*.dc.verdnatura.es)
|
|
ENVIRONMENT="${PRO}Production${RESET}"
|
|
;;
|
|
*.lab.verdnatura.es)
|
|
ENVIRONMENT="${LAB}Laboratory${RESET}"
|
|
;;
|
|
*.verdnatura.es)
|
|
ENVIRONMENT="${VN}Verdnatura${RESET}"
|
|
;;
|
|
*)
|
|
ENVIRONMENT="${UNKNOWN}Unknown${RESET}"
|
|
;;
|
|
esac
|
|
|
|
# Last login
|
|
|
|
LAST="$(last -n1 | head -1)"
|
|
if [ "$LAST" != "" ] ; then
|
|
LAST_LOGIN_USER="$(echo $LAST | cut -d' ' -f1)"
|
|
LAST_LOGIN_IP="$(echo $LAST | cut -d' ' -f3)"
|
|
LAST_LOGIN_TIME="$(echo $LAST | cut -d' ' -f4-)"
|
|
LAST_LOGIN="$LAST_LOGIN_USER ($LAST_LOGIN_IP) $LAST_LOGIN_TIME"
|
|
fi
|
|
|
|
# Packages
|
|
|
|
PACKAGES=$(dpkg-query -W -f='${binary:Package}\n' | wc -l)
|
|
SHOW_UPGRADEABLE=0
|
|
USER_UID=$(id -u $USER)
|
|
USER_GROUPS=$(id -Gn $USER)
|
|
|
|
if [ ${USER_UID} -eq 0 ] ; then
|
|
SHOW_UPGRADEABLE=1
|
|
fi
|
|
if [[ "${USER_GROUPS}" == *"sysadmin"* ]] ; then
|
|
SHOW_UPGRADEABLE=1
|
|
fi
|
|
if [ $SHOW_UPGRADEABLE -eq 1 ] ; then
|
|
UPGRADEABLE="$(apt list --upgradable 2>/dev/null | tail -n +2 | wc -l)"
|
|
|
|
if [ "$UPGRADEABLE" -gt 0 ]; then
|
|
UPGRADEABLE_ALERT="${BLINK}($UPGRADEABLE upgradeable)${RESET}"
|
|
fi
|
|
fi
|
|
|
|
# Network and users
|
|
|
|
NET_IPS=$(ip -o -4 add sh | tail -n +2 | awk '{printf "\033[0;36m%16s >\033[0m %-15s\n",$2,$4}')
|
|
CONNECTED_USERS=$(w | tail -n +2 | awk '{printf "\t%15s %12s %8s %s\n",$1,$3,$4, substr( $0, index($0,$8), index($0,$NF)) }')
|
|
|
|
# Logo
|
|
|
|
FW="\033[1;37m"
|
|
FG="\033[1;32m"
|
|
GB="\e[48;5;112m"
|
|
GL="\e[48;5;70m"
|
|
RS="\e[0m"
|
|
|
|
echo -e
|
|
echo -e " $GL $GB $RS"
|
|
echo -e " $GL $GB $GL $RS $GL $GB $RS" " ${FW}__ __ _ ${FG} _ _ _ ${RS}"
|
|
echo -e " $GB $GL $RS $GL $GB $GL $RS" " ${FW}\ \ / /__ _ __ __| |${FG}| \ | | __ _| |_ _ _ _ __ __ _ ${RS}"
|
|
echo -e " $GL $GB $RS $GB $GL $RS " " ${FW} \ \ / / _ \ '__/ _' |${FG}| \| |/ _' | __| | | | '__/ _' |${RS}"
|
|
echo -e " $GL $GB $RS $GB $GL $RS " " ${FW} \ V / __/ | | (_| |${FG}| |\ | (_| | |_| |_| | | | (_| |${RS}"
|
|
echo -e " " " ${FW} \_/ \___|_| \__,_|${FG}|_| \_|\__,_|\__|\__,_|_| \__,_|${RS}"
|
|
echo -e " $GL $GB $RS $GB $GL $RS"
|
|
echo -e " $GL $GB $GL $RS $GL $GB $RS"
|
|
echo -e " $GB $GL $RS"
|
|
echo -e
|
|
|
|
# Information
|
|
|
|
echo -e "${LABEL}Host :${RESET} $FQDN"
|
|
echo -e "${LABEL}OS :${RESET} $NAME $(cat /etc/debian_version) ($VERSION_CODENAME)"
|
|
echo -e "${LABEL}Kernel :${RESET} $(uname -r)"
|
|
echo -e "${LABEL}Shell :${RESET} $SHELL $(echo $BASH_VERSION | cut -d'(' -f1)"
|
|
echo -e "${LABEL}Uptime :${RESET} $(uptime -p | tr -d ',')"
|
|
echo -e "${LABEL}Packages :${RESET} $PACKAGES $UPGRADEABLE_ALERT"
|
|
echo -e "${LABEL}IP :${RESET}"
|
|
echo -e "$NET_IPS"
|
|
echo -e "${LABEL}Last Login :${RESET} $LAST_LOGIN"
|
|
echo -e "${LABEL}Environment :${RESET} $ENVIRONMENT"
|
|
echo -e "${LABEL}Connected users :${RESET}"
|
|
echo -e "$CONNECTED_USERS"
|