From af1c0522f03d39ebb9eb4e10f44d3f264b69aa0e Mon Sep 17 00:00:00 2001 From: David Lopez Date: Sat, 7 Sep 2024 09:20:08 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20roles/config-motd/files/90-vn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/config-motd/files/90-vn | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 roles/config-motd/files/90-vn diff --git a/roles/config-motd/files/90-vn b/roles/config-motd/files/90-vn new file mode 100644 index 0000000..d2678b2 --- /dev/null +++ b/roles/config-motd/files/90-vn @@ -0,0 +1,104 @@ +#!/bin/sh +uname -snrvm +root@dhcp1:/etc/dhcp/subnets# cat /etc/update-motd.d/90-vn +#!/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" +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="-" + ;; + *) + 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"