#!/bin/bash echo "Updating AUR..." YAY_FLAGS=(--noconfirm --answerdiff=None --answeredit=None --answerclean=None) # Only rebuild yay when yay itself is broken (e.g. a pacman upgrade bumped # libalpm). A failing AUR package is not fixed by a rebuild, so let that error # show and fail the hook instead. if ! yay --version &>/dev/null; then echo "yay is broken (likely a libalpm bump). Rebuilding yay..." sudo pacman -R --noconfirm yay cd /tmp || exit 1 rm -rf yay git clone https://aur.archlinux.org/yay.git cd yay || exit 1 makepkg -si --noconfirm cd .. rm -rf yay cd || exit 1 fi if ! yay -Sua "${YAY_FLAGS[@]}"; then # yay goes on to build and install the other packages after one fails, so # whatever is still out of date is what failed. Name it at the end, where # it's easy to find; yay's own error is far up in the build output. mapfile -t STUCK < <(yay -Qua 2> /dev/null | awk '{print $1}') echo if (( ${#STUCK[@]} > 0 )); then echo "These AUR packages could not be updated: ${STUCK[*]}" echo "The other AUR updates are installed. AUR packages are maintained by" echo "volunteers, and a broken update is usually fixed on the AUR within a few" echo "days; the next update will try again. The error is above, just before" echo "\"error making\" or \"error downloading sources\"." else echo "yay reported an error, though no AUR updates are left to install." fi exit 1 fi