1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-25 11:37:56 +00:00

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
This commit is contained in:
Conrad Meyer 2019-07-20 20:56:31 +00:00
parent 6d5685c762
commit 2826da432c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350184
8 changed files with 48 additions and 34 deletions

View File

@ -4,48 +4,52 @@
# #
# PROVIDE: motd # PROVIDE: motd
# REQUIRE: mountcritremote # REQUIRE: mountcritremote FILESYSTEMS
# BEFORE: LOGIN # BEFORE: LOGIN
. /etc/rc.subr . /etc/rc.subr
name="motd" name="motd"
desc="Update /etc/motd" desc="Update /var/run/motd"
rcvar="update_motd" rcvar="update_motd"
start_cmd="motd_start" start_cmd="motd_start"
stop_cmd=":" stop_cmd=":"
COMPAT_MOTD="/etc/motd"
TARGET="/var/run/motd"
TEMPLATE="/etc/motd.template"
PERMS="644" PERMS="644"
motd_start() motd_start()
{ {
# Update kernel info in /etc/motd # Update kernel info in /var/run/motd
# Must be done *before* interactive logins are possible # Must be done *before* interactive logins are possible
# to prevent possible race conditions. # to prevent possible race conditions.
# #
check_startmsgs && echo -n 'Updating motd:' check_startmsgs && echo -n 'Updating motd:'
if [ ! -f /etc/motd ]; then if [ ! -f "${TEMPLATE}" ]; then
install -c -o root -g wheel -m ${PERMS} /dev/null /etc/motd # 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
if [ ! -w /etc/motd ]; then
echo ' /etc/motd is not writable, update failed.'
return
fi fi
T=`mktemp -t motd` T=`mktemp -t motd`
uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 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} cat "${TEMPLATE}" >> ${T}
if ! cmp -s $T /etc/motd; then install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}"
mv -f $T /etc/.motd.tmp rm -f "$T"
fsync /etc/.motd.tmp
mv -f /etc/.motd.tmp /etc/motd
chmod ${PERMS} /etc/motd
fsync /etc
else
rm -f $T
fi
check_startmsgs && echo '.' check_startmsgs && echo '.'
} }

View File

@ -39,7 +39,7 @@
#include <paths.h> #include <paths.h>
#define _PATH_HUSHLOGIN ".hushlogin" #define _PATH_HUSHLOGIN ".hushlogin"
#define _PATH_MOTDFILE "/etc/motd" #define _PATH_MOTDFILE "/var/run/motd"
#define _PATH_LOGACCESS "/etc/login.access" #define _PATH_LOGACCESS "/etc/login.access"
#define _PATH_FBTAB "/etc/fbtab" #define _PATH_FBTAB "/etc/fbtab"
#define _PATH_LOGINDEVPERM "/etc/logindevperm" #define _PATH_LOGINDEVPERM "/etc/logindevperm"

View File

@ -3,7 +3,7 @@
.\" This file is in the public domain. .\" This file is in the public domain.
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd February 13, 1997 .Dd July 20, 2019
.Dt MOTD 5 .Dt MOTD 5
.Os .Os
.Sh NAME .Sh NAME
@ -11,13 +11,16 @@
.Nd file containing message(s) of the day .Nd file containing message(s) of the day
.Sh DESCRIPTION .Sh DESCRIPTION
The file The file
.Pa /etc/motd .Pa /var/run/motd
is normally displayed by is normally displayed by
.Xr login 1 .Xr login 1
after a user has logged in but before the shell is run. after a user has logged in but before the shell is run.
It is generally used for important system-wide announcements. It is generally used for important system-wide announcements.
During system startup, a line containing the kernel version string is During system startup, a line containing the kernel version string is
prepended to this file. prepended to
.Pa /etc/motd.template
and the contents are written to
.Pa /var/run/motd .
.Pp .Pp
Individual users may suppress the display of this file by Individual users may suppress the display of this file by
creating a file named creating a file named
@ -26,11 +29,13 @@ in their home directories or through
.Xr login.conf 5 . .Xr login.conf 5 .
.Sh FILES .Sh FILES
.Bl -tag -width $HOME/.hushlogin -compact .Bl -tag -width $HOME/.hushlogin -compact
.It Pa /etc/motd .It Pa /etc/motd.template
The template file that system administrators can edit.
.It Pa /var/run/motd
The message of the day. The message of the day.
.It Pa $HOME/.hushlogin .It Pa $HOME/.hushlogin
Suppresses output of Suppresses output of
.Pa /etc/motd . .Pa /var/run/motd .
.El .El
.Sh EXAMPLES .Sh EXAMPLES
.Bd -literal .Bd -literal
@ -41,3 +46,9 @@ FreeBSD 2.1.6.1-RELEASE (GENERIC) #0: Sun Dec 29 03:08:31 PST 1996
.Sh SEE ALSO .Sh SEE ALSO
.Xr login 1 , .Xr login 1 ,
.Xr login.conf 5 .Xr login.conf 5
.Sh HISTORY
Prior to
.Fx 13.0 ,
.Nm
lived in
.Pa /etc .

