diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rwxr-xr-x | bin/pacman-offline | 59 | ||||
-rw-r--r-- | hook/99-pacman-offline.hook | 2 | ||||
-rwxr-xr-x | systemd/pacman-offline | 16 | ||||
-rw-r--r-- | systemd/pacman-offline-reboot.service | 4 |
6 files changed, 60 insertions, 26 deletions
@@ -7,7 +7,7 @@ SED := sed # this is just a fallback in case you do not # use git but downloaded a release tarball... -VERSION := 0.2.3 +VERSION := 0.3.0 all: README.html @@ -4,7 +4,7 @@ pacman-offline **Run offline system update with pacman.** The offline system update with pacman is achieved by integrating into -[offline updates in systemd](https://www.freedesktop.org/software/systemd/man/systemd.offline-updates.html#/etc/system-update). +[offline updates in systemd](https://www.freedesktop.org/software/systemd/man/systemd.offline-updates.html). In fact only two scripts and a number of systemd unit files are used to glue `systemd` and `pacman`. @@ -29,6 +29,7 @@ It accepts some arguments: * *-c*: clean before download * *-f*: force if other system-update is pending * *-h*: show help +* *-p*: reboot, install and poweroff immediately * *-r*: reboot and install immediately * *-t*: start timer for nightly reboot * *-y*: update sync databases diff --git a/bin/pacman-offline b/bin/pacman-offline index acc8646..a6e2a99 100755 --- a/bin/pacman-offline +++ b/bin/pacman-offline @@ -12,19 +12,41 @@ set -e function help() { echo "usage: ${0} [OPTIONS]" echo - echo ' -f force if other system-update is pending' echo ' -c clean before download' + echo ' -f force if other system-update is pending' echo ' -h this help' + echo ' -p reboot, install and poweroff immediately' echo ' -r reboot and install immediately' echo ' -t start timer for nightly reboot' echo ' -y update sync databases' } CLEAN=0 +POWEROFF=0 REBOOT=0 TIMER=0 -while getopts 'cfhrty' opt; do +while getopts 'cfhprty' opt; do + case ${opt} in + h) + help + exit 0 + ;; + esac +done + +if [ "${UID}" -ne 0 ]; then + if command -v run0 >/dev/null; then + echo 'Missing privileges, trying to elevate.' >&2 + exec run0 "${0}" "${@}" + fi + + echo "You need elevated privileges. Please run as user 'root'!" >&2 + exit 1 +fi + +OPTIND=1 +while getopts 'cfhprty' opt; do case ${opt} in c) if pacman-conf 'CleanMethod' | grep -q 'KeepCurrent'; then @@ -36,9 +58,9 @@ while getopts 'cfhrty' opt; do f) rm -f /system-update ;; - h) - help - exit 0 + p) + POWEROFF=1 + REBOOT=1 ;; r) REBOOT=1 @@ -82,19 +104,26 @@ pacman --config /run/pacman.conf --sync --noconfirm --sysupgrade --downloadonly # enable system update ln -sf /var/cache/pacman/pkg /system-update +if [ ${POWEROFF} -eq 1 ]; then + touch /run/system-update-poweroff +fi -# reboot if requested +# (soft-)reboot if requested if [ ${REBOOT} -eq 1 ]; then - if systemctl --dry-run soft-reboot 2>/dev/null; then - echo "Soft-rebooting for update." - systemctl soft-reboot - else - echo "Rebooting for update." - systemctl reboot - fi -# force a soft-reboot on (manual) reboot -elif [ -e /usr/lib/systemd/system/systemd-soft-reboot.service ]; then + echo "Soft-rebooting for update." + systemctl soft-reboot +else + # force a soft-reboot on (manual) reboot ... ln -sf ../../../usr/lib/systemd/system/systemd-soft-reboot.service /run/systemd/system/systemd-reboot.service + + # ... and also on poweroff, but prepare poweroff + cp /usr/lib/systemd/system/systemd-soft-reboot.service /run/systemd/system/systemd-poweroff.service + cat >> /run/systemd/system/systemd-poweroff.service <<-EOF + + [Service] + ExecStart=/usr/bin/touch /run/system-update-poweroff + EOF + systemctl daemon-reload fi diff --git a/hook/99-pacman-offline.hook b/hook/99-pacman-offline.hook index 0538072..9c4f456 100644 --- a/hook/99-pacman-offline.hook +++ b/hook/99-pacman-offline.hook @@ -8,4 +8,4 @@ Target = * [Action] Description = Disabling scheduled pacman offline update... When = PostTransaction -Exec = /bin/sh -c 'rm -fv /system-update /run/systemd/system/systemd-reboot.service && systemctl daemon-reload' +Exec = /bin/sh -c 'rm --force /system-update /run/systemd/system/systemd-poweroff.service /run/systemd/system/systemd-reboot.service && systemctl daemon-reload' diff --git a/systemd/pacman-offline b/systemd/pacman-offline index 9471bfc..9bae2ee 100755 --- a/systemd/pacman-offline +++ b/systemd/pacman-offline @@ -19,12 +19,14 @@ 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 +# remove triggering symlink and reboot & poweroff override +rm --force \ + /system-update \ + /run/systemd/system/systemd-poweroff.service \ + /run/systemd/system/systemd-reboot.service # 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 @@ -32,8 +34,10 @@ pacman --config /run/pacman.conf --sync --noconfirm --sysupgrade # 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 +# poweroff or (soft-)reboot +if [ -e '/run/system-update-poweroff' ]; then + systemctl poweroff +elif [ -s "/usr/lib/modules/$(uname -r)/pkgbase" ]; then systemctl soft-reboot else systemctl reboot diff --git a/systemd/pacman-offline-reboot.service b/systemd/pacman-offline-reboot.service index 26dca94..c131d70 100644 --- a/systemd/pacman-offline-reboot.service +++ b/systemd/pacman-offline-reboot.service @@ -6,9 +6,9 @@ # (at your option) any later version. [Unit] -Description=Reboot for pacman offline system-update +Description=Soft-reboot for pacman offline system-update ConditionPathExists=/system-update [Service] Type=oneshot -ExecStart=/bin/sh -c "if systemctl --dry-run soft-reboot 2>/dev/null; then systemctl soft-reboot; else systemctl reboot; fi" +ExecStart=/usr/bin/systemctl soft-reboot |