diff --git a/nt_install.sh b/nt_install.sh index 5fc7822..ab03dae 100644 --- a/nt_install.sh +++ b/nt_install.sh @@ -15,7 +15,43 @@ function red(){ checkRootPermit() { [[ $EUID -ne 0 ]] && red "请使用sudo/root权限运行本脚本" && exit 1 } - +ask_if() +{ + local choice="" + while [ "$choice" != "y" ] && [ "$choice" != "n" ] + do + echo -e "${Info} $1" + read choice + done + [ $choice == y ] && return 0 + return 1 +} +#检查脚本更新 +check_script_update() +{ + [ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh") | awk '{print $1}')" ] && return 1 || return 0 +} +#更新脚本 +update_script() +{ + if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then + echo -e "${Info} 脚本更新完成,正在重启脚本..." + exec bash ${BASH_SOURCE[0]} + else + echo -e "${Info} 更新脚本失败!" + exit 1 + fi +} +ask_update_script() +{ + if check_script_update; then + echo -e "${Info} 脚本可升级" + [[ $auto == True ]] && update_script + ask_if "是否升级脚本?(y/n)" && update_script + else + echo -e "${Info} 脚本已经是最新版本" + fi +} checkSystemArch() { arch=$(uname -m) case $arch in @@ -217,6 +253,7 @@ addCronTask() { # Check Procedure checkRootPermit +ask_update_script checkSystemDistribution checkSystemArch checkPackageManger