installer: use multiple geoip api to determine location (#393)

This commit is contained in:
UUBulb
2024-07-20 06:48:53 +08:00
committed by GitHub
parent d8f4236404
commit 6005004681
3 changed files with 33 additions and 5 deletions

View File

@@ -48,6 +48,19 @@ err() {
printf "${red}$*${plain}\n" >&2
}
geo_check() {
api_list="http://api.myip.la/en?json https://api.ip.sb/geoip https://ipapi.co/json http://ip-api.com/json/"
ua="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
set -- $api_list
for url in $api_list; do
text="$(curl -A $ua -m 10 -s $url)"
if echo $text | grep -qw 'CN'; then
isCN=true
break
fi
done
}
pre_check() {
## os_arch
if uname -m | grep -q 'x86_64'; then
@@ -66,8 +79,9 @@ pre_check() {
## China_IP
if [ -z "$CN" ]; then
if curl -m 10 -s http://ip-api.com/json |grep 'country' |grep -q 'China'; then
echo "According to the information provided by ip-api.com, the current IP may be in China"
geo_check
if [ ! -z "$isCN" ]; then
echo "According to the information provided by various geoip api, the current IP may be in China"
printf "Will the installation be done with a Chinese Mirror? [Y/n] (Custom Mirror Input 3): "
read -r input
case $input in