aboutsummaryrefslogtreecommitdiff
#!/bin/bash 
#
# 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
# will run if found.  We recommend placing this under /usr/local/sbin.
#

export PATH=$PATH:/usr/local/bin:/usr/local/sbin

# Duration in seconds to wait before installing pending updates.
WAIT_TIME=5

# Where packages are stored pending installation.  You can use sub-directories
# to order and group packages.
PACKAGE_DIR="/var/spool/slack-autoupdate"

UPDATES="$(find "$PACKAGE_DIR" -name '*.t*z' | sort)"

if [ -z "$UPDATES" ]; then
  exit 0
fi

if read -r -t "$WAIT_TIME" -p "Your system has pending software updates.  They will be installed in ${WAIT_TIME} seconds.  Press enter to skip..."; then
  exit 0
fi
echo " proceeding."

OLD_KERNEL="$(md5sum /boot/vmlinuz | cut -f1 -d' ')"

for PKG in $UPDATES; do
  upgradepkg --install-new --terse "$PKG"
done

NEW_KERNEL="$(md5sum /boot/vmlinuz | cut -f1 -d' ')"
if [ "$OLD_KERNEL" != "$NEW_KERNEL" ]; then
  if command -v install-kernel &> /dev/null; then
    install-kernel /boot/vmlinuz
  fi
fi

# All package updates have been processed.
#
# This will error out if PACKAGE_DIR is accidentally unset.
find "$PACKAGE_DIR" -mindepth 1 | xargs rm -fr

echo "All updates have been installed."

reboot