[BACK]Return to motd CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc / rc.d

File: [cvs.NetBSD.org] / src / etc / rc.d / motd (download)

Revision 1.11, Fri Sep 11 12:50:14 2020 UTC (3 years, 7 months ago) by kim
Branch: MAIN
CVS Tags: netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, HEAD
Changes since 1.10: +5 -5 lines

Make a ": " suffix a fixed part of the release info tag

This results in correct updates to /etc/motd even when the value of
motd_release_tag is changed (a likely event).

Add safe quoting to outputting the read kernel version.

Thanks to kre@ for the feedback.

#!/bin/sh
#
# $NetBSD: motd,v 1.11 2020/09/11 12:50:14 kim Exp $
#

# PROVIDE: motd
# REQUIRE: mountcritremote
# BEFORE:  LOGIN

$_rc_subr_loaded . /etc/rc.subr

name="motd"
rcvar="update_motd"
start_cmd="motd_start"
stop_cmd=":"

motd_start()
{
	#	Update kernel and release info in /etc/motd
	#	Must be done *before* interactive logins are possible
	#	to prevent possible race conditions.
	#
	echo "Updating motd."
	if [ ! -f /etc/motd ]; then
		install -c -o root -g wheel -m 664 /dev/null /etc/motd
	fi
	( umask 022
	T=/etc/_motd
	sysctl -n kern.version | while read i; do echo "$i"; break; done > $T
	if checkyesno update_motd_release; then
		local t=$(echo "${motd_release_tag%%:*}" | tr -d /)
		sed -En '1{/^NetBSD/{'"${t:+s/^/${t}: /;}"'h;d;};q;}
		    /^ *Build ID */{s//(/;s/$/)/;H;g;y/\n/ /;p;q;}
		    ${g;p;}' < /etc/release >> $T
		sed -E '1,2{/^([^:]*: )?NetBSD/{d;};};' \
		    < /etc/motd >> $T
	else
		sed '1{/^NetBSD.*/{d;};};' < /etc/motd >> $T
	fi
	cmp -s $T /etc/motd || cp $T /etc/motd
	rm -f $T
	)
}

load_rc_config $name
run_rc_command "$1"