#!/bin/bash cd "$(dirname "$0")" V2RAY_HOME=${V2RAY_HOME:-$(pwd)} V2RAY="$V2RAY_HOME/v2ray" if [[ -f "$V2RAY" ]] then CURRENT_VERSION=$("$V2RAY" -version | grep -Po "\b\d+\.\d+\.\d+\b") echo "Current version: v$CURRENT_VERSION" fi echo "Checking latest version..." LATEST_VERSION=$(curl -H "Accept: application/vnd.github.v3+json" \ -s "https://api.github.com/repos/v2fly/v2ray-core/releases/latest" | \ grep '"tag_name":' | \ sed -E 's/.*"([^"]+)".*/\1/') [[ -z "$LATEST_VERSION" ]] \ && { echo "Cannot check latest version, check your network." >&2; exit 1; } \ || echo "Lasest version found: $LATEST_VERSION" if [[ -n "$CURRENT_VERSION" && "$LATEST_VERSION" == "v$CURRENT_VERSION" ]] then echo "Already up-to-date." exit 0 fi declare -a file_list=( "v2ray-linux-64.zip" "v2ray-linux-64.zip.dgst" ) for file in "${file_list[@]}" do echo "Downloading $file..." curl -LO "https://github.com/v2fly/v2ray-core/releases/download/$LATEST_VERSION/$file" \ || { echo "Cannot download $file, check your network." >&2; exit 1; } done echo "Checking file integrity..." sha512sum "${file_list[0]}" | \ cut -d ' ' -f 1 | grep -f - -q "${file_list[1]}" \ || { echo "ERROR" >&2; exit 1; } echo "OK" echo "Extracting ${file_list[0]}..." unzip -o "${file_list[0]}" -x "*.sig" "*.json" "systemd/*" echo "Removing archive..." rm -fv "${file_list[@]}" echo "Upgrade complete!"