From 0148030e54255ee136bd5fdfce4b65a5eea57b08 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Thu, 4 Apr 2024 14:18:55 -0500 Subject: Avoid programmer error Use 'find "$VAR" | xarg rm -fr' which will error out if $VAR is unset. --- src/rc.slack-autoupdate | 10 ++++++---- src/slack-autoupdate | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/rc.slack-autoupdate b/src/rc.slack-autoupdate index 9563388..ba5f847 100644 --- a/src/rc.slack-autoupdate +++ b/src/rc.slack-autoupdate @@ -1,6 +1,6 @@ #!/bin/bash # -# Automatically update your system on reboot using packages in the UPDATE_DIR. +# Automatically update your system on reboot using packages in the PACKAGE_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 @@ -11,9 +11,9 @@ export PATH=$PATH:/usr/local/bin:/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" +PACKAGE_DIR="/var/spool/slack-autoupdate" -UPDATES="$(find "$UPDATE_DIR" -name '*.t*z' | sort)" +UPDATES="$(find "$PACKAGE_DIR" -name '*.t*z' | sort)" if [ -z "$UPDATES" ]; then exit 0 @@ -37,6 +37,8 @@ if [ "$OLD_KERNEL" != "$NEW_KERNEL" ]; then fi # All package updates have been processed. -find "$UPDATE_DIR" -mindepth 1 | xargs rm -fr +# +# This will error out if PACKAGE_DIR is accidentally unset. +find "$PACKAGE_DIR" -mindepth 1 | xargs rm -fr reboot diff --git a/src/slack-autoupdate b/src/slack-autoupdate index 4a7a80f..78501a8 100644 --- a/src/slack-autoupdate +++ b/src/slack-autoupdate @@ -19,7 +19,8 @@ NOTIFY="${NOTIFY:-no}" # Set to empty to disable reboot or 'now' to reboot immediately. REBOOT_TIME="${REBOOT_TIME:-""}" -# Packages are copied here on successful download. +# Packages are copied here on successful download. All contents of this +# directory will be deleted. PACKAGE_DIR="${PACKAGE_DIR:-/var/spool/slack-autoupdate}" # Packages are temporarily stored here until success. All contents of this @@ -54,8 +55,8 @@ 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" +find "$STAGING_DIR" -mindepth 1 | xargs rm -fr if ! OUTPUT="$( # Capture this subshell's error output to standard output. @@ -219,8 +220,8 @@ if [ -f "$UPDATE_ERROR" ]; then fi # Now that everything is successful. +find "$PACKAGE_DIR" -mindepth 1 | xargs rm -fr mv "$STAGING_DIR"/* "$PACKAGE_DIR/" -rm -fr "$STAGING_DIR" if [ -n "$REBOOT_TIME" ]; then nohup shutdown -r "$REBOOT_TIME" >/dev/null 2>&1 & -- cgit v1.2.3