aboutsummaryrefslogtreecommitdiffstats
path: root/systemd/pacman-offline
diff options
context:
space:
mode:
Diffstat (limited to 'systemd/pacman-offline')
-rwxr-xr-xsystemd/pacman-offline51
1 files changed, 39 insertions, 12 deletions
diff --git a/systemd/pacman-offline b/systemd/pacman-offline
index 9471bfc..f7ba48a 100755
--- a/systemd/pacman-offline
+++ b/systemd/pacman-offline
@@ -1,6 +1,6 @@
#!/bin/sh
-# (C) 2017-2024 by Christian Hesse <mail@eworm.de>
+# (C) 2017-2025 by Christian Hesse <mail@eworm.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,27 +14,54 @@ if [ "$(readlink '/system-update')" != '/var/cache/pacman/pkg' ]; then
exit 0
fi
+# force the proper action on failure, ...
+if [ -e '/run/pacman-offline-poweroff' ]; then
+ ln -sf ../../../usr/lib/systemd/system/poweroff.target \
+ /run/systemd/system/pacman-offline-failure.target
+else
+ ln -sf ../../../usr/lib/systemd/system/reboot.target \
+ /run/systemd/system/pacman-offline-failure.target
+fi
+# ... remove triggering symlink and reboot & poweroff override, ...
+rm --force \
+ /system-update \
+ /run/systemd/system/systemd-poweroff.service \
+ /run/systemd/system/systemd-reboot.service
+# ... and reload
+systemctl daemon-reload
+
# exclude /etc/pacman.d/offline.conf
function finish { rm -f /run/pacman.conf; }
trap finish EXIT
-sed '/^Include *= *\/etc\/pacman\.d\/offline\.conf$/s|^|#|' < /etc/pacman.conf > /run/pacman.conf
-
-# remove triggering symlink and (soft-)reboot override
-rm -f /system-update
-rm -f /run/systemd/system/systemd-reboot.service
+sed \
+ -e '/^Include *= *\/etc\/pacman\.d\/offline\.conf$/s|^|#|' \
+ -e '/^#Include *= *\/etc\/pacman\.d\/offline-include\.conf$/s|^#||' \
+ < /etc/pacman.conf > /run/pacman.conf
# install updates
-if [ "$(pacman --sync --print --needed archlinux-keyring | wc -l)" -gt 0 ]; then
+if [ "$(pacman --sync --print --needed archlinux-keyring | wc -l)" -gt 0 ]; then
pacman --sync --noconfirm archlinux-keyring
fi
pacman --config /run/pacman.conf --sync --noconfirm --sysupgrade
+# clean up config file, drop trap
+rm -f /run/pacman.conf
+trap - EXIT
+
# clean up package cache
pacman --sync --noconfirm --clean
-# reboot
-if [ -s "/usr/lib/modules/$(uname -r)/pkgbase" ] && systemctl --dry-run soft-reboot 2>/dev/null; then
- systemctl soft-reboot
-else
- systemctl reboot
+# sync the storage
+sync
+
+# prepare for soft-reboot via override when applicable
+if [ ! -e '/run/pacman-offline-poweroff' -a \
+ -s "/usr/lib/modules/$(uname -r)/pkgbase" ]; then
+ ln -sf ../../../usr/lib/systemd/system/systemd-soft-reboot.service \
+ /run/systemd/system/systemd-reboot.service
+ systemctl daemon-reload
fi
+
+# All done, just touch a status file and exit successfully!
+# (Soft-)Reboot or Poweroff is done by specific units.
+touch /run/pacman-offline-done