forked from HawksRepos/PTS-Team
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aa
- Loading branch information
MrDoobPG
authored and
MrDoobPG
committed
Sep 14, 2019
1 parent
9449579
commit b828ead
Showing
10 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/bin/sh | ||
# | ||
# 50-motd-news - print the live news from the Ubuntu wire | ||
# Copyright (C) 2016-2017 Canonical Ltd. | ||
# Copyright (C) 2016-2017 Dustin Kirkland | ||
# | ||
# Authors: Dustin Kirkland <kirkland@canonical.com> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
############################################################################## | ||
# This program could be rewritten in C or Golang for faster performance. | ||
# Or it could be rewritten in Python or another higher level language | ||
# for more modularity. | ||
# However, I've insisted on shell here for transparency! | ||
# - Dustin | ||
############################################################################## | ||
|
||
# Source the local configuration | ||
[ -r /etc/default/motd-news ] && . /etc/default/motd-news | ||
|
||
# Exit immediately, unless we're enabled | ||
# This makes this script very easy to disable in /etc/default/motd-news configuration | ||
[ "$ENABLED" = "1" ] || exit 0 | ||
|
||
# Ensure sane defaults | ||
[ -n "$URLS" ] || URLS="https://motd.ubuntu.com" | ||
[ -n "$WAIT" ] || WAIT=5 | ||
[ -n "$CACHE" ] || CACHE="/var/cache/motd-news" | ||
[ "$1" = "--force" ] && FORCED=1 | ||
|
||
# Ensure we print safely, maximum of the first 10 lines, | ||
# maximum of the first 80 chars per line, no control chars | ||
safe_print() { | ||
cat "$1" | head -n 10 | tr -d '\000-\011\013\014\016-\037' | cut -c -80 | ||
} | ||
|
||
|
||
# If we're not forcing an update, and we have a cached motd-news file, | ||
# then just print it and exit as quickly as possible, for login performance. | ||
# Note that systemd should keep this cache file up to date, asynchronously | ||
if [ "$FORCED" != "1" ]; then | ||
if [ -r $CACHE ]; then | ||
echo | ||
safe_print $CACHE | ||
else | ||
: > $CACHE | ||
fi | ||
exit 0 | ||
fi | ||
|
||
# If we've made it here, we've been given the --force argument, | ||
# probably from the systemd motd-news.service. Let's update... | ||
|
||
# Generate our temp files, clean up when done | ||
NEWS=$(mktemp) || exit 1 | ||
ERR=$(mktemp) || exit 1 | ||
trap "rm -f $NEWS $ERR" HUP INT QUIT ILL TRAP KILL BUS TERM | ||
|
||
# Construct a user agent, similar to Firefox/Chrome/Safari/IE to | ||
# ensure a proper, tailored, accurate message of the day | ||
|
||
# Curl browser version, for debug purposes | ||
curl_ver="$(dpkg -l curl | awk '$1 == "ii" { print($3); exit(0); }')" | ||
|
||
# Distribution version, for messages releated to this Ubuntu release | ||
. /etc/lsb-release | ||
lsb=$(echo "$DISTRIB_DESCRIPTION" | sed -e "s/ /\//g") | ||
codename="$DISTRIB_CODENAME" | ||
|
||
# Kernel version and CPU type, for messages related to a particular revision or hardware | ||
platform="$(uname -o)/$(uname -r)/$(uname -m)" | ||
arch="$(uname -m)" | ||
cpu="$(grep -m1 "^model name" /proc/cpuinfo | sed -e "s/.*: //" -e "s:\s\+:/:g")" | ||
|
||
# Some messages may only be pertinent before or after some amount of uptime | ||
read up idle < /proc/uptime | ||
uptime="uptime/$up/$idle" | ||
|
||
# Piece together the user agent | ||
USER_AGENT="curl/$curl_ver $lsb $platform $cpu $uptime" | ||
|
||
# Loop over any configured URLs | ||
for u in $URLS; do | ||
# Ensure https:// protocol, for security reasons | ||
case $u in | ||
https://*) | ||
true | ||
;; | ||
https://motd.ubuntu.com) | ||
u="$u/$codename/$arch" | ||
;; | ||
*) | ||
continue | ||
;; | ||
esac | ||
# If we're forced, set the wait to much higher (1 minute) | ||
[ "$FORCED" = "1" ] && WAIT=60 | ||
# Fetch and print the news motd | ||
if curl --connect-timeout "$WAIT" --max-time "$WAIT" -A "$USER_AGENT" -o- "$u" >"$NEWS" 2>"$ERR"; then | ||
echo | ||
# At most, 10 lines of text, remove control characters, print at most 80 characters per line | ||
safe_print "$NEWS" | ||
# Try to update the cache | ||
safe_print "$NEWS" 2>/dev/null >$CACHE || true | ||
else | ||
: > "$CACHE" | ||
fi | ||
done | ||
rm -f "$NEWS" "$ERR" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
|
||
SERIES=$(lsb_release -cs) | ||
DESCRIPTION=$(lsb_release -ds) | ||
|
||
[ "$SERIES" = "precise" ] || exit 0 | ||
|
||
[ -x /usr/bin/ubuntu-advantage ] || exit 0 | ||
|
||
if ubuntu-advantage is-esm-enabled; then | ||
cat <<EOF | ||
This ${DESCRIPTION} system is configured to receive extended security updates | ||
from Canonical: | ||
* https://www.ubuntu.com/esm | ||
EOF | ||
else | ||
cat <<EOF | ||
This ${DESCRIPTION} system is past its End of Life, and is no longer | ||
receiving security updates. To protect the integrity of this system, it’s | ||
critical that you enable Extended Security Maintenance updates: | ||
* https://www.ubuntu.com/esm | ||
EOF | ||
fi | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/sh | ||
|
||
UA=${UA:-"/usr/bin/ubuntu-advantage"} | ||
UA_STATUS_CACHE=${UA_STATUS_CACHE:-"/var/cache/ubuntu-advantage-tools/ubuntu-advantage-status.cache"} | ||
|
||
[ -x "$UA" ] || exit 0 | ||
|
||
print_patch_state() { | ||
local patch_state="$1" | ||
|
||
case "$patch_state" in | ||
unapplied) | ||
echo "Patches are available, will be deployed shortly." | ||
;; | ||
applied) | ||
echo "All available patches applied." | ||
;; | ||
applied-with-bug|apply-failed) | ||
echo "Live patching failed, please run \`ubuntu-bug linux\` to report a bug." | ||
;; | ||
nothing-to-apply) | ||
echo "All available patches applied." | ||
;; | ||
applying) | ||
echo "Live patching currently in progress." | ||
;; | ||
*) | ||
echo "Unknown patch status. Please see /var/log/syslog for more information." | ||
echo " Status: \"$patch_state\"" | ||
;; | ||
esac | ||
} | ||
|
||
print_status() { | ||
local check_state="$1" | ||
local patch_state="$2" | ||
|
||
echo -n " - " | ||
case "$check_state" in | ||
needs-check) | ||
echo "Regular server check is pending." | ||
;; | ||
check-failed) | ||
echo "Livepatch server check failed." | ||
echo " Please see /var/log/syslog for more information." | ||
;; | ||
checked) | ||
print_patch_state "$patch_state" | ||
;; | ||
*) | ||
echo "Unknown check status. Please see /var/log/syslog for more information." | ||
echo " Status: \"$check_state\"" | ||
;; | ||
esac | ||
} | ||
|
||
|
||
service_name="livepatch" | ||
# if there is no cache file yet (the cron job hasn't run yet), bail | ||
[ -s "$UA_STATUS_CACHE" ] || exit 0 | ||
ua_status=$(cat "$UA_STATUS_CACHE") | ||
# if there is no livepatch section at all in the output, silently | ||
# bail | ||
has_livepatch=$(echo "${ua_status}" | grep "^${service_name}") | ||
[ -n "${has_livepatch}" ] || exit 0 | ||
livepatch_status=$(echo "$ua_status"|grep ^${service_name}:|sed -r -n "s,^${service_name}: (.*)$,\\1,p") | ||
# only look for patchState and checkState inside the specific service | ||
# block in the status output | ||
patch_state=$(echo "$ua_status"|sed -r -n "/^${service_name}:/,/^\\S/s,^[[:blank:]]+patchState: (.*)$,\\1,p") | ||
check_state=$(echo "$ua_status"|sed -r -n "/^${service_name}:/,/^\\S/s,^[[:blank:]]+checkState: (.*)$,\\1,p") | ||
|
||
case "$livepatch_status" in | ||
"disabled (not available)") | ||
# do nothing | ||
;; | ||
"enabled") | ||
echo | ||
echo " * Canonical Livepatch is enabled." | ||
print_status "${check_state}" "${patch_state}" | ||
;; | ||
"disabled") | ||
echo | ||
echo " * Canonical Livepatch is available for installation." | ||
echo " - Reduce system reboots and improve kernel security. Activate at:" | ||
echo " https://ubuntu.com/livepatch" | ||
;; | ||
*) | ||
echo | ||
echo " * Canonical Livepatch is in an unknown state." | ||
echo " - Please see /var/log/syslog for more information." | ||
echo " Status: \"$livepatch_status\"" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
stamp="/var/lib/update-notifier/updates-available" | ||
|
||
[ ! -r "$stamp" ] || cat "$stamp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
# if the current release is under development there won't be a new one | ||
if [ "$(lsb_release -sd | cut -d' ' -f4)" = "(development" ]; then | ||
exit 0 | ||
fi | ||
if [ -x /usr/lib/ubuntu-release-upgrader/release-upgrade-motd ]; then | ||
exec /usr/lib/ubuntu-release-upgrader/release-upgrade-motd | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
if [ -x /usr/lib/update-notifier/update-motd-hwe-eol ]; then | ||
exec /usr/lib/update-notifier/update-motd-hwe-eol | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
(egrep "overlayroot|/media/root-ro|/media/root-rw" /proc/mounts 2>/dev/null | sort -r) || true | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
if [ -x /usr/lib/update-notifier/update-motd-fsck-at-reboot ]; then | ||
exec /usr/lib/update-notifier/update-motd-fsck-at-reboot | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
if [ -x /usr/lib/update-notifier/update-motd-reboot-required ]; then | ||
exec /usr/lib/update-notifier/update-motd-reboot-required | ||
fi |