From 6005004681e000343a6563849316c91a684e11b2 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Sat, 20 Jul 2024 06:48:53 +0800 Subject: [PATCH] installer: use multiple geoip api to determine location (#393) --- .../template/dashboard-default/server.html | 2 +- script/install.sh | 18 ++++++++++++++++-- script/install_en.sh | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/resource/template/dashboard-default/server.html b/resource/template/dashboard-default/server.html index 04cc8b1..a219e13 100644 --- a/resource/template/dashboard-default/server.html +++ b/resource/template/dashboard-default/server.html @@ -60,7 +60,7 @@ diff --git a/script/install.sh b/script/install.sh index ccb7afc..95dbf63 100755 --- a/script/install.sh +++ b/script/install.sh @@ -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 "根据ip-api.com提供的信息,当前IP可能在中国" + geo_check + if [ ! -z "$isCN" ]; then + echo "根据geoip api提供的信息,当前IP可能在中国" printf "是否选用中国镜像完成安装? [Y/n] (自定义镜像输入 3):" read -r input case $input in diff --git a/script/install_en.sh b/script/install_en.sh index d802635..85456e4 100755 --- a/script/install_en.sh +++ b/script/install_en.sh @@ -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