xref: /dragonfly/etc/rc.d/motd (revision 35e996c9)
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#
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
18motd_start()
19{
20	#	Update kernel info in /etc/motd
21	#	Must be done *before* interactive logins are possible
22	#	to prevent possible race conditions.
23	#
24	local target="/etc/motd"
25	local old new exp temp
26
27	echo "Updating motd."
28	if [ ! -f "${target}" ]; then
29		install -o root -g wheel -m 0644 /dev/null ${target}
30	fi
31
32	old=$(awk '
33	NR == 1 {
34		if ($1 == "DragonFly") { print } else { exit 1 }
35	}' < ${target})
36	if [ $? -ne 0 ]; then
37		return  # custom motd
38	fi
39
40	exp='s@([^#]*) #(.* [1-2][0-9]{3}).*/([^/ ]+) *$@\1 (\3) #\2@'
41	new=$(uname -v | sed -E -e "${exp}")
42	if [ "${old}" != "${new}" ]; then
43		temp=$(mktemp -t motd)
44		printf '%s\n' "${new}" > ${temp}
45		tail -n +2 ${target} >> ${temp}
46		cat ${temp} > ${target}
47		rm -f ${temp}
48	fi
49}
50
51load_rc_config $name
52run_rc_command "$1"
53