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