检查版本功能更新

检查新版本时增加检测本地是否安装的情况
使用version参数时,不需要键入v,直接打版本号即可
pull/1037/head
sunshineplan 2018-04-12 10:53:05 +08:00
parent a06078ecb3
commit c56b55a7d3
1 changed files with 35 additions and 24 deletions

View File

@ -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(){ getVersion(){
if [[ -n "$VERSION" ]]; then if [[ -n "$VERSION" ]]; then
NEW_VER="$VERSION" NEW_VER="v$VERSION"
return 1 return 4
else 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" 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` NEW_VER=`curl ${PROXY} -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
colorEcho ${RED} "Network error! Please check your network or try again." 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 elif [[ "$NEW_VER" != "$CUR_VER" ]];then
return 1 return 1
fi fi
return 0 return 0
fi fi
@ -335,22 +338,26 @@ remove(){
} }
checkUpdate(){ checkUpdate(){
echo "Checking for update." echo "Checking for update."
getVersion VERSION=""
if [[ $? -eq 1 ]]; then getVersion
colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray." RETVAL="$?"
exit if [[ $RETVAL -eq 1 ]]; then
else colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
colorEcho ${GREEN} "No new version." elif [[ $RETVAL -eq 0 ]]; then
exit colorEcho ${GREEN} "No new version. Current version is ${NEW_VER}."
fi elif [[ $RETVAL -eq 2 ]]; then
colorEcho ${RED} "No V2Ray installed."
colorEcho ${GREEN} "The newest version for V2Ray is ${NEW_VER}."
fi
return 0
} }
main(){ main(){
#helping information #helping information
[[ "$HELP" == "1" ]] && Help [[ "$HELP" == "1" ]] && Help
[[ "$CHECK" == "1" ]] && checkUpdate
[[ "$REMOVE" == "1" ]] && remove [[ "$REMOVE" == "1" ]] && remove
[[ "$CHECK" == "1" ]] && checkUpdate && return
sysArch sysArch
# extract local file # extract local file
@ -374,15 +381,19 @@ main(){
# download via network and extract # download via network and extract
installSoftware "curl" installSoftware "curl"
getVersion getVersion
if [[ $? == 0 ]] && [[ "$FORCE" != "1" ]]; then RETVAL="$?"
if [[ $RETVAL == 0 ]] && [[ "$FORCE" != "1" ]]; then
colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed." colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed."
exit return
else elif [[ $RETVAL == 3 ]]; then
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" return 3
downloadV2Ray elif [[ $RETVAL == 1 ]]; then
installSoftware unzip colorEcho ${GREEN} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
extract ${ZIPFILE}
fi fi
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}"
downloadV2Ray || return $?
installSoftware unzip || return $?
extract ${ZIPFILE} || return $?
fi fi
if pgrep "v2ray" > /dev/null ; then if pgrep "v2ray" > /dev/null ; then
V2RAY_RUNNING=1 V2RAY_RUNNING=1