Attempt to use a local mirror
And will fallback to global mirror list if ip.sb fails us or if we have no mirrors in that country.
This commit is contained in:
parent
0369983da6
commit
308142cf6f
1 changed files with 10 additions and 4 deletions
14
vps2arch
14
vps2arch
|
@ -25,9 +25,15 @@ else
|
|||
exit 2
|
||||
fi
|
||||
|
||||
get_worldwide_mirrors() {
|
||||
echo "http://mirrors.kernel.org/archlinux"
|
||||
_download 'https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4' | awk '/^## /{if ($2 == "Worldwide") { flag=1 } else { flag=0 } } /^#Server/ { if (flag) { sub(/\/\$repo.*/, ""); print $3 } }'
|
||||
get_country() {
|
||||
_download "https://api.ip.sb/geoip" | grep -oP '(?<=country_code":")\w+'
|
||||
}
|
||||
|
||||
get_mirrors() {
|
||||
country=$1
|
||||
|
||||
[ -z $country ] && country=$(get_country || echo -n "all")
|
||||
_download "https://www.archlinux.org/mirrorlist/?country=$country&protocol=http&protocol=https&ip_version=4&use_mirror_status=on" | grep -oP '(?<=#Server = ).*(?=\$repo/)' || get_mirrors all
|
||||
}
|
||||
|
||||
cpu_type=$(uname -m)
|
||||
|
@ -330,7 +336,7 @@ while getopts ":b:m:n:h" opt; do
|
|||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
[ -z "$mirrors" ] && mirrors=$(get_worldwide_mirrors)
|
||||
[ -z "$mirrors" ] && mirrors=$(get_mirrors)
|
||||
|
||||
|
||||
if is_openvz; then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue