#!/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 ' -y update sync databases' } REBOOT=0 while getopts 'fhry' opt; do case ${opt} in f) rm -f /system-update ;; h) help exit 0 ;; r) REBOOT=1 ;; y) pacman -Sy ;; 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 # remove the symlink for now, will be recreated it later rm -f /system-update # check for available updates if [ "$(pacman -Sup | wc -l)" -eq 0 ]; then echo "No updates available." exit 0 fi # download packages pacman -Suw --noconfirm # enable system update ln -sf /var/cache/pacman/pkg /system-update # reboot if requested if [ ${REBOOT} -eq 1 ]; then systemctl reboot fi