Files
Cursor AgentandFrank Vitrano bba71040d6 Improve safety and CLI fidelity for everyday use
Drop default --noconfirm (opt-in via --noconfirm), fix --noremovemake,
forward pacman argv intact for -R/-D/-F/-T/-U, deepen PKGBUILD review,
show an install plan before building, and add shellcheck CI plus unit tests.

Co-authored-by: Frank Vitrano <WHC2006@users.noreply.github.com>
2026-07-23 14:39:03 +00:00

96 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# AUR upgrade detection and application
# List foreign packages (AUR candidates): name version
foreign_packages() {
pacman -Qm
}
# Compare installed foreign pkgs with AUR; print upgradable: name local -> remote
aur_outdated() {
local -a names=()
local -A localver=()
local name ver
while read -r name ver; do
[[ -z $name ]] && continue
names+=("$name")
localver[$name]=$ver
done < <(foreign_packages)
[[ ${#names[@]} -eq 0 ]] && return 0
# Batch in chunks of 100
local i chunk=100
local -a batch=()
for ((i = 0; i < ${#names[@]}; i++)); do
batch+=("${names[$i]}")
if ((${#batch[@]} == chunk || i == ${#names[@]} - 1)); then
local json
json=$(aur_multiinfo_json "${batch[@]}") || {
warn "Failed to query AUR updates"
batch=()
continue
}
local line rname rver
while IFS= read -r line; do
rname=${line%%|*}
rver=${line#*|}
[[ -z $rname ]] && continue
local lv=${localver[$rname]:-}
[[ -z $lv ]] && continue
if [[ $(vercmp_safe "$rver" "$lv") -gt 0 ]]; then
printf '%s %s -> %s\n' "$rname" "$lv" "$rver"
fi
done < <(jq -r '.[] | "\(.Name)|\(.Version)"' <<<"$json")
batch=()
fi
done
}
# Print outdated like pacman -Qu
cmd_query_aur_upgrades() {
local name old _arrow new
while read -r name old _arrow new; do
[[ -z $name ]] && continue
printf '%s %s -> %s\n' "$name" "$old" "$new"
done < <(aur_outdated)
return 0
}
# Upgrade all outdated AUR packages
cmd_upgrade_aur() {
local -a pkgs=()
local name old _arrow new
while read -r name old _arrow new; do
[[ -z $name ]] && continue
pkgs+=("$name")
msg2 "$name ${old} -> ${new}"
done < <(aur_outdated)
if [[ ${#pkgs[@]} -eq 0 ]]; then
msg "No AUR package upgrades are available"
return 0
fi
msg "Upgrading ${#pkgs[@]} AUR package(s)"
install_aur_packages "${pkgs[@]}"
}
# Full -Syu: refresh + repo upgrade + AUR upgrade
cmd_upgrade_all() {
local refresh=${1:-0}
sudoloop_start
local -a conf=()
mapfile -t conf < <(pac_noconfirm_args)
msg "Synchronizing databases and upgrading repository packages..."
if [[ $refresh -eq 1 ]]; then
as_root ${MIAUR_PACMAN} -Syu "${conf[@]}" || die "repository upgrade failed"
else
as_root ${MIAUR_PACMAN} -Su "${conf[@]}" || die "repository upgrade failed"
fi
msg "Checking for AUR updates..."
cmd_upgrade_aur
sudoloop_stop
}