9581f4a760cad40cd27be1a36d400f789ca46a58
[dragonfly.git] / etc / rc.d / motd
1 #!/bin/sh
2 #
3 # $NetBSD: motd,v 1.5 2000/09/19 13:04:38 lukem Exp $
4 # $FreeBSD: src/etc/rc.d/motd,v 1.6 2003/06/30 22:06:26 mtm Exp $
5 # $DragonFly: src/etc/rc.d/motd,v 1.8 2004/02/03 05:26:48 rob Exp $
6 #
7
8 # PROVIDE: motd
9 # REQUIRE: mountcritremote
10 # BEFORE:  LOGIN
11 # KEYWORD: DragonFly
12
13 . /etc/rc.subr
14
15 name="motd"
16 rcvar="update_motd"
17 start_cmd="motd_start"
18 stop_cmd=":"
19 PERMS="644"
20
21 motd_start()
22 {
23         #       Update kernel info in /etc/motd
24         #       Must be done *before* interactive logins are possible
25         #       to prevent possible race conditions.
26         #
27         echo "Updating motd."
28         if [ ! -f /etc/motd ]; then
29                 install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
30         fi
31         T1=`mktemp -t motd`
32         awk 'NR == 1{if ($1 == "DragonFly") {print} else {exit 1}}' < /etc/motd > $T1 && {      
33
34         T2=`mktemp -t motd`
35         uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T2}
36         cmp -s $T1 $T2 || {
37                        awk '{if (NR == 1) {next} else {print}}' < /etc/motd >> ${T2}
38                        cp $T2 /etc/motd
39                        chmod ${PERMS} /etc/motd
40                        rm -f $T2
41                }
42         }
43         rm -f $T1
44 }
45 load_rc_config $name
46 run_rc_command "$1"