made repos an array again

This commit is contained in:
2025-05-21 04:01:39 +02:00
parent 6882433c77
commit a4f4a451e8

View File

@@ -1,7 +1,7 @@
#!/usr/bin/bash
updatesAvailable() {
repos=$(grep '^\[' /etc/pacman.conf | sed -e 's/[][]//g' | grep -E 'x86-64-v[2-4]')
readarray -t repos < <(grep '^\[' /etc/pacman.conf | sed -e 's/[][]//g' | grep -E 'x86-64-v[2-4]')
output_json=false
check_pkg=""
@@ -10,7 +10,7 @@ updatesAvailable() {
case "$1" in
-j|--json) output_json=true; shift ;;
--check-pkg)
check_pkg="$2"
check_pkg=$2
shift 2
;;
*)
@@ -22,18 +22,18 @@ updatesAvailable() {
declare -A pkgs
pacman -Sl "${repos[@]}" | while read -r _ name version status; do
while read -r _ name version status; do
if [[ $status == *installed* ]]; then
pkgs["$name"]=1
pkgs[$name]=1
fi
done
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[]')
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
@@ -51,17 +51,17 @@ updatesAvailable() {
else
matches=()
while read -r pkgname; do
if [[ -n "${pkgs[$pkgname]}" ]]; then
matches+=("$pkgname")
if [[ -n ${pkgs[$pkgname]} ]]; then
matches+=($pkgname)
fi
done < <(curl -s "$api_url" | jq -r '.packages[] | .split_packages[]')
done < <(curl -s $api_url | jq -r '.packages[] | .split_packages[]')
if $output_json; then
printf '%s\n' "${matches[@]}" | jq -Rn '[inputs]'
printf '%s\n' ${matches[@]} | jq -Rn '[inputs]'
else
printf '%s\n' "${matches[@]}"
printf '%s\n' ${matches[@]}
fi
fi
}
updatesAvailable "$@"
updatesAvailable $@