aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/rc.update
blob: d7818671df2cc41121cd9813d078b611e5364b13 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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.
#

# The init system is run without a $USER or $HOME, and they are needed for some
# applications.
export GNUPGHOME="$(getent passwd root | cut -d: -f6)/.gnupg"

# A local Slackware mirror with just enough information to support slackpkg.
#
# This step could be skipped if slackpkg supports downloading updates without
# installing them.
LOCAL_MIRROR=${LOCAL_MIRROR:-"/var/cache/slack-autoupdate/mirror"}

# slackpkg exit code when updates are available.
SLACKPKG_UPDATES_PENDING=100

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

# Where information about pending updates is stored.
UPDATE_INFO="$UPDATE_DIR/info.txt"

# Where information about failed updates is stored.
UPDATE_ERROR="$UPDATE_DIR/error.txt"

UPDATES=$(find "$UPDATE_DIR" -name '*.t*z' | sort)
SLACKPKG_UPDATES="$(slackpkg -mirror="file:///$LOCAL_MIRROR/" check-updates 1>/dev/null 2>/dev/null; echo $?)"

if [ -z "$UPDATES" ] && [ "$SLACKPKG_UPDATES" != "$SLACKPKG_UPDATES_PENDING" ]; 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)"

if [ "$SLACKPKG_UPDATES" == "$SLACKPKG_UPDATES_PENDING" ]; then
  slackpkg -batch=on -default_answer=n -mirror="file:///$LOCAL_MIRROR/" update >/dev/null
  slackpkg -batch=on -default_answer=y -postinst=off -mirror="file:///$LOCAL_MIRROR/" upgrade-all
fi

for PKG in $UPDATES; do
  upgradepkg --install-new "$PKG" &&
    rm "$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 -not -path "$UPDATE_DIR_IGNORED/*" | xargs rm -fr

reboot