diff options
Diffstat (limited to 'releng')
3 files changed, 66 insertions, 0 deletions
diff --git a/releng/airootfs/etc/systemd/system/chaotic-rankmirrors.service b/releng/airootfs/etc/systemd/system/chaotic-rankmirrors.service new file mode 100644 index 0000000..d0d3a03 --- /dev/null +++ b/releng/airootfs/etc/systemd/system/chaotic-rankmirrors.service @@ -0,0 +1,11 @@ +[Unit] +Description=Rank Chaotic-AUR mirrors by speed +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/chaotic-rankmirrors + +[Install] +WantedBy=multi-user.target diff --git a/releng/airootfs/etc/systemd/system/multi-user.target.wants/chaotic-rankmirrors.service b/releng/airootfs/etc/systemd/system/multi-user.target.wants/chaotic-rankmirrors.service new file mode 120000 index 0000000..0965d05 --- /dev/null +++ b/releng/airootfs/etc/systemd/system/multi-user.target.wants/chaotic-rankmirrors.service @@ -0,0 +1 @@ +/etc/systemd/system/chaotic-rankmirrors.service
\ No newline at end of file diff --git a/releng/airootfs/usr/local/bin/chaotic-rankmirrors b/releng/airootfs/usr/local/bin/chaotic-rankmirrors new file mode 100755 index 0000000..71c256e --- /dev/null +++ b/releng/airootfs/usr/local/bin/chaotic-rankmirrors @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +MIRRORLIST="/etc/pacman.d/chaotic-mirrorlist" +TIMEOUT=6 +TEST_PATH="chaotic-aur/x86_64/chaotic-aur.db" +TOP_N=5 + +MIRRORS=( + "de-mirror" "cdn-mirror" "geo-mirror" "pl-mirror" + "nl-mirror" "ch-mirror" "se-mirror" "fr-mirror" + "gb-mirror" "de-2-mirror" "nl-1-mirror" "pl-1-mirror" + "se-1-mirror" "ch-1-mirror" +) + +tmp=$(mktemp) + +echo "==> Ranking Chaotic-AUR mirrors..." + +for m in "${MIRRORS[@]}"; do + url="https://${m}.chaotic.cx/${TEST_PATH}" + t=$(curl -o /dev/null -s -w "%{time_starttransfer}" \ + --max-time "$TIMEOUT" --connect-timeout 3 \ + -r 0-1023 "$url" 2>/dev/null) + rc=$? + if [ "$rc" -eq 0 ] && [[ "$t" != "0.000000" ]] && [[ -n "$t" ]]; then + echo "${t} ${m}" >> "$tmp" + echo " OK ${t}s ${m}" + else + echo " FAIL ${m}" + fi +done + +if [ ! -s "$tmp" ]; then + echo "==> WARNING: no mirrors responded, keeping original mirrorlist" + rm -f "$tmp" + exit 0 +fi + +mapfile -t top < <(sort -n "$tmp" | head -n "$TOP_N") +rm -f "$tmp" + +cp "$MIRRORLIST" "${MIRRORLIST}.bak" 2>/dev/null || true + +{ + echo "# Chaotic-AUR mirrorlist" + echo "# Generated by chaotic-rankmirrors on $(date)" + echo "" + for e in "${top[@]}"; do + m="${e#* }" + echo "Server = https://${m}.chaotic.cx/\$repo/\$arch" + done +} > "$MIRRORLIST" + +echo "==> Done. Updated mirrorlist with ${#top[@]} fastest mirrors." |