Update nt_install.sh

增加检查脚本更新功能
This commit is contained in:
tsosunchia
2022-05-26 21:28:12 +08:00
committed by GitHub
parent 97c4387af4
commit cfc1dfdfe5

View File

@@ -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