motd revision 124616
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 124616 2004-01-17 10:16:38Z mtm $
5#
6
7# PROVIDE: motd
8# REQUIRE: mountcritremote
9# BEFORE:  LOGIN
10# KEYWORD: FreeBSD
11
12. /etc/rc.subr
13
14name="motd"
15rcvar="update_motd"
16start_cmd="motd_start"
17stop_cmd=":"
18
19PERMS="644"
20
21motd_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 -n 'Updating motd'
28	if [ ! -f /etc/motd ]; then
29		install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
30	fi
31
32	if [ ! -w /etc/motd ]; then
33		echo ' ... /etc/motd is not writable, update failed.'
34		return
35	fi
36
37	T=`mktemp -t motd`
38	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
39	awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
40
41	cmp -s $T /etc/motd || {
42		cp $T /etc/motd
43		chmod ${PERMS} /etc/motd
44	}
45	rm -f $T
46
47	echo .
48}
49
50load_rc_config $name
51run_rc_command "$1"
52