Merge branch 'vendor/FILE'
[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.10 2005/11/19 21:47:32 swildner Exp $
6 #
7
8 # PROVIDE: motd
9 # REQUIRE: mountcritremote
10 # BEFORE:  LOGIN
11
12 . /etc/rc.subr
13
14 name="motd"
15 rcvar="update_motd"
16 start_cmd="motd_start"
17 stop_cmd=":"
18 PERMS="644"
19
20 motd_start()
21 {
22         #       Update kernel info in /etc/motd
23         #       Must be done *before* interactive logins are possible
24         #       to prevent possible race conditions.
25         #
26         echo "Updating motd."
27         if [ ! -f /etc/motd ]; then
28                 install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
29         fi
30         T1=`mktemp -t motd`
31         awk 'NR == 1{if ($1 == "DragonFly") {print} else {exit 1}}' < /etc/motd > $T1 && {      
32
33         T2=`mktemp -t motd`
34         uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T2}
35         cmp -s $T1 $T2 || {
36                        awk '{if (NR == 1) {next} else {print}}' < /etc/motd >> ${T2}
37                        cp $T2 /etc/motd
38                        chmod ${PERMS} /etc/motd
39                        rm -f $T2
40                }
41         }
42         rm -f $T1 $T2
43 }
44 load_rc_config $name
45 run_rc_command "$1"