#!/usr/bin/bash updatesAvailable() { repos=("core-x86-64-v3" "extra-x86-64-v3" "multilib-x86-64-v3") 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 yay -Sl "${repos[@]}" | while read -r _ name version status; do if [[ $status == *installed* ]]; then pkgs["$name"]=1 fi done 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 "$@"