#!/bin/sh set -e function help() { echo "usage: ${0} [OPTIONS]" echo echo ' -f force if other system-update is pending' echo ' -h this help' echo ' -r reboot and install immediately' echo ' -t start timer for nightly reboot' echo ' -y update sync databases' } REBOOT=0 TIMER=0 while getopts 'fhrty' opt; do case ${opt} in f) rm -f /system-update ;; h) help exit 0 ;; r) REBOOT=1 ;; t) TIMER=1 ;; y) pacman --sync --refresh ;; esac done # make sure no other update is pending if [ -e '/system-update' -a "$(readlink '/system-update')" != '/var/cache/pacman/pkg' ]; then echo 'Another update is pending.' >&2 exit 1 fi # 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 the symlink for now, will be recreated it later rm -f /system-update # check for available updates if [ "$(pacman --config /run/pacman.conf --sync --sysupgrade --print | wc -l)" -eq 0 ]; then echo "No updates available." exit 0 fi # download packages pacman --config /run/pacman.conf --sync --noconfirm --sysupgrade --downloadonly # enable system update ln -sf /var/cache/pacman/pkg /system-update # reboot if requested if [ ${REBOOT} -eq 1 ]; then systemctl reboot # start timer if requested elif [ ${TIMER} -eq 1 ]; then systemctl start pacman-offline-reboot.timer fi