xref: /dragonfly/etc/rc.d/motd (revision 38a690d7)
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# $DragonFly: src/etc/rc.d/motd,v 1.1 2003/07/24 06:35:37 dillon Exp $
6#
7
8# PROVIDE: motd
9# REQUIRE: mountcritremote
10# BEFORE:  LOGIN
11# KEYWORD: DragonFly FreeBSD NetBSD
12
13. /etc/rc.subr
14
15name="motd"
16rcvar="update_motd"
17start_cmd="motd_start"
18stop_cmd=":"
19
20case ${OSTYPE} in
21DragonFly)
22	 PERMS="644"
23        ;;
24
25FreeBSD)
26	PERMS="644"
27	;;
28NetBSD)
29	PERMS="664"
30	;;
31esac
32
33motd_start()
34{
35	#	Update kernel info in /etc/motd
36	#	Must be done *before* interactive logins are possible
37	#	to prevent possible race conditions.
38	#
39	echo "Updating motd."
40	if [ ! -f /etc/motd ]; then
41		install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
42	fi
43
44	case ${OSTYPE} in
45	DragonFly)
46		T=`mktemp -t motd`
47                uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
48                awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
49                ;;
50	FreeBSD)
51		T=`mktemp -t motd`
52		uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
53		awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
54		;;
55	NetBSD)
56		T='/etc/_motd'
57		sysctl -n kern.version | while read i; do echo $i; break; done > $T
58		sed '1{/^NetBSD.*/{d;};};' < /etc/motd >> $T
59		;;
60	esac
61	cmp -s $T /etc/motd || {
62		cp $T /etc/motd
63		chmod ${PERMS} /etc/motd
64	}
65	rm -f $T
66}
67
68load_rc_config $name
69run_rc_command "$1"
70