Created
October 20, 2018 13:00
-
-
Save phoenixxie0/60cb2241d2e51e478ea85c21486930d1 to your computer and use it in GitHub Desktop.
v2ray-updare.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This file is accessible as https://install.direct/go.sh | |
# Original source is located at github.com/v2ray/v2ray-core/release/install-release.sh | |
CUR_VER="" | |
NEW_VER="" | |
ZIPFILE="/tmp/v2ray/v2ray.zip" | |
#######color code######## | |
RED="31m" | |
GREEN="32m" | |
YELLOW="33m" | |
BLUE="36m" | |
############################### | |
colorEcho(){ | |
COLOR=$1 | |
echo -e "\033[${COLOR}${@:2}\033[0m" | |
} | |
downloadV2Ray(){ | |
rm -rf /tmp/v2ray | |
mkdir -p /tmp/v2ray | |
colorEcho ${BLUE} "Downloading V2Ray." | |
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${NEW_VER}/v2ray-linux-64.zip" | |
curl ${PROXY} -L -H "Cache-Control: no-cache" -o ${ZIPFILE} ${DOWNLOAD_LINK} | |
if [ $? != 0 ];then | |
colorEcho ${RED} "Failed to download! Please check your network or try again." | |
exit 1 | |
fi | |
return 0 | |
} | |
extract(){ | |
colorEcho ${BLUE}"Extracting V2Ray package to /tmp/v2ray." | |
mkdir -p /tmp/v2ray | |
unzip $1 -d "/tmp/v2ray/" | |
if [[ $? -ne 0 ]]; then | |
colorEcho ${RED} "Extracting V2Ray failed!" | |
exit | |
fi | |
return 0 | |
} | |
# 1: new V2Ray. 0: no | |
getVersion(){ | |
if [[ -n "$VERSION" ]]; then | |
NEW_VER="$VERSION" | |
return 1 | |
else | |
CUR_VER=`/usr/bin/v2ray/v2ray -version 2>/dev/null | 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 | |
elif [[ "$NEW_VER" != "$CUR_VER" ]];then | |
return 1 | |
fi | |
return 0 | |
fi | |
} | |
copyFile() { | |
NAME=$1 | |
MANDATE=$2 | |
ERROR=`cp "/tmp/v2ray/${NAME}" "/opt/bin/v2ray/${NAME}" 2>&1` | |
if [[ $? -ne 0 ]]; then | |
colorEcho ${YELLOW} "${ERROR}" | |
if [ "$MANDATE" = true ]; then | |
exit | |
fi | |
fi | |
} | |
installV2Ray(){ | |
# Install V2Ray binary to /opt/bin/v2ray | |
mkdir -p /opt/bin/v2ray | |
copyFile v2ray true | |
makeExecutable v2ray | |
copyFile v2ctl false | |
makeExecutable v2ctl | |
copyFile geoip.dat false | |
copyFile geosite.dat false | |
} | |
makeExecutable() { | |
chmod +x "/opt/bin/v2ray/$1" | |
} | |
main(){ | |
# extract local file | |
if [[ $LOCAL_INSTALL -eq 1 ]]; then | |
echo "Install V2Ray via local file" | |
installSoftware unzip | |
rm -rf /tmp/v2ray | |
extract $LOCAL | |
FILEVDIS=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f4` | |
SYSTEM=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f3` | |
if [[ ${SYSTEM} != "linux" ]]; then | |
colorEcho $RED "The local V2Ray can not be installed in linux." | |
exit | |
elif [[ ${FILEVDIS} != ${VDIS} ]]; then | |
colorEcho $RED "The local V2Ray can not be installed in ${ARCH} system." | |
exit | |
else | |
NEW_VER=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f2` | |
fi | |
else | |
# download via network and extract | |
getVersion | |
if [[ $? == 0 ]] && [[ "$FORCE" != "1" ]]; then | |
colorEcho ${GREEN} "Latest version ${NEW_VER} is already installed." | |
exit | |
else | |
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" | |
downloadV2Ray | |
extract ${ZIPFILE} | |
fi | |
fi | |
supervisorctl stop v2-server | |
installV2Ray | |
colorEcho ${GREEN} "V2Ray ${NEW_VER} is installed." | |
rm -rf /tmp/v2ray | |
touch /opt/bin/v2ray/* | |
supervisorctl start v2-server | |
return 0 | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment