aboutsummaryrefslogtreecommitdiffstats
path: root/libexec/rc/rc.d/motd
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/rc/rc.d/motd')
-rwxr-xr-xlibexec/rc/rc.d/motd46
1 files changed, 25 insertions, 21 deletions
diff --git a/libexec/rc/rc.d/motd b/libexec/rc/rc.d/motd
index 2c06187c1d2a..e63973945f9d 100755
--- a/libexec/rc/rc.d/motd
+++ b/libexec/rc/rc.d/motd
@@ -4,48 +4,52 @@
#
# PROVIDE: motd
-# REQUIRE: mountcritremote
+# REQUIRE: mountcritremote FILESYSTEMS
# BEFORE: LOGIN
. /etc/rc.subr
name="motd"
-desc="Update /etc/motd"
+desc="Update /var/run/motd"
rcvar="update_motd"
start_cmd="motd_start"
stop_cmd=":"
+COMPAT_MOTD="/etc/motd"
+TARGET="/var/run/motd"
+TEMPLATE="/etc/motd.template"
PERMS="644"
motd_start()
{
- # Update kernel info in /etc/motd
+ # Update kernel info in /var/run/motd
# Must be done *before* interactive logins are possible
# to prevent possible race conditions.
#
check_startmsgs && echo -n 'Updating motd:'
- if [ ! -f /etc/motd ]; then
- install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd
- fi
-
- if [ ! -w /etc/motd ]; then
- echo ' /etc/motd is not writable, update failed.'
- return
+ if [ ! -f "${TEMPLATE}" ]; then
+ # Create missing template from existing regular motd file, if
+ # one exists.
+ if [ -f "${COMPAT_MOTD}" ]; then
+ sed '1{/^FreeBSD.*/{d;};};' "${COMPAT_MOTD}" > "${TEMPLATE}"
+ chmod $PERMS "${TEMPLATE}"
+ rm -f "${COMPAT_MOTD}"
+ else
+ # Otherwise, create an empty template file.
+ install -c -o root -g wheel -m ${PERMS} /dev/null "${TEMPLATE}"
+ fi
+ # Provide compatibility symlink:
+ if [ ! -h "${COMPAT_MOTD}" ]; then
+ ln -sF "${TARGET}" "${COMPAT_MOTD}"
+ fi
fi
T=`mktemp -t motd`
uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
- awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
-
- if ! cmp -s $T /etc/motd; then
- mv -f $T /etc/.motd.tmp
- fsync /etc/.motd.tmp
- mv -f /etc/.motd.tmp /etc/motd
- chmod ${PERMS} /etc/motd
- fsync /etc
- else
- rm -f $T
- fi
+ cat "${TEMPLATE}" >> ${T}
+
+ install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}"
+ rm -f "$T"
check_startmsgs && echo '.'
}