]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rc/rc.d/motd
dts: Update our copy to be in sync with Linux 5.7
[FreeBSD/FreeBSD.git] / libexec / rc / rc.d / motd
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: motd
7 # REQUIRE: mountcritremote FILESYSTEMS
8 # BEFORE:  LOGIN
9
10 . /etc/rc.subr
11
12 name="motd"
13 desc="Update /var/run/motd"
14 rcvar="update_motd"
15 start_cmd="motd_start"
16 stop_cmd=":"
17
18 COMPAT_MOTD="/etc/motd"
19 TARGET="/var/run/motd"
20 TEMPLATE="/etc/motd.template"
21 PERMS="644"
22
23 motd_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         check_startmsgs && echo -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                 # Provide compatibility symlink:
42                 if [ ! -h "${COMPAT_MOTD}" ]; then
43                         ln -sF "${TARGET}" "${COMPAT_MOTD}"
44                 fi
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,' > ${T}
49         cat "${TEMPLATE}" >> ${T}
50
51         install -C -o root -g wheel -m "${PERMS}" "$T" "${TARGET}"
52         rm -f "$T"
53
54         check_startmsgs && echo '.'
55 }
56
57 load_rc_config $name
58 run_rc_command "$1"