2018-12-29 14:25:55 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
source ${HOME}/bin/script_framework.sh
|
|
|
|
|
|
|
|
check_util rankmirrors # from pacman-contrib
|
|
|
|
|
|
|
|
outfile=/etc/pacman.d/mirrorlist
|
|
|
|
oldlist=/etc/pacman.d/mirrorlist.bak
|
|
|
|
|
|
|
|
if [ $(id -u) -eq 0 ]; then
|
|
|
|
step "Creating backup of current mirrorlist"
|
|
|
|
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
|
|
|
|
else
|
|
|
|
outfile=/tmp/mirrors.rank
|
|
|
|
oldlist=/etc/pacman.d/mirrorlist
|
|
|
|
warn "Not running as root, new mirrorlist will be written to ${outfile}"
|
|
|
|
fi
|
|
|
|
|
2021-05-15 16:49:40 +00:00
|
|
|
step "Collecting mirrors"
|
|
|
|
IFS=$'\n'
|
|
|
|
mirrors=(
|
|
|
|
$(
|
|
|
|
curl -sSfL "https://archlinux.org/mirrors/status/json/" |
|
|
|
|
jq -r '.urls[] | select(.active) | select(.completion_pct == 1.0) | select( .delay < 3600) | select(.protocol == "https") | .url'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
unset IFS
|
|
|
|
|
|
|
|
step "Measuring mirror speed, searching 5 fastest mirrors of ${#mirrors[@]} mirrors"
|
|
|
|
for url in "${mirrors[@]}"; do
|
|
|
|
echo "Server = ${url}\$repo/os/\$arch"
|
|
|
|
done |
|
2018-12-29 14:25:55 +00:00
|
|
|
rankmirrors -n 5 - |
|
2021-05-15 16:49:40 +00:00
|
|
|
tee "${outfile}"
|
2018-12-29 14:25:55 +00:00
|
|
|
|
|
|
|
step "Generating diff from old to new mirrorlist"
|
2021-05-15 16:49:40 +00:00
|
|
|
diff -wu "${oldlist}" "${outfile}"
|