motd revision 197947
1317017Sdim#!/bin/sh
2317017Sdim#
3353358Sdim# $FreeBSD: head/etc/rc.d/motd 197947 2009-10-10 22:17:03Z dougb $
4353358Sdim#
5353358Sdim
6317017Sdim# PROVIDE: motd
7317017Sdim# REQUIRE: mountcritremote
8317017Sdim# BEFORE:  LOGIN
9317017Sdim
10317017Sdim. /etc/rc.subr
11317017Sdim
12317017Sdimname="motd"
13317017Sdimrcvar="update_motd"
14317017Sdimstart_cmd="motd_start"
15317017Sdimstop_cmd=":"
16317017Sdim
17317778SdimPERMS="644"
18317017Sdim
19341825Sdimmotd_start()
20317017Sdim{
21317017Sdim	#	Update kernel info in /etc/motd
22317017Sdim	#	Must be done *before* interactive logins are possible
23341825Sdim	#	to prevent possible race conditions.
24317017Sdim	#
25317017Sdim	check_startmsgs && echo -n 'Updating motd:'
26317017Sdim	if [ ! -f /etc/motd ]; then
27317017Sdim		install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
28317017Sdim	fi
29317017Sdim
30317017Sdim	if [ ! -w /etc/motd ]; then
31317017Sdim		echo ' /etc/motd is not writable, update failed.'
32317017Sdim		return
33317017Sdim	fi
34317017Sdim
35327952Sdim	T=`mktemp -t motd`
36317017Sdim	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
37317017Sdim	awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
38317017Sdim
39317017Sdim	cmp -s $T /etc/motd || {
40317017Sdim		cp $T /etc/motd
41320970Sdim		chmod ${PERMS} /etc/motd
42317017Sdim	}
43317017Sdim	rm -f $T
44317017Sdim
45317017Sdim	check_startmsgs && echo '.'
46317017Sdim}
47317017Sdim
48317017Sdimload_rc_config $name
49317017Sdimrun_rc_command "$1"
50317017Sdim