From f1abd591b4be38b1b77bb26ad6dd829a479689b7 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Sat, 16 Mar 2024 13:37:57 -0500 Subject: [PATCH] Initial Commit --- 00-header | 29 +++++++ 09-sysinfo | 34 +++++++++ 10-help-text | 28 +++++++ 10-uname | 2 + 50-motd-news | 157 ++++++++++++++++++++++++++++++++++++++ 85-fwupd | 5 ++ 91-contract-ua-esm-status | 8 ++ 91-release-upgrade | 20 +++++ 92-unattended-upgrades | 5 ++ 93-updates | 125 ++++++++++++++++++++++++++++++ 93-updates.bak | 116 ++++++++++++++++++++++++++++ 99-footer | 24 ++++++ 12 files changed, 553 insertions(+) create mode 100755 00-header create mode 100755 09-sysinfo create mode 100755 10-help-text create mode 100644 10-uname create mode 100755 50-motd-news create mode 100755 85-fwupd create mode 100755 91-contract-ua-esm-status create mode 100755 91-release-upgrade create mode 100755 92-unattended-upgrades create mode 100755 93-updates create mode 100755 93-updates.bak create mode 100755 99-footer diff --git a/00-header b/00-header new file mode 100755 index 0000000..37629e5 --- /dev/null +++ b/00-header @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 00-header - create the header of the MOTD +# Copyright (C) 2009-2010 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# 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. +[ -r /etc/lsb-release ] && . /etc/lsb-release + +if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then + # Fall back to using the very slow lsb_release utility + DISTRIB_DESCRIPTION=$(lsb_release -s -d) +fi +figlet -f fire $(hostname) +printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)" +[ "$(date +%m/%d)" = "03/14" ] && figlet -f fire "Happy PI day!" diff --git a/09-sysinfo b/09-sysinfo new file mode 100755 index 0000000..a176348 --- /dev/null +++ b/09-sysinfo @@ -0,0 +1,34 @@ +#!/bin/bash +# +# 09-sysinfo - generate the system information +# Copyright (c) 2013 Nick Charlton +# +# Authors: Nick Charlton +# +# 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. + +date=`date` +load=`cat /proc/loadavg | awk '{print $1}'` +root_usage=`df -h / | awk '/\// {print $(NF-1)}'` +memory_usage=`free -m | awk '/Mem/ { printf("%3.1f%%", $3/$2*100) }'` +swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'` +users=`users | wc -w` + +echo "System information as of: $date" +echo +printf "System load:\t%s\tMemory usage:\t%s\n" $load $memory_usage +printf "Usage on /:\t%s\tSwap usage:\t%s\n" $root_usage $swap_usage +printf "Local users:\t%s\n" $users +echo diff --git a/10-help-text b/10-help-text new file mode 100755 index 0000000..29b2030 --- /dev/null +++ b/10-help-text @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 10-help-text - print the help text associated with the distro +# Copyright (C) 2009-2010 Canonical Ltd. +# +# Authors: Dustin Kirkland , +# Brian Murray +# +# 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. + +printf "\n" +printf " * Documentation: https://raspberrypi.com/documentation\n" +#printf " * Management: https://landscape.canonical.com\n" +printf " * Support: https://forums.raspberrypi.com\n" +#spinner /etc/update-motd.d/50-motd-news --force --null +printf " \n" diff --git a/10-uname b/10-uname new file mode 100644 index 0000000..92773ce --- /dev/null +++ b/10-uname @@ -0,0 +1,2 @@ +#!/bin/sh +uname -snrvm diff --git a/50-motd-news b/50-motd-news new file mode 100755 index 0000000..319a1fe --- /dev/null +++ b/50-motd-news @@ -0,0 +1,157 @@ +#!/bin/sh +# +# 50-motd-news - print the live news from the Ubuntu wire +# Copyright (C) 2016-2020 Canonical Ltd. +# Copyright (C) 2016-2017 Dustin Kirkland +# +# Authors: Dustin Kirkland +# Steve Langasek +# +# 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 " * News:" + safe_print $CACHE + elif [ "$(id -u)" -eq 0 ]; then + printf " * News:\n * No News\n" + : > $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... + +# 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 +CLOUD=$(mktemp) || exit 1 +trap "rm -f $NEWS $ERR $CLOUD" 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 + +# 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 +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")" +cloud_id="unknown" +if [ -x /usr/bin/cloud-id ]; then + /usr/bin/cloud-id > "$CLOUD" 2>/dev/null + if [ "$?" -eq "0" ]; then + # sanitize it a bit, just in case + cloud_id=$(cut -c -40 "${CLOUD}" | tr -c -d '[:alnum:]') + if [ -z "${cloud_id}" ]; then + cloud_id="unknown" + fi + fi +fi + +# Piece together the user agent +USER_AGENT="wget/$wget_ver $lsb $platform $cpu cloud_id/$cloud_id" + +# 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" + ;; + call*) + cmd=$(echo $u|cut -c 6-) + response=$($cmd) + title=$(echo "$response"|grep -E " \* " --color=never) + url=$(echo "$response"|tail -1) + echo "$title\n\n$url" > "$CACHE" + continue + ;; + *) + continue + ;; + esac + # If we're forced, set the wait to much higher (1 minute) + [ "$FORCED" = "1" ] && WAIT=60 + # Fetch and print the news motd + 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 + echo " * News:" + safe_print "$NEWS" + # Try to update the cache + safe_print "$NEWS" 2>/dev/null >$CACHE || true + else + printf " * News:\n * No News" + echo " * No News" > "$CACHE" + fi +done +rm -f "$NEWS" "$ERR" "$CLOUD" +exit 0 diff --git a/85-fwupd b/85-fwupd new file mode 100755 index 0000000..261f9a3 --- /dev/null +++ b/85-fwupd @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ -f /run/motd.d/85-fwupd ]; then + cat /run/motd.d/85-fwupd +fi diff --git a/91-contract-ua-esm-status b/91-contract-ua-esm-status new file mode 100755 index 0000000..cfc6bb2 --- /dev/null +++ b/91-contract-ua-esm-status @@ -0,0 +1,8 @@ +#!/bin/sh +contract_status_stamp="/var/lib/ubuntu-advantage/messages/motd-contract-status" + +[ ! -r "$contract_status_stamp" ] || cat "$contract_status_stamp" + +auto_attach_stamp="/var/lib/ubuntu-advantage/messages/motd-auto-attach-status" + +[ ! -r "$auto_attach_stamp" ] || cat "$auto_attach_stamp" diff --git a/91-release-upgrade b/91-release-upgrade new file mode 100755 index 0000000..c89645d --- /dev/null +++ b/91-release-upgrade @@ -0,0 +1,20 @@ +#!/bin/sh + +# if the current release is under development there won't be a new one +[ -r /etc/lsb-release ] && . /etc/lsb-release +if [ -z "$DISTRIB_DESCRIPTION" ] && command -v lsb_release > /dev/null; then + DISTRIB_DESCRIPTION=$(lsb_release -s -d) +fi + +if [ "$(echo "$DISTRIB_DESCRIPTION" | cut -d' ' -f4)" = "(development" ]; then + exit 0 +fi + +# if it is non-root user, skip +if [ $(id -u) -ne 0 ]; 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 diff --git a/92-unattended-upgrades b/92-unattended-upgrades new file mode 100755 index 0000000..57799a4 --- /dev/null +++ b/92-unattended-upgrades @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ -x /usr/share/unattended-upgrades/update-motd-unattended-upgrades ]; then + exec /usr/share/unattended-upgrades/update-motd-unattended-upgrades +fi diff --git a/93-updates b/93-updates new file mode 100755 index 0000000..f48691a --- /dev/null +++ b/93-updates @@ -0,0 +1,125 @@ +#!/usr/bin/python3 +# +# 20-updates - create the system updates section of the MOTD +# Copyright (c) 2013 Nick Charlton +# +# Authors: Nick Charlton +# Based upon prior work by Dustin Kirkland and Michael Vogt. +# +# 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. + +import sys +import subprocess +import apt_pkg + +print("") +print(" * Updates:") + +if subprocess.Popen(["is_tty"], stdout=subprocess.PIPE).communicate()[0].strip().decode()!="tty": + print(" Updates are not checked on non-tty sessions") + print(" so as to not slow down login times") + print("") + sys.exit(0) + +DISTRO = subprocess.Popen(["lsb_release", "-c", "-s"], + stdout=subprocess.PIPE).communicate()[0].strip() + +class OpNullProgress(object): + '''apt progress handler which supresses any output.''' + def update(self): + pass + def done(self): + pass + +def is_security_upgrade(pkg): + ''' + Checks to see if a package comes from a DISTRO-security source. + ''' + security_package_sources = [("Ubuntu", "%s-security" % DISTRO), + ("Debian", "%s-security" % DISTRO)] + + for (file, index) in pkg.file_list: + for origin, archive in security_package_sources: + if (file.archive == archive and file.origin == origin): + return True + return False + +# init apt and config +apt_pkg.init() + +# open the apt cache +try: + cache = apt_pkg.Cache(OpNullProgress()) +except SystemError as e: + sys.stderr.write("Error: Opening the cache (%s)" % e) + sys.exit(-1) + +# setup a DepCache instance to interact with the repo +depcache = apt_pkg.DepCache(cache) + +# take into account apt policies +depcache.read_pinfile() + +# initialise it +depcache.init() + +# give up if packages are broken +if depcache.broken_count > 0: + sys.stderr.write("Error: Broken packages exist.") + sys.exit(-1) + +# mark possible packages +try: + # run distro-upgrade + depcache.upgrade(True) + # reset if packages get marked as deleted -> we don't want to break anything + if depcache.del_count > 0: + depcache.init() + + # then a standard upgrade + depcache.upgrade() +except SystemError as e: + sys.stderr.write("Error: Couldn't mark the upgrade (%s)" % e) + sys.exit(-1) + +# run around the packages +upgrades = 0 +security_upgrades = 0 +for pkg in cache.packages: + candidate = depcache.get_candidate_ver(pkg) + current = pkg.current_ver + + # skip packages not marked as upgraded/installed + if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)): + continue + + # increment the upgrade counter + upgrades += 1 + + # keep another count for security upgrades + if is_security_upgrade(candidate): + security_upgrades += 1 + + # double check for security upgrades masked by another package + for version in pkg.version_list: + if (current and apt_pkg.version_compare(version.ver_str, current.ver_str) <= 0): + continue + if is_security_upgrade(version): + security_upgrades += 1 + break + +print(" %d updates to install." % upgrades) +print(" %d are security updates." % security_upgrades) +print("") # leave a trailing blank line diff --git a/93-updates.bak b/93-updates.bak new file mode 100755 index 0000000..fe07b3d --- /dev/null +++ b/93-updates.bak @@ -0,0 +1,116 @@ +#!/usr/bin/python3 +# +# 20-updates - create the system updates section of the MOTD +# Copyright (c) 2013 Nick Charlton +# +# Authors: Nick Charlton +# Based upon prior work by Dustin Kirkland and Michael Vogt. +# +# 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. + +import sys +import subprocess +import apt_pkg + +DISTRO = subprocess.Popen(["lsb_release", "-c", "-s"], + stdout=subprocess.PIPE).communicate()[0].strip() + +class OpNullProgress(object): + '''apt progress handler which supresses any output.''' + def update(self): + pass + def done(self): + pass + +def is_security_upgrade(pkg): + ''' + Checks to see if a package comes from a DISTRO-security source. + ''' + security_package_sources = [("Ubuntu", "%s-security" % DISTRO), + ("Debian", "%s-security" % DISTRO)] + + for (file, index) in pkg.file_list: + for origin, archive in security_package_sources: + if (file.archive == archive and file.origin == origin): + return True + return False + +# init apt and config +apt_pkg.init() + +# open the apt cache +try: + cache = apt_pkg.Cache(OpNullProgress()) +except SystemError, e: + sys.stderr.write("Error: Opening the cache (%s)" % e) + sys.exit(-1) + +# setup a DepCache instance to interact with the repo +depcache = apt_pkg.DepCache(cache) + +# take into account apt policies +depcache.read_pinfile() + +# initialise it +depcache.init() + +# give up if packages are broken +if depcache.broken_count > 0: + sys.stderr.write("Error: Broken packages exist.") + sys.exit(-1) + +# mark possible packages +try: + # run distro-upgrade + depcache.upgrade(True) + # reset if packages get marked as deleted -> we don't want to break anything + if depcache.del_count > 0: + depcache.init() + + # then a standard upgrade + depcache.upgrade() +except SystemError, e: + sys.stderr.write("Error: Couldn't mark the upgrade (%s)" % e) + sys.exit(-1) + +# run around the packages +upgrades = 0 +security_upgrades = 0 +for pkg in cache.packages: + candidate = depcache.get_candidate_ver(pkg) + current = pkg.current_ver + + # skip packages not marked as upgraded/installed + if not (depcache.marked_install(pkg) or depcache.marked_upgrade(pkg)): + continue + + # increment the upgrade counter + upgrades += 1 + + # keep another count for security upgrades + if is_security_upgrade(candidate): + security_upgrades += 1 + + # double check for security upgrades masked by another package + for version in pkg.version_list: + if (current and apt_pkg.version_compare(version.ver_str, current.ver_str) <= 0): + continue + if is_security_upgrade(version): + security_upgrades += 1 + break + +print "%d updates to install." % upgrades +print "%d are security updates." % security_upgrades +print "" # leave a trailing blank line diff --git a/99-footer b/99-footer new file mode 100755 index 0000000..a74b9e3 --- /dev/null +++ b/99-footer @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 99-footer - write the admin's footer to the MOTD +# Copyright (c) 2013 Nick Charlton +# Copyright (c) 2009-2010 Canonical Ltd. +# +# Authors: Nick Charlton +# Dustin Kirkland +# +# 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. + +[ -f /etc/motd.tail ] && cat /etc/motd.tail || true