Add scripts
This commit is contained in:
43
01-banner.sh
Normal file
43
01-banner.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Dynamic login banner. Installed to /etc/update-motd.d/ (executable) or
|
||||
# rendered once into /etc/motd as a fallback. Keep it fast & dependency-free.
|
||||
|
||||
# --- colors (only if stdout is a tty; motd.d output is captured, so keep plain)
|
||||
B=$'\e[1m'; D=$'\e[2m'; G=$'\e[32m'; Y=$'\e[33m'; R=$'\e[31m'; C=$'\e[36m'; N=$'\e[0m'
|
||||
|
||||
host="$(hostname -f 2>/dev/null || hostname)"
|
||||
os="$(. /etc/os-release 2>/dev/null && echo "${PRETTY_NAME:-Linux}")"
|
||||
kern="$(uname -r)"
|
||||
up="$(uptime -p 2>/dev/null | sed 's/^up //')"
|
||||
load="$(cut -d' ' -f1-3 /proc/loadavg 2>/dev/null)"
|
||||
ipaddr="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{print $7; exit}')"
|
||||
[ -z "$ipaddr" ] && ipaddr="n/a"
|
||||
|
||||
# memory + disk (root fs)
|
||||
mem="$(free -h 2>/dev/null | awk '/^Mem:/ {print $3 "/" $2}')"
|
||||
disk="$(df -h / 2>/dev/null | awk 'NR==2 {print $3 "/" $2 " (" $5 ")"}')"
|
||||
|
||||
# pending updates (apt) + reboot flag - cheap checks, ignore errors
|
||||
updates=""
|
||||
if [ -r /var/lib/update-notifier/updates-available ]; then
|
||||
updates="$(awk 'NR==1{print}' /var/lib/update-notifier/updates-available 2>/dev/null)"
|
||||
fi
|
||||
reboot_flag=""
|
||||
[ -f /var/run/reboot-required ] && reboot_flag="${R} reboot required${N}"
|
||||
|
||||
# load colorization
|
||||
load1="${load%% *}"
|
||||
lc="$G"
|
||||
awk "BEGIN{exit !($load1 > 2.0)}" && lc="$Y"
|
||||
awk "BEGIN{exit !($load1 > 4.0)}" && lc="$R"
|
||||
|
||||
printf '\n'
|
||||
printf ' %s%s%s\n' "$B$C" "$host" "$N"
|
||||
printf ' %s%s%s\n' "$D" "$os · kernel $kern" "$N"
|
||||
printf '\n'
|
||||
printf ' %sIP%s %s\n' "$D" "$N" "$ipaddr"
|
||||
printf ' %sUptime%s %s %sload%s %s%s%s\n' "$D" "$N" "${up:-n/a}" "$D" "$N" "$lc" "$load" "$N"
|
||||
printf ' %sMem%s %s %sdisk /%s %s\n' "$D" "$N" "${mem:-n/a}" "$D" "$N" "${disk:-n/a}"
|
||||
[ -n "$updates" ] && printf ' %sUpdates%s %s\n' "$D" "$N" "$updates"
|
||||
[ -n "$reboot_flag" ] && printf ' %s\n' "$reboot_flag"
|
||||
printf '\n'
|
||||
Reference in New Issue
Block a user