# Some ideas and code reworked from other resources
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
-VER="2.0.46" # installer version
+VER="2.0.47" # installer version
DIST="ArchLabs" # linux distributor
MNT="/mnt" # install mountpoint
ANS="/tmp/ans" # dialog answer file
if hash reflector >/dev/null 2>&1; then
reflector --score 120 -l 50 -f 5 --sort rate --save "$mfile"
elif hash rankmirrors >/dev/null 2>&1; then
- i="$(json 'ip' "check&?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=ip")"
- c="$(json 'country_code' "${i}?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=country_code")"
- if [[ $c && $c =~ (CA|US) ]]; then
- m="https://www.archlinux.org/mirrorlist/?country=US&country=CA&use_mirror_status=on"
- elif [[ $c ]]; then
- m="https://www.archlinux.org/mirrorlist/?country=${c}&use_mirror_status=on"
+ ip_add="$(curl -fsSL "http://api.ipstack.com/check&?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=ip" |
+ python -c "import sys, json; print(json.load(sys.stdin)['ip'])")"
+
+ country="$(curl -fsSL "http://api.ipstack.com/${ip_add}?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=country_code" |
+ python -c "import sys, json; print(json.load(sys.stdin)['country_code'])")"
+
+ if [[ "$country" ]]; then
+ if [[ $country =~ (CA|US) ]]; then
+ mirror="https://www.archlinux.org/mirrorlist/?country=US&country=CA&use_mirror_status=on"
+ elif [[ $country =~ (AU|NZ) ]]; then
+ mirror="https://www.archlinux.org/mirrorlist/?country=AU&country=NZ&use_mirror_status=on"
+ else
+ mirror="https://www.archlinux.org/mirrorlist/?country=${country}&use_mirror_status=on"
+ fi
else
- m="https://www.archlinux.org/mirrorlist/?country=US&country=CA&country=NZ&country=GB&country=AU&use_mirror_status=on"
+ mirror="https://www.archlinux.org/mirrorlist/?country=all&use_mirror_status=on"
fi
- curl -s "$m" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -t -n 10 - | tail -n 10 >"$mfile"
+
+ curl -fsSL "$mirror" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 6 - >/etc/pacman.d/mirrorlist
fi
+
return 0
}
fi
}
-json()
-{
- curl -s "http://api.ipstack.com/$2" | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])"
-}
-
yesno()
{
local title="$1" body="$2" yes='Yes' no='No'