View File

@ -3,7 +3,7 @@
.include <src.opts.mk> .include <src.opts.mk>
CONFS= fbtab login.conf motd login.access CONFS= fbtab login.conf motd.template login.access
PROG= login PROG= login
SRCS= login.c login_fbtab.c SRCS= login.c login_fbtab.c
CFLAGS+=-DLOGALL CFLAGS+=-DLOGALL

View File

@ -28,7 +28,7 @@
.\" @(#)login.1 8.2 (Berkeley) 5/5/94 .\" @(#)login.1 8.2 (Berkeley) 5/5/94
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd September 13, 2006 .Dd July 20, 2019
.Dt LOGIN 1 .Dt LOGIN 1
.Os .Os
.Sh NAME .Sh NAME
@ -131,7 +131,7 @@ result in an error exit from
changes device protections changes device protections
.It Pa /etc/login.conf .It Pa /etc/login.conf
login class capabilities database login class capabilities database
.It Pa /etc/motd .It Pa /var/run/motd
message-of-the-day message-of-the-day
.It Pa /var/mail/user .It Pa /var/mail/user
system mailboxes system mailboxes

View File

@ -25,7 +25,7 @@
default:\ default:\
:passwd_format=sha512:\ :passwd_format=sha512:\
:copyright=/etc/COPYRIGHT:\ :copyright=/etc/COPYRIGHT:\
:welcome=/etc/motd:\ :welcome=/var/run/motd:\
:setenv=MAIL=/var/mail/$,BLOCKSIZE=K:\ :setenv=MAIL=/var/mail/$,BLOCKSIZE=K:\
:path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin:\ :path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin:\
:nologin=/var/run/nologin:\ :nologin=/var/run/nologin:\
@ -120,7 +120,7 @@ russian|Russian Users Accounts:\
## ##
#standard:\ #standard:\
# :copyright=/etc/COPYRIGHT:\ # :copyright=/etc/COPYRIGHT:\
# :welcome=/etc/motd:\ # :welcome=/var/run/motd:\
# :setenv=MAIL=/var/mail/$,BLOCKSIZE=K:\ # :setenv=MAIL=/var/mail/$,BLOCKSIZE=K:\
# :path=~/bin /bin /usr/bin /usr/local/bin:\ # :path=~/bin /bin /usr/bin /usr/local/bin:\
# :manpath=/usr/share/man /usr/local/man:\ # :manpath=/usr/share/man /usr/local/man:\

View File

@ -1,4 +1,3 @@
FreeBSD ?.?.? (UNKNOWN)
Welcome to FreeBSD! Welcome to FreeBSD!
@ -18,4 +17,4 @@ Please include that output and any error messages when posting questions.
Introduction to manual pages: man man Introduction to manual pages: man man
FreeBSD directory layout: man hier FreeBSD directory layout: man hier
Edit /etc/motd to change this login announcement. Edit /etc/motd.template to change this login announcement.

View File

@ -35,6 +35,6 @@
#include <paths.h> #include <paths.h>
#define _PATH_HUSHLOGIN ".hushlogin" #define _PATH_HUSHLOGIN ".hushlogin"
#define _PATH_MOTDFILE "/etc/motd" #define _PATH_MOTDFILE "/var/run/motd"
#define _PATH_FBTAB "/etc/fbtab" #define _PATH_FBTAB "/etc/fbtab"
#define _PATH_LOGINDEVPERM "/etc/logindevperm" #define _PATH_LOGINDEVPERM "/etc/logindevperm"