-
Notifications
You must be signed in to change notification settings - Fork 3
/
sbin_update-motd
executable file
·72 lines (67 loc) · 2.31 KB
/
sbin_update-motd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
################################################################################
# Copyright 2011-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
# use this file except in compliance with the License. A copy of the License is
# located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions
# and limitations under the License.
################################################################################
if [ $(/usr/bin/id -u) -ne 0 ]; then
echo "You are not root"
exit 1
fi
# Parse the few supported options
case "$1" in
--enable)
rm -f /var/lib/update-motd/disabled
exit 0;;
--disable)
mkdir -p /var/lib/update-motd/
touch /var/lib/update-motd/disabled
exit 0;;
'' | --force);;
*)
echo "update-motd [option]"
echo " --disable: Disable update-motd"
echo " --enable: Enable update-motd"
echo " --force: Ignore disabled setting"
exit 1;;
esac
# Just exit if update-motd is disabled and --force wasn't passed
if [ -e /var/lib/update-motd/disabled ] && [ "$1" != "--force" ]
then
exit 0
fi
if [ -d /etc/update-motd.d ]; then
TMPFILE=$(mktemp --tmpdir=/var/lib/update-motd/)
if [ -f /etc/motd.head ]; then
cat /etc/motd.head >> $TMPFILE
fi
# Simulated run-parts, wildcards in bash are expanded sorted
# Skip files ending in ~ or ,
for part in /etc/update-motd.d/*[^~,]; do
# Skip .rpmnew, etc.
[[ $part =~ \.rpm* ]] && continue
# Run only if it's a regular file and executable
if [ -f $part ] && [ -x $part ]; then
TMPPART=$(mktemp --tmpdir motd.partXXXXX)
if (timeout 30s $part > $TMPPART); then
cat $TMPPART >> $TMPFILE
fi
rm -f $TMPPART
fi
done
if [ -f /etc/motd.tail ]; then
cat /etc/motd.tail >> $TMPFILE
fi
# mktemp creates files with only user read-write permissions
chmod go+r $TMPFILE
mv $TMPFILE /var/lib/update-motd/motd
fi