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 fi 42 # Provide compatibility symlink: 43 if [ ! -h "${COMPAT_MOTD}" ]; then 44 ln -sF "${TARGET}" "${COMPAT_MOTD}" 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,' \ 49 -e 's,^\([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\)$,\1 \2 (\4) \3,' > ${T} 50 cat "${TEMPLATE}" >> ${T} 51 52 install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}" 53 rm -f "$T" 54 55 startmsg '.' 56} 57 58load_rc_config $name 59run_rc_command "$1" 60