1
0
Fork 0
mirror of https://github.com/Luzifer/archrepo.git synced 2024-11-10 10:30:02 +00:00
archrepo/scripts/check_aur_updates.sh

76 lines
1.9 KiB
Bash
Raw Normal View History

2019-09-29 23:20:25 +00:00
#!/bin/bash
set -euo pipefail
source scripts/script_framework.sh
join_by() {
local d=$1
shift
echo -n "$1"
shift
printf "%s" "${@/#/$d}"
}
declare -A local_versions
declare -A aur_versions
IFS=$'\n'
database=$(find ${REPO_DIR:-$(pwd)} -maxdepth 1 -mindepth 1 -name '*.db.tar.xz' -or -name '*.db.tar.zst')
2019-09-29 23:20:25 +00:00
aur_query=("https://aur.archlinux.org/rpc/?v=5&type=info")
step "Collecting local package versions..."
# Prime the local_versions array from the package list
for package in $(<aur-packages); do
local_versions[${package}]=0.0.0
aur_query+=("arg[]=${package}")
done
2019-09-29 23:20:25 +00:00
# Update versions in local_versions from database entries
known_packages=$(tar -tf ${database} | grep -v /desc | sed -E 's@^(.*)-([^-]+-[0-9]+)/$@\1 \2@')
2019-09-29 23:20:25 +00:00
for package in ${known_packages}; do
name=$(echo "${package}" | cut -d ' ' -f 1)
version=$(echo "${package}" | cut -d ' ' -f 2)
# If there is no entry most likely this is not an AUR package, skip it
[[ -n ${local_versions[${name}]:-} ]] || continue
2019-09-29 23:20:25 +00:00
local_versions[${name}]=${version}
done
step "Fetching AUR package versions..."
aur_packages=$(curl -sSfL "$(join_by "&" "${aur_query[@]}")" | jq -r '.results | .[] | .Name + " " + .Version')
step "Collecting AUR package versions..."
for package in ${aur_packages}; do
name=$(echo "${package}" | cut -d ' ' -f 1)
version=$(echo "${package}" | cut -d ' ' -f 2)
aur_versions[${name}]=${version}
done
updates=()
step "Checking for updates..."
for package in "${!local_versions[@]}"; do
local_version="${local_versions[${package}]}"
aur_version="${aur_versions[${package}]:-}"
[[ -n ${aur_version} ]] || {
error "Package ${package} did not yield a version from AUR (local=${local_version})"
continue
}
[ $(vercmp "${local_version}" "${aur_version}") -eq -1 ] && {
2019-09-29 23:20:25 +00:00
warn "Package ${package} needs update (${local_version} => ${aur_version})"
updates+=("${package}")
continue
}
success "Package ${package} is up-to-date (${local_version})"
done
echo "${updates[@]}"