aboutsummaryrefslogtreecommitdiff
path: root/src/rc.slack-autoupdate
blob: ba5f847496c7675e25408598a769b7d69f038906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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

# 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 5 -p "Installing updates, press enter to skip this process..."; then
  exit 0
fi

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

for PKG in $UPDATES; do
  upgradepkg --install-new "$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

reboot