added a mirrortimestamp check

This commit is contained in:
2025-05-21 16:36:28 +02:00
parent 6c23864e0e
commit c81a12d76c

View File

@@ -1,5 +1,49 @@
#!/usr/bin/bash
set -o pipefail
ALHP_STATS_URL='https://api.alhp.dev/stats'
ALHP_BQ_URL='https://api.alhp.dev/packages?limit=0&offset=0&status=queued&status=building'
mirrorlistsOutOfDate(){
local max_mirrors="${1:-1}"
local mirrorlists mirrorlist mirror_urls mirror_url all_mirrors=() alhp_timestamp
local -A mirror_timestamps=()
readarray -t mirrorlists < <(awk '
/^\s*\[.*x86-64-v[2-4].*\]/ { in_repo = 1; next }
in_repo && /^\s*Include\s*=\s*/ {
match($0, /Include\s*=\s*(.*)/, arr)
print arr[1]
in_repo = 0
}
' /etc/pacman.conf | sort -u
)
for mirrorlist in ${mirrorlists[@]}; do
readarray -t mirror_urls < <(
grep '^Server =' "$mirrorlist" | \
sed -E 's/^Server = (https?:\/\/[^$]+).*/\1\/lastupdate/'
)
all_mirrors+=(${mirror_urls[@]})
done
mapfile -t all_mirrors < <(printf '%s\n' ${all_mirrors[@]} | sort -u | head -n $max_mirrors)
#TODO: fork curls for better performance
for mirror_url in "${all_mirrors[@]}"; do
# curl quietly, fail silently, timeout 5s
timestamp=$(curl -fs --max-time 5 "$mirror_url" || echo "error")
mirror_timestamps["$mirror_url"]=$timestamp
done
alhp_timestamp=$(curl -fs --max-time 5 $ALHP_STATS_URL | jq .last_mirror_timestamp || echo "error")
for url in "${!mirror_timestamps[@]}"; do
if [[ ${mirror_timestamps[$url]} -lt $alhp_timestamp ]]; then
echo "Mirror: $url outdated."
fi
done
}
updatesAvailable() {
readarray -t repos < <(grep '^\[' /etc/pacman.conf | sed -e 's/[][]//g' | grep -E 'x86-64-v[2-4]')
@@ -29,7 +73,7 @@ updatesAvailable() {
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}"
api_url="$ALHP_BQ_URL${repo_query}"
if [[ -n $check_pkg ]]; then
building_pkgs=$(curl -s $api_url \
@@ -47,7 +91,6 @@ updatesAvailable() {
else
printf '%s\n' "${matches[@]}"
fi
else
matches=()
while read -r pkgname; do
@@ -64,4 +107,6 @@ updatesAvailable() {
fi
}
mirrorlistsOutOfDate
updatesAvailable $@