Files
ALHP_PACMAN_HOOKS/scripts/alhp-check.sh
2025-05-21 04:01:39 +02:00

68 lines
1.5 KiB
Bash

#!/usr/bin/bash
updatesAvailable() {
readarray -t repos < <(grep '^\[' /etc/pacman.conf | sed -e 's/[][]//g' | grep -E 'x86-64-v[2-4]')
output_json=false
check_pkg=""
while [[ $# -gt 0 ]]; do
case "$1" in
-j|--json) output_json=true; shift ;;
--check-pkg)
check_pkg=$2
shift 2
;;
*)
echo "Unknown argument: $1"
return 1
;;
esac
done
declare -A pkgs
while read -r _ name version status; do
if [[ $status == *installed* ]]; then
pkgs[$name]=1
fi
done < <(pacman -Sl ${repos[@]})
repo_query=$(printf '&repo=%s' "${repos[@]}")
api_url="https://api.alhp.dev/packages?limit=0&offset=0&status=queued&status=building${repo_query}"
if [[ -n $check_pkg ]]; then
building_pkgs=$(curl -s $api_url \
| jq -r --arg pkg $check_pkg '.packages[] | select(.split_packages[] == $pkg) | .split_packages[]')
matches=()
for bpkg in $building_pkgs; do
if [[ -n "${pkgs[$bpkg]}" ]]; then
matches+=("$bpkg")
fi
done
if $output_json; then
printf '%s\n' "${matches[@]}" | jq -Rn '[inputs]'
else
printf '%s\n' "${matches[@]}"
fi
else
matches=()
while read -r pkgname; do
if [[ -n ${pkgs[$pkgname]} ]]; then
matches+=($pkgname)
fi
done < <(curl -s $api_url | jq -r '.packages[] | .split_packages[]')
if $output_json; then
printf '%s\n' ${matches[@]} | jq -Rn '[inputs]'
else
printf '%s\n' ${matches[@]}
fi
fi
}
updatesAvailable $@