motd (7f49ce7a0b5f0d501d233308d73ccb1bf191a68b) | motd (2826da432cfda62b5512dfa72641c77fc10373d0) |
---|---|
1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# PROVIDE: motd | 1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# PROVIDE: motd |
7# REQUIRE: mountcritremote | 7# REQUIRE: mountcritremote FILESYSTEMS |
8# BEFORE: LOGIN 9 10. /etc/rc.subr 11 12name="motd" | 8# BEFORE: LOGIN 9 10. /etc/rc.subr 11 12name="motd" |
13desc="Update /etc/motd" | 13desc="Update /var/run/motd" |
14rcvar="update_motd" 15start_cmd="motd_start" 16stop_cmd=":" 17 | 14rcvar="update_motd" 15start_cmd="motd_start" 16stop_cmd=":" 17 |
18COMPAT_MOTD="/etc/motd" 19TARGET="/var/run/motd" 20TEMPLATE="/etc/motd.template" |
|
18PERMS="644" 19 20motd_start() 21{ | 21PERMS="644" 22 23motd_start() 24{ |
22 # Update kernel info in /etc/motd | 25 # Update kernel info in /var/run/motd |
23 # Must be done *before* interactive logins are possible 24 # to prevent possible race conditions. 25 # 26 check_startmsgs && echo -n 'Updating motd:' | 26 # Must be done *before* interactive logins are possible 27 # to prevent possible race conditions. 28 # 29 check_startmsgs && echo -n 'Updating motd:' |
27 if [ ! -f /etc/motd ]; then 28 install -c -o root -g wheel -m ${PERMS} /dev/null /etc/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 |
29 fi 30 | 45 fi 46 |
31 if [ ! -w /etc/motd ]; then 32 echo ' /etc/motd is not writable, update failed.' 33 return 34 fi 35 | |
36 T=`mktemp -t motd` 37 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} | 47 T=`mktemp -t motd` 48 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} |
38 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} | 49 cat "${TEMPLATE}" >> ${T} |
39 | 50 |
40 if ! cmp -s $T /etc/motd; then 41 mv -f $T /etc/.motd.tmp 42 fsync /etc/.motd.tmp 43 mv -f /etc/.motd.tmp /etc/motd 44 chmod ${PERMS} /etc/motd 45 fsync /etc 46 else 47 rm -f $T 48 fi | 51 install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}" 52 rm -f "$T" |
49 50 check_startmsgs && echo '.' 51} 52 53load_rc_config $name 54run_rc_command "$1" | 53 54 check_startmsgs && echo '.' 55} 56 57load_rc_config $name 58run_rc_command "$1" |