# Install AUR packages one at a time, so a single build failure (common with the
# AUR — removed packages, broken builds) doesn't abort the rest. yay still pulls
# each package's AUR dependencies automatically. Failures are collected and
# reported at the end, and logged to ~/aur-failed.log for retrying.
LOG="$HOME/aur-failed.log"
: > "$LOG"

while read -r pkg; do
  yay -S --needed --noconfirm "$pkg" || echo "$pkg" >> "$LOG"
done < <(grep -vE '^\s*#|^\s*$' "$REPO_ROOT/03-user/packages/aur.txt")

if [ -s "$LOG" ]; then
  echo ""
  echo "!! $(wc -l < "$LOG") AUR package(s) FAILED — retry later with:"
  echo "     yay -S \$(cat $LOG)"
  echo "   failed:"
  sed 's/^/     - /' "$LOG"
else
  rm -f "$LOG"
  info "all AUR packages installed"
fi
