2024-06-25 10:15:49 -04:00
|
|
|
|
#!/bin/sh
|
2020-11-29 09:17:40 -05:00
|
|
|
|
|
2021-03-02 10:08:40 -05:00
|
|
|
|
#========================================================
|
2024-12-01 03:38:53 -05:00
|
|
|
|
# v0 分支脚本强制重定向至新仓库
|
2021-03-02 10:08:40 -05:00
|
|
|
|
#========================================================
|
2020-11-29 09:17:40 -05:00
|
|
|
|
|
2024-12-01 03:38:53 -05:00
|
|
|
|
# 判断是否应使用中国镜像
|
2024-06-25 10:15:49 -04:00
|
|
|
|
|
2024-07-19 18:48:53 -04:00
|
|
|
|
geo_check() {
|
2024-12-01 03:38:53 -05:00
|
|
|
|
api_list="https://blog.cloudflare.com/cdn-cgi/trace https://developers.cloudflare.com/cdn-cgi/trace"
|
2024-07-19 18:48:53 -04:00
|
|
|
|
ua="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
|
2024-10-19 10:03:00 -04:00
|
|
|
|
set -- "$api_list"
|
2024-07-19 18:48:53 -04:00
|
|
|
|
for url in $api_list; do
|
2024-10-19 10:03:00 -04:00
|
|
|
|
text="$(curl -A "$ua" -m 10 -s "$url")"
|
|
|
|
|
endpoint="$(echo "$text" | sed -n 's/.*h=\([^ ]*\).*/\1/p')"
|
|
|
|
|
if echo "$text" | grep -qw 'CN'; then
|
2024-07-19 18:48:53 -04:00
|
|
|
|
isCN=true
|
|
|
|
|
break
|
2024-10-19 10:03:00 -04:00
|
|
|
|
elif echo "$url" | grep -q "$endpoint"; then
|
2024-08-04 22:21:14 -04:00
|
|
|
|
break
|
2024-07-19 18:48:53 -04:00
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 03:38:53 -05:00
|
|
|
|
# 向用户确认是否使用中国镜像
|
|
|
|
|
geo_check
|
2023-11-13 03:10:09 -05:00
|
|
|
|
|
2024-12-01 03:38:53 -05:00
|
|
|
|
if [ "$isCN" = true ]; then
|
|
|
|
|
read -p "检测到您的IP可能来自中国大陆,是否使用中国镜像? [y/n] " choice
|
|
|
|
|
case "$choice" in
|
|
|
|
|
y|Y)
|
|
|
|
|
echo "将使用中国镜像..."
|
|
|
|
|
USE_CN_MIRROR=true
|
2023-11-29 20:39:00 -05:00
|
|
|
|
;;
|
2024-12-01 03:38:53 -05:00
|
|
|
|
n|N)
|
|
|
|
|
echo "将使用国际镜像..."
|
|
|
|
|
USE_CN_MIRROR=false
|
2023-11-29 20:39:00 -05:00
|
|
|
|
;;
|
2024-01-18 00:34:58 -05:00
|
|
|
|
*)
|
2024-12-01 03:38:53 -05:00
|
|
|
|
echo "输入无效,将使用国际镜像..."
|
|
|
|
|
USE_CN_MIRROR=false
|
2023-11-29 20:39:00 -05:00
|
|
|
|
;;
|
2024-03-29 23:08:29 -04:00
|
|
|
|
esac
|
2024-12-01 03:38:53 -05:00
|
|
|
|
else
|
|
|
|
|
USE_CN_MIRROR=false
|
|
|
|
|
fi
|
2020-11-29 09:17:40 -05:00
|
|
|
|
|
2024-12-01 03:38:53 -05:00
|
|
|
|
if [ "$USE_CN_MIRROR" = true ]; then
|
|
|
|
|
shell_url="https://gitee.com/naibahq/scripts/raw/v0/install.sh"
|
|
|
|
|
else
|
|
|
|
|
shell_url="https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/v0/install.sh"
|
|
|
|
|
fi
|
2020-11-29 09:17:40 -05:00
|
|
|
|
|
2024-12-01 03:38:53 -05:00
|
|
|
|
|
|
|
|
|
# 新地址 https://raw.githubusercontent.com/nezhahq/scripts/refs/heads/v0/install.sh
|
|
|
|
|
if command -v wget >/dev/null 2>&1; then
|
|
|
|
|
wget -O nezha_v0.sh "$shell_url"
|
|
|
|
|
elif command -v curl >/dev/null 2>&1; then
|
|
|
|
|
curl -o nezha_v0.sh "$shell_url"
|
2020-11-29 09:17:40 -05:00
|
|
|
|
else
|
2024-12-01 03:38:53 -05:00
|
|
|
|
echo "错误: 未找到 wget 或 curl,请安装其中任意一个后再试"
|
|
|
|
|
exit 1
|
2024-10-19 10:03:00 -04:00
|
|
|
|
fi
|
2024-12-01 03:38:53 -05:00
|
|
|
|
|
|
|
|
|
chmod +x nezha_v0.sh
|
|
|
|
|
|
|
|
|
|
# 携带原参数运行新脚本
|
|
|
|
|
exec ./nezha_v0.sh "$@"
|