aboutsummaryrefslogtreecommitdiff
path: root/src/rc.slack-autoupdate
diff options
context:
space:
mode:
Diffstat (limited to 'src/rc.slack-autoupdate')
-rw-r--r--src/rc.slack-autoupdate40
1 files changed, 40 insertions, 0 deletions
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