xref: /freebsd/libexec/rc/rc.d/motd (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: motd
7# REQUIRE: mountcritremote FILESYSTEMS
8# BEFORE:  LOGIN
9
10. /etc/rc.subr
11
12name="motd"
13desc="Update /var/run/motd"
14rcvar="update_motd"
15start_cmd="motd_start"
16stop_cmd=":"
17
18COMPAT_MOTD="/etc/motd"
19TARGET="/var/run/motd"
20TEMPLATE="/etc/motd.template"
21PERMS="644"
22
23motd_start()
24{
25	#	Update kernel info in /var/run/motd
26	#	Must be done *before* interactive logins are possible
27	#	to prevent possible race conditions.
28	#
29	startmsg -n 'Updating motd:'
30	if [ ! -f "${TEMPLATE}" ]; then
31		# Create missing template from existing regular motd file, if
32		# one exists.
33		if [ -f "${COMPAT_MOTD}" ]; then
34			sed '1{/^FreeBSD.*/{d;};};' "${COMPAT_MOTD}" > "${TEMPLATE}"
35			chmod $PERMS "${TEMPLATE}"
36			rm -f "${COMPAT_MOTD}"
37		else
38			# Otherwise, create an empty template file.
39			install -c -o root -g wheel -m ${PERMS} /dev/null "${TEMPLATE}"
40		fi
41		# Provide compatibility symlink:
42		if [ ! -h "${COMPAT_MOTD}" ]; then
43			ln -sF "${TARGET}" "${COMPAT_MOTD}"
44		fi
45	fi
46
47	T=`mktemp -t motd`
48	uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
49	cat "${TEMPLATE}" >> ${T}
50
51	install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}"
52	rm -f "$T"
53
54	startmsg '.'
55}
56
57load_rc_config $name
58run_rc_command "$1"
59