From c56b55a7d36bb2865b025d3f7e1b353a4344eca1 Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Thu, 12 Apr 2018 10:53:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 检查新版本时增加检测本地是否安装的情况 使用version参数时,不需要键入v,直接打版本号即可 --- release/install-release.sh | 59 ++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/release/install-release.sh b/release/install-release.sh index d67ed56b..47f930ef 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -156,21 +156,24 @@ extract(){ } -# 1: new V2Ray. 0: no +# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check. getVersion(){ if [[ -n "$VERSION" ]]; then - NEW_VER="$VERSION" - return 1 + NEW_VER="v$VERSION" + return 4 else - CUR_VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null | head -n 1 | cut -d " " -f2` + VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null` + RETVAL="$?" + CUR_VER=`echo $VER | head -n 1 | cut -d " " -f2` TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest" NEW_VER=`curl ${PROXY} -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4` - if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then colorEcho ${RED} "Network error! Please check your network or try again." - exit + return 3 + elif [[ $RETVAL -ne 0 ]];then + return 2 elif [[ "$NEW_VER" != "$CUR_VER" ]];then - return 1 + return 1 fi return 0 fi @@ -335,22 +338,26 @@ remove(){ } checkUpdate(){ - echo "Checking for update." - getVersion - if [[ $? -eq 1 ]]; then - colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray." - exit - else - colorEcho ${GREEN} "No new version." - exit - fi + echo "Checking for update." + VERSION="" + getVersion + RETVAL="$?" + if [[ $RETVAL -eq 1 ]]; then + colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)" + elif [[ $RETVAL -eq 0 ]]; then + colorEcho ${GREEN} "No new version. Current version is ${NEW_VER}." + elif [[ $RETVAL -eq 2 ]]; then + colorEcho ${RED} "No V2Ray installed." + colorEcho ${GREEN} "The newest version for V2Ray is ${NEW_VER}." + fi + return 0 } main(){ #helping information [[ "$HELP" == "1" ]] && Help - [[ "$CHECK" == "1" ]] && checkUpdate [[ "$REMOVE" == "1" ]] && remove + [[ "$CHECK" == "1" ]] && checkUpdate && return sysArch # extract local file @@ -374,15 +381,19 @@ main(){ # download via network and extract installSoftware "curl" getVersion - if [[ $? == 0 ]] && [[ "$FORCE" != "1" ]]; then + RETVAL="$?" + if [[ $RETVAL == 0 ]] && [[ "$FORCE" != "1" ]]; then colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed." - exit - else - colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" - downloadV2Ray - installSoftware unzip - extract ${ZIPFILE} + return + elif [[ $RETVAL == 3 ]]; then + return 3 + elif [[ $RETVAL == 1 ]]; then + colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)" fi + colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" + downloadV2Ray || return $? + installSoftware unzip || return $? + extract ${ZIPFILE} || return $? fi if pgrep "v2ray" > /dev/null ; then V2RAY_RUNNING=1 From 648b7e35f1e38927055595f6bf7b4129a8f87d6d Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Thu, 12 Apr 2018 15:41:35 +0800 Subject: [PATCH 2/5] Update install-release.sh --- release/install-release.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/release/install-release.sh b/release/install-release.sh index 47f930ef..b20536a5 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -389,11 +389,12 @@ main(){ return 3 elif [[ $RETVAL == 1 ]]; then colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)" + else + colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" + downloadV2Ray || return $? + installSoftware unzip || return $? + extract ${ZIPFILE} || return $? fi - colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" - downloadV2Ray || return $? - installSoftware unzip || return $? - extract ${ZIPFILE} || return $? fi if pgrep "v2ray" > /dev/null ; then V2RAY_RUNNING=1 From e154ff3dfdd558a74727f5f31f04d0cd99bfa023 Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Thu, 12 Apr 2018 15:45:46 +0800 Subject: [PATCH 3/5] Update install-release.sh --- release/install-release.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/release/install-release.sh b/release/install-release.sh index b20536a5..b462ca48 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -391,9 +391,9 @@ main(){ colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)" else colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" - downloadV2Ray || return $? - installSoftware unzip || return $? - extract ${ZIPFILE} || return $? + downloadV2Ray + installSoftware unzip + extract ${ZIPFILE} fi fi if pgrep "v2ray" > /dev/null ; then From 8f8e393e5fcb5e1a5c70ec6dd654d2802184a507 Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Thu, 12 Apr 2018 18:18:26 +0800 Subject: [PATCH 4/5] Update install-release.sh --- release/install-release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/install-release.sh b/release/install-release.sh index b462ca48..6eef9413 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -280,7 +280,7 @@ Help(){ echo " -h, --help Show help" echo " -p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc" echo " -f, --force Force install" - echo " --version Install a particular version" + echo " --version Install a particular version, use --version 3.15" echo " -l, --local Install from a local file" echo " --remove Remove installed V2Ray" echo " -c, --check Check for update" From 90ad6bb121ac80a7ea957f4df5d1fdc8548bceba Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Thu, 12 Apr 2018 19:00:13 +0800 Subject: [PATCH 5/5] Update install-release.sh --- release/install-release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release/install-release.sh b/release/install-release.sh index 6eef9413..cbd83cb4 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -159,7 +159,7 @@ extract(){ # 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check. getVersion(){ if [[ -n "$VERSION" ]]; then - NEW_VER="v$VERSION" + NEW_VER="$VERSION" return 4 else VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null` @@ -280,7 +280,7 @@ Help(){ echo " -h, --help Show help" echo " -p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc" echo " -f, --force Force install" - echo " --version Install a particular version, use --version 3.15" + echo " --version Install a particular version, use --version v3.15" echo " -l, --local Install from a local file" echo " --remove Remove installed V2Ray" echo " -c, --check Check for update"