From 608847b1cb39bdd4edae6ebf0f77c156bfedfc91 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Wed, 25 May 2022 14:01:21 +0800 Subject: [PATCH] Implement update function --- nt_install.sh | 59 ++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/nt_install.sh b/nt_install.sh index e6889c6..cfe7ca1 100644 --- a/nt_install.sh +++ b/nt_install.sh @@ -190,6 +190,29 @@ checkWgetPackage() { fi } +checkJqPackage() { + jq -h &>/dev/null + if [ $? -ne 0 ]; then + read -r -p "您还没有安装jq,是否安装? (y/n)" input + + case $input in + [yY][eE][sS] | [yY]) + installJqPackage + ;; + + [nN][oO] | [nN]) + echo "您选择了取消安装,脚本即将退出" + exit 1 + ;; + + *) + installJqPackage + ;; + esac + fi + return 1 +} + checkVersion() { checkJqPackage echo "正在检查版本..." @@ -198,8 +221,14 @@ checkVersion() { echo "获取版本失败,请检查网络连接" exit 1 fi + currentVersion=$(nexttrace -V | head -n 1 | awk '{print $2}') + if [[ $currentVersion == $version ]]; then + echo "当前版本已是最新版本" + exit 0 + fi echo 当前最新release版本:${version} - read -r -p "是否安装/更新软件? (y/n)" input + echo 您当前的版本:${currentVersion} + read -r -p "是否更新软件? (y/n)" input case $input in [yY][eE][sS] | [yY]) break @@ -214,30 +243,6 @@ checkVersion() { esac } -checkJqPackage() { - jq -h &>/dev/null - if [ $? -ne 0 ]; then - echo "您还没有安装jq, 当您取消安装,我们会使用awk获取当前版本号。" - read -r -p "但是如遇Github变更API,这可能会存在问题,是否安装? (y/n)" input - - case $input in - [yY][eE][sS] | [yY]) - installJqPackage - ;; - - [nN][oO] | [nN]) - echo "您选择了取消安装" - return 0 - ;; - - *) - installJqPackage - ;; - esac - fi - return 1 -} - downloadBinrayFile() { echo "正在获取最新版的 NextTrace 发行版文件信息..." checkJqPackage @@ -298,8 +303,8 @@ checkRootPermit checkSystemDistribution checkSystemArch checkWgetPackage -# TODO: 检查版本并更新 -#checkVersion +checkJqPackage +checkVersion # Download Procedure getLocation