improve version and mirror updating
shellcheck / shellcheck (push) Failing after 14s

This commit is contained in:
2026-11-04 07:08:44 -07:00
parent 7f37a1b9ee
commit c3ac9f49d0
10 changed files with 175 additions and 2 deletions
+23
View File
@@ -199,6 +199,29 @@ initramfs_build_failed() {
(( succeeded == 0 || succeeded < built ))
}
# pacman downloads from the first mirror in this list (system/mirrors.sh keeps
# it fresh). Overridable for the tests.
MIRRORLIST="${MIRRORLIST:-/etc/pacman.d/mirrorlist}"
# A mirror further behind Arch than this is stale; most sync every few hours
MIRROR_STALE_HOURS=24
# The first mirror in MIRRORLIST, without its /$repo/os/$arch
first_mirror() {
sed -nE 's/^[[:space:]]*Server[[:space:]]*=[[:space:]]*//p' "$MIRRORLIST" 2> /dev/null \
| head -n 1 | sed -E 's#/\$repo.*##'
}
# Print how many hours ago the first mirror last synced with Arch, from the
# timestamp mirrors publish in lastsync. Fails if it couldn't tell.
mirror_age_hours() {
local mirror lastsync
mirror="$(first_mirror)"
[ -n "$mirror" ] || return 1
lastsync="$(curl -sf --max-time 10 "$mirror/lastsync" 2> /dev/null)" || return 1
[[ "$lastsync" =~ ^[0-9]+$ ]] || return 1
echo $(( ($(date +%s) - lastsync) / 3600 ))
}
# Install a script atomically (copy to a temp file, then rename over the target)
# so a copy of it that is running right now keeps reading the old file
install_script() {