added files

This commit is contained in:
2025-05-21 03:10:07 +02:00
parent 8c734e0141
commit 79da7e0eba
4 changed files with 119 additions and 0 deletions

71
alhp-check.sh Normal file
View File

@@ -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 "$@"

10
alhp-install-check.hook Normal file
View File

@@ -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

28
alhp-pacman-hook.sh Normal file
View File

@@ -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

10
alhp-upgrade-check.hook Normal file
View File

@@ -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