2024-03-06 16:55:27 -07:00

69 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env zsh
# This script runs a full update, automatically upgrading specific packages
# first so as to prevent the issue that occurs when the keyring package is
# sufficiently out of date that it can't verify other packages.
# This script cannot be run as root, as it invokes the AUR helper `paru`.
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root" 1>&2
exit 1
fi
# Check for updates
repo_updates=$(checkupdates --nocolor)
aur_updates=$(paru -Qum)
grep -q "^linux " <<< "$repo_updates"
has_kernel_update=$?
# Fetch news
news=$(paru -Pw 2> /dev/null)
has_news=$?
if [[ $has_news == '0' ]]; then
# Display news in pager if necessary (more lines than the terminal can display)
[[ $(echo "$news" | wc -l) -gt $LINES ]] && echo "$news" | less
[[ $(echo "$news" | wc -l) -le $LINES ]] && echo "$news"
echo -n "Proceed with update? [y/N] "
read -q resp
echo
if [[ $resp == 'n' ]]; then
echo "Aborting."
exit 1
fi
fi
# If there is a kernel update, alert the user and prompt for confirmation
if [[ $has_kernel_update == '0' ]]; then
echo -n "Kernel update available. Proceed? [y/N] "
read -q resp
echo
if [[ $resp == 'n' ]]; then
echo "Aborting."
exit 1
fi
fi
# Update keyring
sudo pacman-key --populate archlinux
# Upgrade packages
paru --noconfirm -Syu
return_code=$?
# If a kernel update was performed, ask the user to reboot
if [[ $has_kernel_update == '0' ]]; then
echo -n "Kernel updated. Reboot? [y/N] "
read -q resp
echo
if [[ $resp == 'n' ]]; then
echo "Aborting."
exit 1
fi
sudo reboot
fi
exit $return_code