diff options
Diffstat (limited to 'bin/pacman-offline')
-rwxr-xr-x | bin/pacman-offline | 59 |
1 files changed, 44 insertions, 15 deletions
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 |