first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / core / byemessage.sh
1 #!/bin/bash
2 # byemessage prints out a nechung message as part of logging out.
3 # the first parameter is the file or device to send the message to.
4 # if it is blank, then standard output is used.
5
6 # figure out where they want to show the message, or pick a default.
7 TARGET_CONSOLE=$1
8 if [ -z "$TARGET_CONSOLE" ]; then
9   TARGET_CONSOLE=/dev/console
10 fi
11
12 # FORTUNE_TO_SHOW is a massaged form of a fortune cookie output.
13 export FORTUNE_TO_SHOW="$(mktemp "$TMP/zz_nechung.XXXXXX")"
14
15 # see if we can send out a screen blank character.
16 echo -e '\0xc' >$FORTUNE_TO_SHOW
17 #####echo >>$FORTUNE_TO_SHOW  # first blank line in the file.
18 # add lots of blank lines.
19 for ((i=0; i<100; i++)); do echo >>$FORTUNE_TO_SHOW; done
20 # drop in a fortune cookie.
21 $BINDIR/nechung >>$FORTUNE_TO_SHOW
22 # a couple extra blank lines.
23 for i in 1 2 3; do echo >>$FORTUNE_TO_SHOW; done
24 # and a reprinting of a login menu, since that's actually where we're
25 # intended to leave the machine at.
26 if [ -f /etc/issue.net ]; then
27   cat /etc/issue.net >>$FORTUNE_TO_SHOW
28 elif [ -f /etc/issue ]; then
29   cat /etc/issue >>$FORTUNE_TO_SHOW
30 fi
31 echo -ne "$(hostname) login: " >>$FORTUNE_TO_SHOW
32
33 # clear the screen, if we can.
34 clear_console
35
36 # we have to do extra processing to send the file out to the console.
37 tr '\n' '\a' <$FORTUNE_TO_SHOW | sed -r -e 's/\a/\r\n/g' >$TARGET_CONSOLE
38
39 # clean up.
40 /bin/rm $FORTUNE_TO_SHOW
41