diff --git a/profile.d/update-motd.sh b/profile.d/update-motd.sh index 7cbdc28..6279ad6 100644 --- a/profile.d/update-motd.sh +++ b/profile.d/update-motd.sh @@ -1,17 +1,35 @@ #!/bin/sh +# bashsupport disable=BP5007 -# runs the scripts on /etc/update-motd.d +hushlogin_not_enabled() { + [ ! -e "${hushlogin_file}" ] +} -motd_shown_file="$HOME/.motd_shown" -hushlogin_file="$HOME/.hushlogin" +motd_shown_today() { + find "${motd_shown_file}" -newermt 'today 0:00' 2>/dev/null | grep -q -m 1 '' +} -if [ ! -e "${hushlogin_file}" ] && ! find "${motd_shown_file}" -newermt 'today 0:00' 2>/dev/null | grep -q -m 1 ''; then - run-parts --lsbsysinit /etc/update-motd.d - touch "${motd_shown_file}" - printf "\n" - printf "This message is shown once a day. To disable it you can create the %s file" "${hushlogin_file}" - printf "\n\n" -fi +motd_show_always() { + [ -e "${motd_show_always_file}" ] +} -unset motd_shown_file -unset hushlogin_file +main() { + # runs the scripts on /etc/update-motd.d + motd_shown_file="$HOME/.motd_shown" + hushlogin_file="$HOME/.hushlogin" + motd_show_always_file="$HOME/.motd_show_always" + + if motd_show_always || (hushlogin_not_enabled && ! motd_shown_today); then + run-parts --lsbsysinit /etc/update-motd.d + touch "${motd_shown_file}" + printf "\n" + printf "This message is shown once a day. To disable it you can create the %s file" "${hushlogin_file}" + printf "\n\n" + fi + + unset motd_shown_file + unset hushlogin_file + unset motd_show_always_file +} + +main "$@"