Last active
December 1, 2023 20:19
-
-
Save Absolucy/c30be2d5d5259fa26ad5b1eb849761f9 to your computer and use it in GitHub Desktop.
Arch Linux rate-mirrors script (Arch + CachyOS + archzfs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
TMP_SUFFIX=".rate-mirrors" | |
MIRROR_FOLDER="/etc/pacman.d/mirrors" | |
PROTOCOLS="https" | |
TIMEOUT_MS="5000" | |
[ -d "${MIRROR_FOLDER}" ] || sudo mkdir -p "${MIRROR_FOLDER}" | |
TMPDIR="$(mktemp --directory --suffix "${TMP_SUFFIX}")" | |
function cleanup() { | |
[[ -n "${TMPDIR}" ]] && rm -rf "${TMPDIR}" | |
} | |
trap cleanup EXIT | |
# arch repos | |
echo ">=== Rating Arch Linux repos <===" | |
rate-mirrors --per-mirror-timeout "${TIMEOUT_MS}" --protocol "${PROTOCOLS}" --save "${TMPDIR}/arch-linux.list" arch | |
# cachyos repos | |
echo ">=== Rating CachyOS (x86_64) repos <===" | |
rate-mirrors --per-mirror-timeout "${TIMEOUT_MS}" --protocol "${PROTOCOLS}" --save "${TMPDIR}/cachyos.list" cachyos --arch "x86_64" --path-to-test "x86_64/cachyos-extra/cachyos-extra.files" | |
echo ">=== Rating CachyOS (x86_64-v3) repos <===" | |
rate-mirrors --per-mirror-timeout "${TIMEOUT_MS}" --protocol "${PROTOCOLS}" --save "${TMPDIR}/cachyos-v3.list" cachyos --arch "x86_64_v3" --path-to-test "x86_64_v3/cachyos-extra-v3/cachyos-extra-v3.files" | |
# archzfs repos | |
echo ">=== Rating ArchZFS repos <===" | |
ARCHZFS_MIRRORS="$(curl https://raw.githubusercontent.com/wiki/archzfs/archzfs/Home.md | grep "Server =" - | cut -d ' ' -f 3 | sed 's/\$repo\/\$arch//' | sort | uniq)" | |
rate-mirrors --per-mirror-timeout "${TIMEOUT_MS}" --output-prefix "Server = " --protocol "${PROTOCOLS}" --save "${TMPDIR}/archzfs.list" stdin --path-to-test "archzfs/x86_64/archzfs.files" --path-to-return '$repo/$arch' < <(echo "${ARCHZFS_MIRRORS}") | |
sudo mv --force --target-directory="${MIRROR_FOLDER}" "${TMPDIR}"/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment