Created
October 14, 2023 14:42
-
-
Save tralce/1819020979705e37faf0b33f36b34b8a to your computer and use it in GitHub Desktop.
This file contains 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 | |
trap exit 1 INT | |
tmp="$(mktemp)" | |
inputfile="$tmp" | |
outputfile="/etc/pacman.d/mirrorlist" | |
source ~/.bin/src.sh | |
usage() { | |
echo "sortmirrors.sh [-i inputfile] [-o outputfile]" | |
echo "inputfile default: $inputfile" | |
echo "outputfile default: $outputfile" | |
exit "$1" | |
} | |
while getopts "i:o:h" arg | |
do | |
case $arg in | |
i) inputfile="$OPTARG";; | |
o) outputfile="$OPTARG";; | |
h) usage 0;; | |
?|*) usage 1;; | |
esac | |
done | |
shift $(( OPTIND - 1 )) | |
echo -e "Input file:\t$inputfile" | |
echo -e "Output file\t$outputfile" | |
echo -e "If input file isn't specified, reflector\nwill download a fresh one from MirrorStatus" | |
echo -e "Enter to continue... \n" | |
read enterKey | |
if [ -f "$outputfile" ] | |
then | |
if [ "$inputfile" == "$tmp" ] | |
then | |
reflector --country "United States" --age 3 --fastest 7 --sort rate --verbose --save "$tmp" | |
else | |
cp "$inputfile" "$tmp" | |
fi | |
sed -i -e 's/^#Server/Server/' -e '/^##/d' -e '/^$/d' "$tmp" | |
rankmirrors -v -n 10 "$tmp" | checkroot tee "$outputfile" | |
rm "$tmp" | |
else | |
echo "$outputfile doesn't seem to exist." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment