From 9b0e58359fa662f77bcfaa127aa977fde21f578d Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Tue, 31 May 2022 18:27:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=96=84=E8=84=9A=E6=9C=AC=E5=9C=A8?= =?UTF-8?q?=E5=9B=BD=E5=86=85=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84=E8=A1=A8?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nt_install.sh | 51 +++++++++++++++++++++++++------------------------- quicklytest.sh | 34 +++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/nt_install.sh b/nt_install.sh index fc93add..b8a382b 100644 --- a/nt_install.sh +++ b/nt_install.sh @@ -59,6 +59,32 @@ checkSystemDistribution() { esac } +getLocation() { + red "正在获取地理位置信息..." + countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode") + if [ "$countryCode" == "CN" ]; then + if [[ $auto == True ]]; then + URLprefix="https://ghproxy.com/" + else + read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input + case $input in + [yY][eE][sS] | [yY]) + URLprefix="https://ghproxy.com/" + ;; + + [nN][oO] | [nN]) + URLprefix="" + red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败" + ;; + + *) + URLprefix="https://ghproxy.com/" + ;; + esac + fi + fi +} + ask_if() { local choice="" red "${1}" @@ -96,31 +122,6 @@ ask_update_script() { fi } -getLocation() { - red "正在获取地理位置信息..." - countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode") - if [ "$countryCode" == "CN" ]; then - if [[ $auto == True ]]; then - URLprefix="https://ghproxy.com/" - else - read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input - case $input in - [yY][eE][sS] | [yY]) - URLprefix="https://ghproxy.com/" - ;; - - [nN][oO] | [nN]) - red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败" - ;; - - *) - URLprefix="https://ghproxy.com/" - ;; - esac - fi - fi -} - checkPackageManger() { if [[ ${osDistribution} == "darwin" ]]; then # brew update diff --git a/quicklytest.sh b/quicklytest.sh index 4f90ceb..b52529e 100644 --- a/quicklytest.sh +++ b/quicklytest.sh @@ -21,11 +21,36 @@ check_root() { checkNexttrace() { echo -e "${Info} 正在检查Nexttrace...(若未安装NextTrace则开始安装)" - if curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then + if curl -sL -O ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh" || curl -sL -O ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh"; then bash nt_install.sh #--auto #>/dev/null fi } +getLocation() { + red "正在获取地理位置信息..." + countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode") + if [ "$countryCode" == "CN" ]; then + if [[ $auto == True ]]; then + URLprefix="https://ghproxy.com/" + else + read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input + case $input in + [yY][eE][sS] | [yY]) + URLprefix="https://ghproxy.com/" + ;; + + [nN][oO] | [nN]) + red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败" + ;; + + *) + URLprefix="https://ghproxy.com/" + ;; + esac + fi + fi +} + ask_if() { local choice="" echo -e "${Info} $1" @@ -52,15 +77,15 @@ checkSystemDistribution() { #检查脚本更新 check_script_update() { if [[ ${osDistribution} == "darwin" ]]; then - [ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh" | md5)" ] && return 1 || return 0 + [ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh" | md5)" ] && return 1 || return 0 else - [ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh") | awk '{print $1}')" ] && return 1 || return 0 + [ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh") | awk '{print $1}')" ] && return 1 || return 0 fi } #更新脚本 update_script() { - if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh"; then + if curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh" || curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh"; then echo -e "${Info} quickylytest.sh更新完成,正在重启脚本..." exec bash "${BASH_SOURCE[0]}" else @@ -250,6 +275,7 @@ result_all() { check_root checkSystemDistribution +getLocation ask_update_script checkNexttrace check_mode