1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-30 15:56:28 -04:00

refactor: Extract normalizeVersion()

This commit is contained in:
xymopen 2020-01-07 23:21:34 +08:00 committed by kslr
parent 52917c3243
commit 4ae653e884

View File

@ -198,27 +198,33 @@ extract(){
return 0 return 0
} }
normalizeVersion() {
if [ -n "$1" ]; then
case "$1" in
v*)
echo "$1"
;;
*)
echo "v$1"
;;
esac
else
echo ""
fi
}
# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check. # 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="$(normalizeVersion "$VERSION")"
if [[ ${NEW_VER} != v* ]]; then
NEW_VER=v${NEW_VER}
fi
return 4 return 4
else else
VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null` VER="$(/usr/bin/v2ray/v2ray -version 2>/dev/null)"
RETVAL="$?" RETVAL=$?
CUR_VER=`echo $VER | head -n 1 | cut -d " " -f2` CUR_VER="$(normalizeVersion "$(echo "$VER" | head -n 1 | cut -d " " -f2)")"
if [[ ${CUR_VER} != v* ]]; then
CUR_VER=v${CUR_VER}
fi
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="$(normalizeVersion "$(curl ${PROXY} -s "${TAG_URL}" --connect-timeout 10| grep 'tag_name' | cut -d\" -f4)")"
if [[ ${NEW_VER} != v* ]]; then
NEW_VER=v${NEW_VER}
fi
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
colorEcho ${RED} "Failed to fetch release information. Please check your network or try again." colorEcho ${RED} "Failed to fetch release information. Please check your network or try again."
return 3 return 3