From b5ce47c155157269bc558ef1654aad5a84e79224 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Mon, 25 Mar 2024 09:14:16 -0500 Subject: Use project name in scripts Make the relationship between the scripts clear by using the project name in the update and download scripts. --- README.md | 33 ++++---- src/autoupdate | 215 ------------------------------------------------ src/rc.slack-autoupdate | 40 +++++++++ src/rc.update | 40 --------- src/slack-autoupdate | 215 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 272 insertions(+), 271 deletions(-) delete mode 100644 src/autoupdate create mode 100644 src/rc.slack-autoupdate delete mode 100644 src/rc.update create mode 100644 src/slack-autoupdate diff --git a/README.md b/README.md index 0f6fd55..d5eca2a 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,11 @@ These scripts only currently support stable Slackware64 releases (sorry -current ## Installation and Configuration -There are three components. the [cron script](./src/autoupdate) which downloads -packages, the [rc.update script](./src/rc.update) which installs the packages, and -the [install-kernel script](./src/install-kernel) which updates your computer after a -kernel update. +There are three components. the [cron script](./src/slack-autoupdate) which +downloads packages, the [rc.slack-autoupdate script](./src/rc.slack-autoupdate) +which installs the packages, and the [install-kernel +script](./src/install-kernel) which updates your computer after a kernel +update. ### Cron script @@ -26,52 +27,52 @@ Your system downloads the packages using this script. Adjust the script using your favorite editor: ``` -vim src/autoupdate +vim src/slack-autoupdate ``` Then as root: ``` -cp src/autoupdate /etc/cron.daily -chown root:root /etc/cron.daily/autoupdate -chmod +x /etc/cron.daily/autoupdate +cp src/slack-autoupdate /etc/cron.hourly +chown root:root /etc/cron.hourly/slack-autoupdate +chmod +x /etc/cron.hourly/slack-autoupdate ``` -### rc.update +### rc.slack-autoupdate Your system updates your installed packages using this script. Adjust the script using your favorite editor: ``` -vim src/rc.update +vim src/rc.slack-autoupdate ``` Then as root: ``` -cp src/rc.update /etc/rc.d/ -chown root:root /etc/rc.d/rc.update +cp src/rc.slack-autoupdate /etc/rc.d/ +chown root:root /etc/rc.d/rc.slack-autoupdate ``` Then add this to /etc/rc.d/rc.local: ``` -if [ -x /etc/rc.d/rc.update ]; then - /etc/rc.d/rc.update +if [ -x /etc/rc.d/rc.slack-autoupdate ]; then + /etc/rc.d/rc.slack-autoupdate fi ``` To enable installation on reboot: ``` -chmod +x /etc/rc.d/rc.update +chmod +x /etc/rc.d/rc.slack-autoupdate ``` or to disable it again: ``` -chmod -x /etc/rc.d/rc.update +chmod -x /etc/rc.d/rc.slack-autoupdate ``` ### install-kernel diff --git a/src/autoupdate b/src/autoupdate deleted file mode 100644 index 30315df..0000000 --- a/src/autoupdate +++ /dev/null @@ -1,215 +0,0 @@ -#!/bin/bash -# -# Update your system automatically! -# -# Packages from different sources are downloaded, under sub-shells, into the -# PACKAGE_DIR where they can be installed on reboot. -# -# A failure encountered at any point should abort any pending package updates -# to install. -# -# To enable sbotools updates, make the /etc/sbotools/sbotools.conf file exist -# and configure PKG_DIR to point to the same path as STAGING_DIR. - -# Set to "yes" to send notification to stdout, causing cron to send an email. -NOTIFY="${NOTIFY:-no}" - -# Reboot after this period for install after a successful update. -# -# Set to empty to disable reboot or 'now' to reboot immediately. -export REBOOT_TIME="${REBOOT_TIME:-""}" - -# Packages are copied here on successful download. -export PACKAGE_DIR="${PACKAGE_DIR:-/var/spool/slack-autoupdate}" - -# Packages are temperarily stored here until success. -export STAGING_DIR="${STAGING_DIR:-/var/cache/slack-autoupdate/staging}" - -# Information of interest to the admin on success. -export UPDATE_INFO="${UPDATE_INFO:-$STAGING_DIR/info.txt}" - -# Information of interest to the admin on failure. -export UPDATE_ERROR="${UPDATE_ERROR:-$STAGING_DIR/error.txt}" - -# Avoid concurrently running with another instance. -if [ "$(ls /var/lock/autoupdate.* 2>/dev/null)" ]; then - echo "Another instance of autoupdate is running. If this is not correct, you can remove /var/lock/autoupdate.* files and run autoupdate again." \ - >>"$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" - if [ "$NOTIFY" = "yes" ]; then - cat "$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" - fi - - exit 1 -fi - -touch /var/lock/autoupdate.$$ -trap "rm -f /var/lock/autoupdate.$$" EXIT - -# Keep it simple stupid, install pending updates first. -mkdir --parents "$PACKAGE_DIR" -if [ -n "$(find "$PACKAGE_DIR" -name "*.t*z")" ]; then - exit 0 -fi - -# Make the set of package updates available atomically by storing them in a -# temporary location until completion. -rm -fr "$STAGING_DIR" -mkdir --parents "$STAGING_DIR" - -if ! OUTPUT="$( - # Capture this subshell's error output to standard output. - exec 2>&1 - - echo "Checking updates for slackpkg..." - - slackpkg -batch=on -default_answer=n update || exit "$?" - - CHANGELOG_TXT="$(mktemp /tmp/slack-autoupdate.XXXXXX)" - PACKAGE_UPDATES="$(mktemp /tmp/slack-autoupdate.XXXXXX)" - trap "rm -f ${CHANGELOG_TXT} ${PACKAGE_UPDATES}" EXIT - - slackpkg -batch=on -default_answer=n upgrade-all \ - | grep "\.t.z$" \ - | tee "$PACKAGE_UPDATES" \ - || exit "$?" - - if [ ! -s "$PACKAGE_UPDATES" ]; then - # No updates - exit 0 - fi - - # - # We need slackpkg to support downloading an exact package file to a provided - # location. The following is a workaround. - # - - SOURCE=$(sed -n ' - # Remove leading and trailing blanks - s/^[[:blank:]]*// - s/[[:blank:]]*$// - # Only one token is allowed per line - /[[:blank:]]/d - # A single solidus should end the URI - s,[/]*$,/, - # Print the lines beginning with one of the URI schemes we look for - \@^file://@p - \@^cdrom://@p - \@^local://@p - \@^https\{0,1\}://@p - \@^ftps\{0,1\}://@p' /etc/slackpkg/mirrors) - - while read PKG; do - PKG_URL="$( - grep "${PKG}$" /var/lib/slackpkg/CHECKSUMS.md5 \ - | tr -s ' ' \ - | cut -f 2 -d ' ' - )" || exit "$?" - - wget \ - --quiet \ - --directory-prefix="$STAGING_DIR" \ - "${SOURCE}${PKG_URL}" \ - "${SOURCE}${PKG_URL}.asc" \ - || exit "$?" - done <"$PACKAGE_UPDATES" - - gpg2 --verify-files "$STAGING_DIR"/*.asc || exit "$?" - - ( - # Provide update information to the user. - - # Redirect this subshell's standard output to info file. - exec 1>>"$UPDATE_INFO" - - LAST_INSTALLED_PACKAGE="$( - grep \ - "$(ls /var/log/packages | sed "s/$/\\\|/g" | tr --delete '\n')XXXXX" \ - /var/lib/slackpkg/ChangeLog.txt \ - | head -n 1 - )" - - echo "Slackware updates" - echo - grep --before-context 10000 "$LAST_INSTALLED_PACKAGE" /var/lib/slackpkg/ChangeLog.txt - echo - ) -)"; then - >>"$UPDATE_ERROR" echo -e "slackpkg:\n\n$OUTPUT" -fi - -if ! OUTPUT="$( - exec 2>&1 - - echo "Checking updates for sbotools..." - - if [ ! -f /etc/sbotools/sbotools.conf ] \ - || [ "$(sed -n 's/PKG_DIR=//p' /etc/sbotools/sbotools.conf)" != "$STAGING_DIR" ]; then - # Assume sbotools is disabled. - exit 0 - fi - - source /etc/profile.d/*.sh - - PACKAGE_UPDATES=$(mktemp /tmp/slack-autoupdate.XXXXXX) - trap "rm -f ${PACKAGE_UPDATES}" EXIT - - (sbocheck | tee $PACKAGE_UPDATES) || exit 1 - if grep -i "no updates available" "$PACKAGE_UPDATES"; then - exit 0 - fi - - sboupgrade \ - --all \ - --noinstall \ - --nointeractive \ - || exit "$?" - - ( - exec 1>>"$UPDATE_INFO" - - echo "Slackbuild updates" - echo - cat "$PACKAGE_UPDATES" - echo - ) -)"; then - if [ -f "$UPDATE_ERROR" ]; then - >>"$UPDATE_ERROR" echo "" - >>"$UPDATE_ERROR" echo "" - fi - - >>"$UPDATE_ERROR" echo -e "sbotools:\n\n$OUTPUT" -fi - -# Make updates atomic. -if [ -f "$UPDATE_ERROR" ]; then - mv "$UPDATE_ERROR" "$PACKAGE_DIR" - mv "$UPDATE_INFO" "$PACKAGE_DIR" - - exit 1 -fi - - -mv "$STAGING_DIR"/* "$PACKAGE_DIR/" -rm -fr "$STAGING_DIR" - -if [ -z "$(find "$PACKAGE_DIR" -name "*.t*z" -or -name "info.txt" -or -name "error.txt")" ]; then - # No updates - exit 0 -fi - -if [ "$NOTIFY" = "yes" ]; then - if [ -f "$UPDATE_ERROR" ]; then - echo "Failures were encountered while trying to download updates" - echo "" - cat "$UPDATE_ERROR" - elif [ -f "$UPDATE_INFO" ]; then - echo "Updates pending installation" - echo "" - cat "$UPDATE_INFO" - fi -fi - -if [ -n "$REBOOT_TIME" ]; then - nohup shutdown -r "$REBOOT_TIME" >/dev/null 2>&1 & -fi diff --git a/src/rc.slack-autoupdate b/src/rc.slack-autoupdate new file mode 100644 index 0000000..afc45d9 --- /dev/null +++ b/src/rc.slack-autoupdate @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Automatically update your system on reboot using packages in the UPDATE_DIR. +# +# Sometimes there are additional steps to make when your kernel is updated. +# You can define these in a custom 'install-kernel' command which this script +# will run if found. We recommend placing this under /usr/local/sbin. +# + +# Where packages are stored pending installation. You can use sub-directories +# to order and group packages. +UPDATE_DIR="/var/spool/slack-autoupdate" + +UPDATES="$(find "$UPDATE_DIR" -name '*.t*z' | sort)" + +if [ -z "$UPDATES" ]; then + exit 0 +fi + +if read -r -t 5 -p "Installing updates, press enter to skip this process..."; then + exit 0 +fi + +OLD_KERNEL="$(realpath /boot/vmlinuz)" + +for PKG in $UPDATES; do + upgradepkg --install-new "$PKG" +done + +NEW_KERNEL="$(realpath /boot/vmlinuz)" +if [ "$OLD_KERNEL" != "$NEW_KERNEL" ]; then + if command -v install-kernel &> /dev/null; then + install-kernel "$NEW_KERNEL" + fi +fi + +# All package updates have been processed. +find "$UPDATE_DIR" -mindepth 1 | xargs rm -fr + +reboot diff --git a/src/rc.update b/src/rc.update deleted file mode 100644 index afc45d9..0000000 --- a/src/rc.update +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# -# Automatically update your system on reboot using packages in the UPDATE_DIR. -# -# Sometimes there are additional steps to make when your kernel is updated. -# You can define these in a custom 'install-kernel' command which this script -# will run if found. We recommend placing this under /usr/local/sbin. -# - -# Where packages are stored pending installation. You can use sub-directories -# to order and group packages. -UPDATE_DIR="/var/spool/slack-autoupdate" - -UPDATES="$(find "$UPDATE_DIR" -name '*.t*z' | sort)" - -if [ -z "$UPDATES" ]; then - exit 0 -fi - -if read -r -t 5 -p "Installing updates, press enter to skip this process..."; then - exit 0 -fi - -OLD_KERNEL="$(realpath /boot/vmlinuz)" - -for PKG in $UPDATES; do - upgradepkg --install-new "$PKG" -done - -NEW_KERNEL="$(realpath /boot/vmlinuz)" -if [ "$OLD_KERNEL" != "$NEW_KERNEL" ]; then - if command -v install-kernel &> /dev/null; then - install-kernel "$NEW_KERNEL" - fi -fi - -# All package updates have been processed. -find "$UPDATE_DIR" -mindepth 1 | xargs rm -fr - -reboot diff --git a/src/slack-autoupdate b/src/slack-autoupdate new file mode 100644 index 0000000..30315df --- /dev/null +++ b/src/slack-autoupdate @@ -0,0 +1,215 @@ +#!/bin/bash +# +# Update your system automatically! +# +# Packages from different sources are downloaded, under sub-shells, into the +# PACKAGE_DIR where they can be installed on reboot. +# +# A failure encountered at any point should abort any pending package updates +# to install. +# +# To enable sbotools updates, make the /etc/sbotools/sbotools.conf file exist +# and configure PKG_DIR to point to the same path as STAGING_DIR. + +# Set to "yes" to send notification to stdout, causing cron to send an email. +NOTIFY="${NOTIFY:-no}" + +# Reboot after this period for install after a successful update. +# +# Set to empty to disable reboot or 'now' to reboot immediately. +export REBOOT_TIME="${REBOOT_TIME:-""}" + +# Packages are copied here on successful download. +export PACKAGE_DIR="${PACKAGE_DIR:-/var/spool/slack-autoupdate}" + +# Packages are temperarily stored here until success. +export STAGING_DIR="${STAGING_DIR:-/var/cache/slack-autoupdate/staging}" + +# Information of interest to the admin on success. +export UPDATE_INFO="${UPDATE_INFO:-$STAGING_DIR/info.txt}" + +# Information of interest to the admin on failure. +export UPDATE_ERROR="${UPDATE_ERROR:-$STAGING_DIR/error.txt}" + +# Avoid concurrently running with another instance. +if [ "$(ls /var/lock/autoupdate.* 2>/dev/null)" ]; then + echo "Another instance of autoupdate is running. If this is not correct, you can remove /var/lock/autoupdate.* files and run autoupdate again." \ + >>"$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" + if [ "$NOTIFY" = "yes" ]; then + cat "$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" + fi + + exit 1 +fi + +touch /var/lock/autoupdate.$$ +trap "rm -f /var/lock/autoupdate.$$" EXIT + +# Keep it simple stupid, install pending updates first. +mkdir --parents "$PACKAGE_DIR" +if [ -n "$(find "$PACKAGE_DIR" -name "*.t*z")" ]; then + exit 0 +fi + +# Make the set of package updates available atomically by storing them in a +# temporary location until completion. +rm -fr "$STAGING_DIR" +mkdir --parents "$STAGING_DIR" + +if ! OUTPUT="$( + # Capture this subshell's error output to standard output. + exec 2>&1 + + echo "Checking updates for slackpkg..." + + slackpkg -batch=on -default_answer=n update || exit "$?" + + CHANGELOG_TXT="$(mktemp /tmp/slack-autoupdate.XXXXXX)" + PACKAGE_UPDATES="$(mktemp /tmp/slack-autoupdate.XXXXXX)" + trap "rm -f ${CHANGELOG_TXT} ${PACKAGE_UPDATES}" EXIT + + slackpkg -batch=on -default_answer=n upgrade-all \ + | grep "\.t.z$" \ + | tee "$PACKAGE_UPDATES" \ + || exit "$?" + + if [ ! -s "$PACKAGE_UPDATES" ]; then + # No updates + exit 0 + fi + + # + # We need slackpkg to support downloading an exact package file to a provided + # location. The following is a workaround. + # + + SOURCE=$(sed -n ' + # Remove leading and trailing blanks + s/^[[:blank:]]*// + s/[[:blank:]]*$// + # Only one token is allowed per line + /[[:blank:]]/d + # A single solidus should end the URI + s,[/]*$,/, + # Print the lines beginning with one of the URI schemes we look for + \@^file://@p + \@^cdrom://@p + \@^local://@p + \@^https\{0,1\}://@p + \@^ftps\{0,1\}://@p' /etc/slackpkg/mirrors) + + while read PKG; do + PKG_URL="$( + grep "${PKG}$" /var/lib/slackpkg/CHECKSUMS.md5 \ + | tr -s ' ' \ + | cut -f 2 -d ' ' + )" || exit "$?" + + wget \ + --quiet \ + --directory-prefix="$STAGING_DIR" \ + "${SOURCE}${PKG_URL}" \ + "${SOURCE}${PKG_URL}.asc" \ + || exit "$?" + done <"$PACKAGE_UPDATES" + + gpg2 --verify-files "$STAGING_DIR"/*.asc || exit "$?" + + ( + # Provide update information to the user. + + # Redirect this subshell's standard output to info file. + exec 1>>"$UPDATE_INFO" + + LAST_INSTALLED_PACKAGE="$( + grep \ + "$(ls /var/log/packages | sed "s/$/\\\|/g" | tr --delete '\n')XXXXX" \ + /var/lib/slackpkg/ChangeLog.txt \ + | head -n 1 + )" + + echo "Slackware updates" + echo + grep --before-context 10000 "$LAST_INSTALLED_PACKAGE" /var/lib/slackpkg/ChangeLog.txt + echo + ) +)"; then + >>"$UPDATE_ERROR" echo -e "slackpkg:\n\n$OUTPUT" +fi + +if ! OUTPUT="$( + exec 2>&1 + + echo "Checking updates for sbotools..." + + if [ ! -f /etc/sbotools/sbotools.conf ] \ + || [ "$(sed -n 's/PKG_DIR=//p' /etc/sbotools/sbotools.conf)" != "$STAGING_DIR" ]; then + # Assume sbotools is disabled. + exit 0 + fi + + source /etc/profile.d/*.sh + + PACKAGE_UPDATES=$(mktemp /tmp/slack-autoupdate.XXXXXX) + trap "rm -f ${PACKAGE_UPDATES}" EXIT + + (sbocheck | tee $PACKAGE_UPDATES) || exit 1 + if grep -i "no updates available" "$PACKAGE_UPDATES"; then + exit 0 + fi + + sboupgrade \ + --all \ + --noinstall \ + --nointeractive \ + || exit "$?" + + ( + exec 1>>"$UPDATE_INFO" + + echo "Slackbuild updates" + echo + cat "$PACKAGE_UPDATES" + echo + ) +)"; then + if [ -f "$UPDATE_ERROR" ]; then + >>"$UPDATE_ERROR" echo "" + >>"$UPDATE_ERROR" echo "" + fi + + >>"$UPDATE_ERROR" echo -e "sbotools:\n\n$OUTPUT" +fi + +# Make updates atomic. +if [ -f "$UPDATE_ERROR" ]; then + mv "$UPDATE_ERROR" "$PACKAGE_DIR" + mv "$UPDATE_INFO" "$PACKAGE_DIR" + + exit 1 +fi + + +mv "$STAGING_DIR"/* "$PACKAGE_DIR/" +rm -fr "$STAGING_DIR" + +if [ -z "$(find "$PACKAGE_DIR" -name "*.t*z" -or -name "info.txt" -or -name "error.txt")" ]; then + # No updates + exit 0 +fi + +if [ "$NOTIFY" = "yes" ]; then + if [ -f "$UPDATE_ERROR" ]; then + echo "Failures were encountered while trying to download updates" + echo "" + cat "$UPDATE_ERROR" + elif [ -f "$UPDATE_INFO" ]; then + echo "Updates pending installation" + echo "" + cat "$UPDATE_INFO" + fi +fi + +if [ -n "$REBOOT_TIME" ]; then + nohup shutdown -r "$REBOOT_TIME" >/dev/null 2>&1 & +fi -- cgit v1.2.3