diff --git a/alhp-check.sh b/alhp-check.sh new file mode 100644 index 0000000..f578f25 --- /dev/null +++ b/alhp-check.sh @@ -0,0 +1,71 @@ +#!/usr/bin/bash + +updatesAvailable() { + repos=("core-x86-64-v3" "extra-x86-64-v3" "multilib-x86-64-v3") + + output_json=false + check_pkg="" + + # Parse arguments + 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 + + # Collect installed packages + 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 + # Check if a specific package is building + 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 + # Full scan + 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 "$@" diff --git a/alhp-install-check.hook b/alhp-install-check.hook new file mode 100644 index 0000000..9b1a152 --- /dev/null +++ b/alhp-install-check.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Install +Type = Package +Target = * + +[Action] +Description = Check if packages being installed are building on ALHP +When = PreTransaction +Exec = /usr/local/bin/alhp-pacman-hook.sh %n +Depends = jq,curl,yay diff --git a/alhp-pacman-hook.sh b/alhp-pacman-hook.sh new file mode 100644 index 0000000..8e3c208 --- /dev/null +++ b/alhp-pacman-hook.sh @@ -0,0 +1,28 @@ +#!/usr/bin/bash + +ALHP_SCRIPT="/usr/local/bin/alhp-check.sh" +building_pkgs=() + +if [[ $# -gt 0 ]]; then + # Check only specified packages (for install hook) + for pkg in "$@"; do + result=$($ALHP_SCRIPT --check-pkg "$pkg" -j) + if [[ "$result" != "[]" ]]; then + building_pkgs+=("$pkg") + fi + done +else + # No args: full scan (for upgrade hook) + mapfile -t building_pkgs < <($ALHP_SCRIPT) +fi + +if (( ${#building_pkgs[@]} > 0 )); then + echo "WARNING: The following packages are currently building or queued on ALHP:" + for p in "${building_pkgs[@]}"; do + echo " - $p" + done + # Uncomment to abort pacman transaction + # exit 1 +fi + +exit 0 diff --git a/alhp-upgrade-check.hook b/alhp-upgrade-check.hook new file mode 100644 index 0000000..a99939d --- /dev/null +++ b/alhp-upgrade-check.hook @@ -0,0 +1,10 @@ +[Trigger] +Operation = Upgrade +Type = Package +Target = * + +[Action] +Description = Check if installed packages have new versions building on ALHP +When = PreTransaction +Exec = /usr/local/bin/alhp-pacman-hook.sh +Depends = jq,curl,yay