aboutsummaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2019-07-20 20:56:31 +0000
committerConrad Meyer <cem@FreeBSD.org>2019-07-20 20:56:31 +0000
commit2826da432cfda62b5512dfa72641c77fc10373d0 (patch)
treebbb41694b0b06ca8eb111a53d2cce03821ceaf69 /libexec
parent6d5685c76278d8a3b7765b03bc33f0152af8f7a9 (diff)
downloadsrc-2826da432cfda62b5512dfa72641c77fc10373d0.tar.gz
src-2826da432cfda62b5512dfa72641c77fc10373d0.zip
motd: Generate from template to /var/run
Update login(1), its manual pages, similar utilities, and motd.5 to refer to the new location. Suggested by: delphij@ (re: r349256) Reviewed by: bcr (manpages), delphij Differential Revision: https://reviews.freebsd.org/D20721
Notes
Notes: svn path=/head/; revision=350184
Diffstat (limited to 'libexec')
-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 '.'
}