Bring RCNG in from 5.x and adjust config files and scripts accordingly.
[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.1 2003/07/24 06:35:37 dillon Exp $
6 #
7
8 # PROVIDE: motd
9 # REQUIRE: mountcritremote
10 # BEFORE:  LOGIN
11 # KEYWORD: DragonFly FreeBSD NetBSD
12
13 . /etc/rc.subr
14
15 name="motd"
16 rcvar="update_motd"
17 start_cmd="motd_start"
18 stop_cmd=":"
19
20 case ${OSTYPE} in
21 DragonFly)
22          PERMS="644"
23         ;;
24
25 FreeBSD)
26         PERMS="644"
27         ;;
28 NetBSD)
29         PERMS="664"
30         ;;
31 esac
32
33 motd_start()
34 {
35         #       Update kernel info in /etc/motd
36         #       Must be done *before* interactive logins are possible
37         #       to prevent possible race conditions.
38         #
39         echo "Updating motd."
40         if [ ! -f /etc/motd ]; then
41                 install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
42         fi
43
44         case ${OSTYPE} in
45         DragonFly)
46                 T=`mktemp -t motd`
47                 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
48                 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
49                 ;;
50         FreeBSD)
51                 T=`mktemp -t motd`
52                 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
53                 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
54                 ;;
55         NetBSD)
56                 T='/etc/_motd'
57                 sysctl -n kern.version | while read i; do echo $i; break; done > $T
58                 sed '1{/^NetBSD.*/{d;};};' < /etc/motd >> $T
59                 ;;
60         esac
61         cmp -s $T /etc/motd || {
62                 cp $T /etc/motd
63                 chmod ${PERMS} /etc/motd
64         }
65         rm -f $T
66 }
67
68 load_rc_config $name
69 run_rc_command "$1"