Skip to content

Commit

Permalink
Implement showing Message of the Day always by creating a file called…
Browse files Browse the repository at this point in the history
… `.motd_show_always` at HOME. WhitewaterFoundry/Pengwin#766
  • Loading branch information
crramirez committed Mar 2, 2024
1 parent 37d4698 commit 143d6e0
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions profile.d/update-motd.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 143d6e0

Please sign in to comment.