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
|
|
|
|
|
2020-07-15 21:18:52 +00:00
|
|
|
IFS=$'\n'
|
|
|
|
|
2021-10-20 19:25:37 +00:00
|
|
|
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..."
|
|
|
|
|
2020-07-15 21:18:52 +00:00
|
|
|
# Prime the local_versions array from the package list
|
|
|
|
for package in $(<aur-packages); do
|
|
|
|
local_versions[${package}]=0.0.0
|
2020-07-19 22:49:28 +00:00
|
|
|
aur_query+=("arg[]=${package}")
|
2020-07-15 21:18:52 +00:00
|
|
|
done
|
2019-09-29 23:20:25 +00:00
|
|
|
|
2020-07-15 21:18:52 +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)
|
|
|
|
|
2020-07-15 21:18:52 +00:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2020-05-31 13:20:55 +00:00
|
|
|
[ $(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[@]}"
|