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