diff --git a/Makefile b/Makefile index 36729db..fff648d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -install: apt bin templates man completion files efingerd menu postfix +install: apt bin templates man completion files efingerd menu postfix updatemotd +.PHONY: apt bin templates man completion files efingerd menu postfix updatemotd apt: xargs -a pkglist sudo apt install -y @@ -26,6 +27,11 @@ efingerd: mkdir -p "/etc/efingerd" stow -t "/etc/efingerd" efingerd +updatemotd: + mkdir -p "/etc/update-motd.d" + stow -t "/etc/update-motd.d" update-motd + sudo chown -R root /etc/update-motd.d + menu: stow -t "/etc" menu @@ -48,4 +54,3 @@ uninstall: stow -t "/etc/postfix" -D postfix cd files && stow -t "/usr/share/games/fortunes" -D fortunes -.PHONY: bin templates man completion files efingerd menu postfix diff --git a/update-motd/00-header b/update-motd/00-header new file mode 100755 index 0000000..0acd924 --- /dev/null +++ b/update-motd/00-header @@ -0,0 +1,3 @@ +#!/bin/bash + +/usr/bin/env figlet -f /etc/fonts/contessa "$(hostname)" | /usr/games/lolcat -f diff --git a/update-motd/20-sysinfo b/update-motd/20-sysinfo new file mode 100755 index 0000000..5748f05 --- /dev/null +++ b/update-motd/20-sysinfo @@ -0,0 +1,30 @@ +#!/bin/bash + +# get load averages +IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(cat /proc/loadavg | awk '{ print $1,$2,$3 }') +# get free memory +IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'}) +# get processes +PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'` +PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` +PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}` +PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'` +# get processors +PROCESSOR_NAME=`grep "model name" /proc/cpuinfo | cut -d ' ' -f3- | awk {'print $0'} | head -1` +PROCESSOR_COUNT=`grep -ioP 'processor\t:' /proc/cpuinfo | wc -l` + +W="\e[0;39m" +G="\e[1;32m" + +echo -e " +${W}system info: +$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'` +$W Kernel......: $W`uname -sr` + +$W Uptime......: $W`uptime -p` +$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m) +$W Processes...:$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user), $G$PROCESS_ALL$W (total) + +$W CPU.........: $W$PROCESSOR_NAME ($G$PROCESSOR_COUNT$W vCPU) +$W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W total$W +" | /usr/games/lolcat -f diff --git a/update-motd/35-diskspace b/update-motd/35-diskspace new file mode 100755 index 0000000..80ec222 --- /dev/null +++ b/update-motd/35-diskspace @@ -0,0 +1,39 @@ +#!/bin/bash + +# config +max_usage=90 +bar_width=50 +# colors +white="\e[39m" +green="\e[1;32m" +red="\e[1;31m" +dim="\e[2m" +undim="\e[0m" + +# disk usage: ignore zfs, squashfs & tmpfs +mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs --output=target,pcent,size | tail -n+2) +for line in "${dfs[@]}"; do + # get disk usage + usage=$(echo "$line" | awk '{print $2}' | sed 's/%//') + used_width=$((($usage*$bar_width)/100)) + # color is green if usage < max_usage, else red + if [ "${usage}" -ge "${max_usage}" ]; then + color=$red + else + color=$green + fi + # print green/red bar until used_width + bar="[${color}" + for ((i=0; i<$used_width; i++)); do + bar+="=" + done + # print dimmmed bar until end + bar+="${white}${dim}" + for ((i=$used_width; i<$bar_width; i++)); do + bar+="=" + done + bar+="${undim}]" + # print usage line & bar + printf " Disk usage:\\n" | /usr/games/lolcat -f + echo -e "${bar}" | sed -e 's/^/ /' +done diff --git a/update-motd/90-motd b/update-motd/90-motd new file mode 100755 index 0000000..6b4e8a5 --- /dev/null +++ b/update-motd/90-motd @@ -0,0 +1,4 @@ +#!/bin/bash + +printf "\\n" +grep -v '^<' /var/wiki/changelog.html | awk -v RS= 'NR==1 || NR==2 {print $0 "\n"}' | /usr/games/lolcat -f