MOTDfetch/motdfetch.d/00-header

82 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-02-07 10:10:46 +01:00
#!/usr/bin/env bash
#
# display a custom decorative text (default to username)
# + welcome the username + date, time and timezone
# + inform of mail presence for user (if s-nail is installed)
#
# requirements: sudo apt install figlet
# sudo wget --no-check-certificate -O "/usr/share/figlet/ansi-shadow.flf" https://raw.githubusercontent.com/xero/figlet-fonts/master/ANSI%20Shadow.flf
# optionnal: sudo apt install s-nail
# GENERAL ###########################################################
# locale env
unset LC_ALL
export LC_MESSAGES=C
# check if module was disabled
module_disable=${module_header_disable:=0}
if (($module_disable == 1)); then
exit 1
fi
# colors
c_txt=${c_txt:="39"}
c_txt_emphase=${c_txt_emphase:="35"}
c_txt_deco=${c_txt_deco:="97"}
c_txt_invert=${c_txt_invert:="30"}
c_bg=${c_bg_sec:="47"}
c_danger=${c_danger:="31"}
c_warning=${c_warning:="33"}
c_success=${c_success:="32"}
c_title=${c_title:="${c_bg};1;${c_txt_invert}m"}
# OPTIONS ###########################################################
# banner custom text or username
username=$(/usr/bin/id -un)
header_text=${module_header_text:="$username"}
# PREPARATIONS ######################################################
# check if s-nail is available and if you have mail
if command -v s-nail 1>/dev/null; then
# check mail for user
if /usr/bin/s-nail -e; then
hasmail=$(echo -e " You have \e[1;${c_success}mmessages\e[0m.")
else
hasmail=$(echo -e " You have no messages.")
fi
else
hasmail=""
fi
# trim banner text
header_text_width=${#header_text}
figlet_width=$(/usr/bin/env figlet -f "ANSI Shadow" "$header_text" | wc -L)
while [[ $figlet_width -ge 73 ]]; do
let "header_text_width-=1"
header_text=$(echo -e "${header_text:0:$header_text_width}...")
figlet_width=$(/usr/bin/env figlet -f "ANSI Shadow" "$header_text" | wc -L)
done
# OUTPUT ############################################################
if [[ $module_header_text != "$username" ]]; then
/usr/bin/env figlet -f "ANSI Shadow" "$header_text" \
| sed "$d" \
| sed "s/^/ /" \
| echo -e "$(sed "1 s/^/\\\e[${c_txt_emphase}m/")" \
| echo -e "$(sed "$ s/$/\\\e[0m/")"
echo -e " \e[1;${c_txt}mWelcome \e[${c_txt_emphase}m${username}\e[${c_txt}m, it is \e[${c_txt_emphase}m$(date +"%Y-%m-%d %H:%M:%S %z")\e[${c_txt}m.\e[0m\n${hasmail}"
else
echo -e " Welcome"
/usr/bin/env figlet -f "ANSI Shadow" "$header_text" \
| sed "$d" \
| sed "s/^/ /" \
| echo -e "$(sed "1 s/^/\\\e[${c_txt_emphase}m/")" \
| echo -e "$(sed "$ s/$/\\\e[0m/")"
echo -e " \e[1;${c_txt}mIt is \e[${c_txt_emphase}m$(date +"%Y-%m-%d %H:%M:%S %z")\e[${c_txt}m.\e[0m\n${hasmail}"
fi