+++ /dev/null
-# Enable/disable the dynamic MOTD news service
-# This is a useful way to provide dynamic, informative
-# information pertinent to the users and administrators
-# of the local system
-ENABLED=1
-
-# Configure the source of dynamic MOTD news
-# White space separated list of 0 to many news services
-# For security reasons, these must be https
-# and have a valid certificate
-# Canonical runs a service at motd.ubuntu.com, and you
-# can easily run one too
-URLS="https://motd.ubuntu.com"
-
-# Specify the time in seconds, you're willing to wait for
-# dynamic MOTD news
-# Note that news messages are fetched in the background by
-# a systemd timer, so this should never block boot or login
-WAIT=5
#!/bin/sh
#
# 50-motd-news - print the live news from the Ubuntu wire
-# Copyright (C) 2016-2017 Canonical Ltd.
+# Copyright (C) 2016-2020 Canonical Ltd.
# Copyright (C) 2016-2017 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
+# Steve Langasek <steve.langasek@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
# If we've made it here, we've been given the --force argument,
# probably from the systemd motd-news.service. Let's update...
+# Abort early if wget is missing
+[ -x /usr/bin/wget ] || exit 0
+
# Generate our temp files, clean up when done
NEWS=$(mktemp) || exit 1
ERR=$(mktemp) || exit 1
# 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); }')"
+# wget browser version, for debug purposes
+wget_ver="$(dpkg -l wget | awk '$1 == "ii" { print($3); exit(0); }')"
# Distribution version, for messages releated to this Ubuntu release
. /etc/lsb-release
fi
fi
-# 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 cloud_id/$cloud_id"
+USER_AGENT="wget/$wget_ver $lsb $platform $cpu cloud_id/$cloud_id"
# Loop over any configured URLs
for u in $URLS; do
# 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
+ result=0
+ not_found_is_ok=0
+ wget --timeout "$WAIT" -U "$USER_AGENT" -O- --content-on-error "$u" >"$NEWS" 2>"$ERR" || result=$?
+ # from wget's manpage: 8 Server issued an error response.
+ if [ $result -eq 8 ]; then
+ if grep -q "ERROR 404" "$ERR"; then
+ # The server's 404 document is the generic, non cloud-specific, motd-news
+ # content present in the index.txt file
+ not_found_is_ok=1
+ fi
+ fi
+ if [ $result -eq 0 ] || [ $not_found_is_ok -eq 1 ]; then
echo
# At most, 10 lines of text, remove control characters, print at most 80 characters per line
safe_print "$NEWS"