installer: use multiple geoip api to determine location (#393)
This commit is contained in:
parent
d8f4236404
commit
6005004681
@ -60,7 +60,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="ui icon green mini button"
|
<button class="ui icon green mini button"
|
||||||
data-clipboard-text="{{if $.Conf.GRPCHost}}{{if eq $.Conf.Language "zh-CN"}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh{{else}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh{{end}} -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh install_agent {{$.Conf.GRPCHost}} {{if $.Conf.ProxyGRPCPort}}{{$.Conf.ProxyGRPCPort}}{{else}}{{$.Conf.GRPCPort}}{{end}} {{$server.Secret}}{{if $.Conf.TLS}} --tls{{end}}{{else}}{{tr "NoDomainAlert"}}{{end}}"
|
data-clipboard-text="{{if $.Conf.GRPCHost}}{{if eq $.Conf.Language "zh-CN"}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh{{else}}curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install_en.sh{{end}} -o nezha.sh && chmod +x nezha.sh && ./nezha.sh install_agent {{$.Conf.GRPCHost}} {{if $.Conf.ProxyGRPCPort}}{{$.Conf.ProxyGRPCPort}}{{else}}{{$.Conf.GRPCPort}}{{end}} {{$server.Secret}}{{if $.Conf.TLS}} --tls{{end}}{{else}}{{tr "NoDomainAlert"}}{{end}}"
|
||||||
data-tooltip="{{tr "ClickToCopy"}}">
|
data-tooltip="{{tr "ClickToCopy"}}">
|
||||||
<i class="linux icon"></i>
|
<i class="linux icon"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@ -48,6 +48,19 @@ err() {
|
|||||||
printf "${red}$*${plain}\n" >&2
|
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() {
|
pre_check() {
|
||||||
## os_arch
|
## os_arch
|
||||||
if uname -m | grep -q 'x86_64'; then
|
if uname -m | grep -q 'x86_64'; then
|
||||||
@ -66,8 +79,9 @@ pre_check() {
|
|||||||
|
|
||||||
## China_IP
|
## China_IP
|
||||||
if [ -z "$CN" ]; then
|
if [ -z "$CN" ]; then
|
||||||
if curl -m 10 -s http://ip-api.com/json |grep 'country' |grep -q 'China'; then
|
geo_check
|
||||||
echo "根据ip-api.com提供的信息,当前IP可能在中国"
|
if [ ! -z "$isCN" ]; then
|
||||||
|
echo "根据geoip api提供的信息,当前IP可能在中国"
|
||||||
printf "是否选用中国镜像完成安装? [Y/n] (自定义镜像输入 3):"
|
printf "是否选用中国镜像完成安装? [Y/n] (自定义镜像输入 3):"
|
||||||
read -r input
|
read -r input
|
||||||
case $input in
|
case $input in
|
||||||
|
@ -48,6 +48,19 @@ err() {
|
|||||||
printf "${red}$*${plain}\n" >&2
|
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() {
|
pre_check() {
|
||||||
## os_arch
|
## os_arch
|
||||||
if uname -m | grep -q 'x86_64'; then
|
if uname -m | grep -q 'x86_64'; then
|
||||||
@ -66,8 +79,9 @@ pre_check() {
|
|||||||
|
|
||||||
## China_IP
|
## China_IP
|
||||||
if [ -z "$CN" ]; then
|
if [ -z "$CN" ]; then
|
||||||
if curl -m 10 -s http://ip-api.com/json |grep 'country' |grep -q 'China'; then
|
geo_check
|
||||||
echo "According to the information provided by ip-api.com, the current IP may be in China"
|
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): "
|
printf "Will the installation be done with a Chinese Mirror? [Y/n] (Custom Mirror Input 3): "
|
||||||
read -r input
|
read -r input
|
||||||
case $input in
|
case $input in
|
||||||
|
Loading…
Reference in New Issue
Block a user