motd.sh: improve overall display
This commit is contained in:
parent
39b4cdc3c0
commit
677a72700d
117
motd.sh
117
motd.sh
@ -4,26 +4,34 @@
|
|||||||
echo -e "$(date)"
|
echo -e "$(date)"
|
||||||
echo -e
|
echo -e
|
||||||
|
|
||||||
|
|
||||||
### Hostname ###
|
### Hostname ###
|
||||||
echo -e "$(/usr/bin/env figlet -w $(tput cols) "$(hostname)" | /usr/bin/env lolcat -f -F 0.05 -S $(echo $((0x$(hostname | md5sum | cut -c 1-10))) | cut -c 2-5))"
|
seed=$(echo $((0x$(hostname | md5sum | cut -c 1-10))) | cut -c 2-5)
|
||||||
|
echo -e "$(/usr/bin/env figlet -w $(tput cols) "$(hostname)" | /usr/bin/env lolcat -f -F 0.05 -S $seed)"
|
||||||
echo -e
|
echo -e
|
||||||
|
|
||||||
|
|
||||||
### System info ###
|
### System info ###
|
||||||
echo -e "$(cat /etc/*release | grep PRETTY_NAME | cut -d = -f 2- | sed 's/\"//g') | Kernel: $(uname -r)
|
echo -e "$(cat /etc/*release | grep PRETTY_NAME | cut -d = -f 2- | sed 's/\"//g') | Kernel: $(uname -r)"
|
||||||
Uptime: $(uptime -p | sed 's/up //')"
|
echo -e "Uptime: $(uptime -p | sed 's/up //')"
|
||||||
|
echo -e
|
||||||
|
|
||||||
|
### Colors ###
|
||||||
### Services ###
|
white="\e[39m"
|
||||||
# set column width
|
|
||||||
COLUMNS=1
|
|
||||||
# colors
|
|
||||||
green="\e[1;32m"
|
green="\e[1;32m"
|
||||||
red="\e[1;31m"
|
red="\e[1;31m"
|
||||||
|
magenta="\e[1;35m"
|
||||||
|
lightgreen="\e[1;92m"
|
||||||
|
lightred="\e[1;91m"
|
||||||
|
yellow="\e[1;33m"
|
||||||
|
lightyellow="\e[1;93m"
|
||||||
|
dim="\e[2m"
|
||||||
|
bold="\e[1m"
|
||||||
undim="\e[0m"
|
undim="\e[0m"
|
||||||
|
|
||||||
|
graybg="\e[40m"
|
||||||
|
redbg="\e[41m"
|
||||||
|
greenbg="\e[42m"
|
||||||
|
|
||||||
|
### Services ###
|
||||||
services=($(cat /.motd.services))
|
services=($(cat /.motd.services))
|
||||||
# sort services
|
# sort services
|
||||||
#IFS=$'\n' services=($(sort <<<"${services[*]}"))
|
#IFS=$'\n' services=($(sort <<<"${services[*]}"))
|
||||||
@ -34,73 +42,65 @@ service_status=()
|
|||||||
for service in "${services[@]}"; do
|
for service in "${services[@]}"; do
|
||||||
service_status+=($(systemctl is-active "$service"))
|
service_status+=($(systemctl is-active "$service"))
|
||||||
done
|
done
|
||||||
|
out=" SERVICE,STATUS\n"
|
||||||
out=""
|
out+="${bold}[SYSTEMD]${undim}\n"
|
||||||
for i in "${!services[@]}"; do
|
for i in "${!services[@]}"; do
|
||||||
# color green if service is active, else red
|
# color green if service is active, else red
|
||||||
if [[ "${service_status[$i]}" == "active" ]]; then
|
if [[ "${service_status[$i]}" == "active" ]]; then
|
||||||
out+="${services[$i]}:,${green}${service_status[$i]}${undim},"
|
out+=" - ${services[$i]},${green}${service_status[$i]}${undim}\n"
|
||||||
else
|
else
|
||||||
out+="${services[$i]}:,${red}${service_status[$i]}${undim},"
|
out+=" ${redbg}/!\\\\${undim} - ${services[$i]},${red}${service_status[$i]}${undim}\n"
|
||||||
fi
|
|
||||||
# insert \n every $COLUMNS column
|
|
||||||
if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then
|
|
||||||
out+="\n"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
out+="\n"
|
|
||||||
|
|
||||||
printf "\nServices:\n"
|
|
||||||
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|
|
||||||
|
|
||||||
|
|
||||||
### Docker ###
|
### Docker ###
|
||||||
|
out+="${bold}[DOCKER]${undim}\n"
|
||||||
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
|
containers=($(docker ps --format "{{.Image}}/{{.Names}}"))
|
||||||
container_statuses=($(docker ps --format "{{.State}}"))
|
container_statuses=($(docker ps --format "{{.State}}"))
|
||||||
out=""
|
docker_out=" [root]\n"
|
||||||
for i in ${!containers[@]}; do
|
for i in ${!containers[@]}; do
|
||||||
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
||||||
out+="${containers[$i]}:,${green}${container_statuses[$i]}${undim},"
|
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
|
||||||
else
|
else
|
||||||
out+="${containers[$i]}:,${red}${container_statuses[$i]}${undim},"
|
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
|
||||||
fi
|
fi
|
||||||
out+="\n"
|
|
||||||
done
|
done
|
||||||
printf "\nDocker:\n"
|
|
||||||
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|
|
||||||
|
|
||||||
|
docker_out+=" [rootless]\n"
|
||||||
rootless_users=($(cat /.motd.users))
|
rootless_users=($(cat /.motd.users))
|
||||||
for user in ${rootless_users[@]}; do
|
for user in ${rootless_users[@]}; do
|
||||||
|
|
||||||
|
if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then
|
||||||
|
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! Docker not running !${undim}\n"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
containers=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.Image}}/{{.Names}}"))
|
containers=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.Image}}/{{.Names}}"))
|
||||||
container_statuses=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.State}}"))
|
container_statuses=($(sudo -n DOCKER_HOST=unix:///run/user/$(id -u $user)/docker.sock docker ps --format "{{.State}}"))
|
||||||
out=""
|
if [ ${#containers[@]} -eq 0 ]; then
|
||||||
|
docker_out+=" ${redbg}/!\\\\${undim} - $user,${red}! No container !${undim}\n"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker_out+=" - $user\n"
|
||||||
for i in ${!containers[@]}; do
|
for i in ${!containers[@]}; do
|
||||||
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
if [[ "${container_statuses[$i]}" == "running" ]]; then
|
||||||
out+="${containers[$i]}:,${green}${container_statuses[$i]}${undim},"
|
docker_out+=" - ${containers[$i]},${green}${container_statuses[$i]}${undim}\n"
|
||||||
else
|
else
|
||||||
out+="${containers[$i]}:,${red}${container_statuses[$i]}${undim},"
|
docker_out+=" ${redbg}/!\\\\${undim} - ${containers[$i]},${red}${container_statuses[$i]}${undim}\n"
|
||||||
fi
|
fi
|
||||||
out+="\n"
|
|
||||||
done
|
done
|
||||||
printf "\nDocker > $user:\n"
|
|
||||||
printf "$out" | column -ts $',' | sed -e 's/^/ /'
|
|
||||||
done
|
done
|
||||||
|
out+=$docker_out
|
||||||
|
|
||||||
|
printf "$out" | column -ts $',' -o " "
|
||||||
|
echo -e
|
||||||
|
|
||||||
### Disk space ###
|
### Disk space ###
|
||||||
# config
|
# config
|
||||||
max_usage=80
|
max_usage=80
|
||||||
bar_width=50
|
bar_width=50
|
||||||
# colors
|
|
||||||
white="\e[39m"
|
|
||||||
green="\e[1;32m"
|
|
||||||
red="\e[1;31m"
|
|
||||||
magenta="\e[1;35m"
|
|
||||||
lightgreen="\e[1;92m"
|
|
||||||
lightred="\e[1;91m"
|
|
||||||
yellow="\e[1;33m"
|
|
||||||
lightyellow="\e[1;93m"
|
|
||||||
dim="\e[2m"
|
|
||||||
undim="\e[0m"
|
|
||||||
|
|
||||||
# disk usage: ignore zfs, squashfs & tmpfs
|
# disk usage: ignore zfs, squashfs & tmpfs
|
||||||
DISKS=$(df -H -x squashfs -x tmpfs -x devtmpfs -x zfs --output=target,pcent,size,used | tail -n+2)" 0 0 0 -"
|
DISKS=$(df -H -x squashfs -x tmpfs -x devtmpfs -x zfs --output=target,pcent,size,used | tail -n+2)" 0 0 0 -"
|
||||||
@ -120,7 +120,7 @@ if test $(command -v zfs); then
|
|||||||
DISKS+="$name $pcent% $gfxsize $gfxused $usedsnappercent $useddspercent $usedchildpercent x$compressratio\n"
|
DISKS+="$name $pcent% $gfxsize $gfxused $usedsnappercent $useddspercent $usedchildpercent x$compressratio\n"
|
||||||
done <<< $(zfs list -H -p -d 0 -o name,available,used,usedsnap,usedds,usedchild,compressratio)
|
done <<< $(zfs list -H -p -d 0 -o name,available,used,usedsnap,usedds,usedchild,compressratio)
|
||||||
fi
|
fi
|
||||||
printf "\nDisk usage:\n"
|
printf "${bold}[DISK USAGE]${undim}\n"
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
if [ -z "$line" ]; then
|
if [ -z "$line" ]; then
|
||||||
@ -189,16 +189,15 @@ while read line; do
|
|||||||
bar+="${undim}]"
|
bar+="${undim}]"
|
||||||
|
|
||||||
# print usage line & bar
|
# print usage line & bar
|
||||||
echo "${line}" | awk '{ printf("%-19scompratio %+5s %+4s/%+4s [%+3s]\n", $1, $8, $4, $3, $2); }' | sed -e 's/^/ /'
|
echo -e "${line}" | awk '{ printf(" %-19scompratio %+5s %+4s/%+4s [%+3s]\n", $1, $8, $4, $3, $2); }'
|
||||||
echo -e "${bar}" | sed -e 's/^/ /'
|
if [ "${usage}" -ge "${max_usage}" ]; then
|
||||||
|
echo -en " ${redbg}/!\\\\${undim} "
|
||||||
|
else
|
||||||
|
echo -en " "
|
||||||
|
fi
|
||||||
|
echo -e "${bar}"
|
||||||
done <<< $(echo -e "$DISKS")
|
done <<< $(echo -e "$DISKS")
|
||||||
|
|
||||||
|
|
||||||
### Welcome message ###
|
|
||||||
LAST_LOGIN=$(last -w --time-format iso | grep $(whoami) | head -2 | tail -1)
|
|
||||||
echo -e
|
echo -e
|
||||||
echo -e "Welcome to $(hostname), $(whoami)!
|
|
||||||
Last login: $(echo "$LAST_LOGIN" | awk '{for(i=4;i<=NF;i++) print $i}' | paste -sd ' ') from $(echo "$LAST_LOGIN" | awk '{print $3}')"
|
|
||||||
|
|
||||||
### ZFS available space warning ###
|
### ZFS available space warning ###
|
||||||
if test $(command -v zfs); then
|
if test $(command -v zfs); then
|
||||||
@ -211,7 +210,13 @@ if test $(command -v zfs); then
|
|||||||
percentage=$(echo "scale=2;$avail/($used+$avail)*100" | bc)
|
percentage=$(echo "scale=2;$avail/($used+$avail)*100" | bc)
|
||||||
|
|
||||||
if (( $(echo "$percentage < 20" | bc -l) )); then
|
if (( $(echo "$percentage < 20" | bc -l) )); then
|
||||||
echo -e "${red}Warning! ${white}$name ${undim}only has ${percentage}% capacity left"
|
echo -e " ${redbg}/!\\\\${undim} ${bold}$name ${undim}only has ${percentage}% capacity left"
|
||||||
fi
|
fi
|
||||||
done <<< $(echo -e "$POOLS")
|
done <<< $(echo -e "$POOLS")
|
||||||
fi
|
fi
|
||||||
|
echo -e
|
||||||
|
|
||||||
|
### Welcome message ###
|
||||||
|
LAST_LOGIN=$(last -w --time-format full | grep $(whoami) | head -2 | tail -1)
|
||||||
|
echo -e " Welcome to $(hostname | /usr/bin/env lolcat -f -F 0.05 -S $seed), ${green}$(whoami)${undim}!"
|
||||||
|
echo -e " Last login: ${bold}$(echo "$LAST_LOGIN" | awk '{print $3}')${undim} | [$(echo "$LAST_LOGIN" | awk '{for(i=4;i<=NF;i++) print $i}' | paste -sd ' ')]"
|
||||||
|
Loading…
Reference in New Issue
Block a user