-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from v2fly/master
Up to date from Origin
- Loading branch information
Showing
2 changed files
with
22 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ judgment_parameters() { | |
exit 1 | ||
;; | ||
esac | ||
PROXY="-x $2" | ||
PROXY="-x$2" | ||
# Parameters available through a proxy server | ||
if [[ "$#" -gt '2' ]]; then | ||
case "$3" in | ||
|
@@ -199,7 +199,7 @@ judgment_parameters() { | |
|
||
install_software() { | ||
COMPONENT="$1" | ||
if [[ -n "$(command -v $COMPONENT)" ]]; then | ||
if [[ -n "$(command -v "$COMPONENT")" ]]; then | ||
return | ||
fi | ||
${PACKAGE_MANAGEMENT_INSTALL} "$COMPONENT" | ||
|
@@ -229,7 +229,7 @@ get_version() { | |
# Determine the version number for V2Ray installed from a local file | ||
if [[ -f '/usr/local/bin/v2ray' ]]; then | ||
VERSION="$(/usr/local/bin/v2ray -version)" | ||
CURRENT_VERSION="$(version_number $(echo $VERSION | head -n 1 | awk -F ' ' '{print $2}'))" | ||
CURRENT_VERSION="$(version_number $(echo "$VERSION" | head -n 1 | awk -F ' ' '{print $2}'))" | ||
if [[ "$LOCAL_INSTALL" -eq '1' ]]; then | ||
RELEASE_VERSION="$CURRENT_VERSION" | ||
return | ||
|
@@ -238,24 +238,23 @@ get_version() { | |
# Get V2Ray release version number | ||
TMP_FILE="$(mktemp)" | ||
install_software curl | ||
curl ${PROXY} -o "$TMP_FILE" https://api.github.com/repos/v2fly/v2ray-core/releases/latest -s | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! curl ${PROXY} -s -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then | ||
rm "$TMP_FILE" | ||
echo 'error: Failed to get release list, please check your network.' | ||
exit 1 | ||
fi | ||
RELEASE_LATEST="$(cat $TMP_FILE | sed 'y/,/\n/' | grep 'tag_name' | awk -F '"' '{print $4}')" | ||
RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')" | ||
rm "$TMP_FILE" | ||
RELEASE_VERSION="$(version_number $RELEASE_LATEST)" | ||
RELEASE_VERSION="$(version_number "$RELEASE_LATEST")" | ||
# Compare V2Ray version numbers | ||
if [[ "$RELEASE_VERSION" != "$CURRENT_VERSION" ]]; then | ||
RELEASE_VERSIONSION_NUMBER="${RELEASE_VERSION#v}" | ||
RELEASE_MAJOR_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER%%.*}" | ||
RELEASE_MINOR_VERSION_NUMBER="$(echo $RELEASE_VERSIONSION_NUMBER | awk -F '.' '{print $2}')" | ||
RELEASE_MINOR_VERSION_NUMBER="$(echo "$RELEASE_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')" | ||
RELEASE_MINIMUM_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER##*.}" | ||
CURRENT_VERSIONSION_NUMBER="$(echo ${CURRENT_VERSION#v} | sed 's/-.*//')" | ||
CURRENT_VERSIONSION_NUMBER="$(echo "${CURRENT_VERSION#v}" | sed 's/-.*//')" | ||
CURRENT_MAJOR_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER%%.*}" | ||
CURRENT_MINOR_VERSION_NUMBER="$(echo $CURRENT_VERSIONSION_NUMBER | awk -F '.' '{print $2}')" | ||
CURRENT_MINOR_VERSION_NUMBER="$(echo "$CURRENT_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')" | ||
CURRENT_MINIMUM_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER##*.}" | ||
if [[ "$RELEASE_MAJOR_VERSION_NUMBER" -gt "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then | ||
return 0 | ||
|
@@ -278,7 +277,7 @@ get_version() { | |
return 1 | ||
fi | ||
else | ||
RELEASE_VERSION="$(version_number $VERSION)" | ||
RELEASE_VERSION="$(version_number "$VERSION")" | ||
return 2 | ||
fi | ||
} | ||
|
@@ -287,26 +286,24 @@ download_v2ray() { | |
mkdir "$TMP_DIRECTORY" | ||
DOWNLOAD_LINK="https://github.com/v2fly/v2ray-core/releases/download/$RELEASE_VERSION/v2ray-linux-$MACHINE.zip" | ||
echo "Downloading V2Ray archive: $DOWNLOAD_LINK" | ||
curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK" | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then | ||
echo 'error: Download failed! Please check your network or try again.' | ||
return 1 | ||
fi | ||
echo "Downloading verification file for V2Ray archive: $DOWNLOAD_LINK.dgst" | ||
curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst" | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst"; then | ||
echo 'error: Download failed! Please check your network or try again.' | ||
return 1 | ||
fi | ||
if [[ "$(cat $ZIP_FILE.dgst)" == 'Not Found' ]]; then | ||
if [[ "$(cat "$ZIP_FILE".dgst)" == 'Not Found' ]]; then | ||
echo 'error: This version does not support verification. Please replace with another version.' | ||
return 1 | ||
fi | ||
|
||
# Verification of V2Ray archive | ||
for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do | ||
SUM="$(${LISTSUM}sum $ZIP_FILE | sed 's/ .*//')" | ||
CHECKSUM="$(grep ${LISTSUM^^} $ZIP_FILE.dgst | grep $SUM -o -a | uniq)" | ||
SUM="$(${LISTSUM}sum "$ZIP_FILE" | sed 's/ .*//')" | ||
CHECKSUM="$(grep ${LISTSUM^^} "$ZIP_FILE".dgst | grep "$SUM" -o -a | uniq)" | ||
if [[ "$SUM" != "$CHECKSUM" ]]; then | ||
echo 'error: Check failed! Please check your network or try again.' | ||
return 1 | ||
|
@@ -315,8 +312,7 @@ download_v2ray() { | |
} | ||
|
||
decompression() { | ||
unzip -q "$1" -d "$TMP_DIRECTORY" | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! unzip -q "$1" -d "$TMP_DIRECTORY"; then | ||
echo 'error: V2Ray decompression failed.' | ||
rm -r "$TMP_DIRECTORY" | ||
echo "removed: $TMP_DIRECTORY" | ||
|
@@ -366,13 +362,11 @@ install_startup_service_file() { | |
if [[ ! -f '/etc/systemd/system/v2ray.service' ]]; then | ||
mkdir "${TMP_DIRECTORY}systemd/system/" | ||
install_software curl | ||
curl ${PROXY} -o "${TMP_DIRECTORY}systemd/system/v2ray.service" https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/v2ray.service -s | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! curl ${PROXY} -s -o "${TMP_DIRECTORY}systemd/system/v2ray.service" 'https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/v2ray.service'; then | ||
echo 'error: Failed to start service file download! Please check your network or try again.' | ||
exit 1 | ||
fi | ||
curl ${PROXY} -o "${TMP_DIRECTORY}systemd/system/[email protected]" https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/[email protected] -s | ||
if [[ "$?" -ne '0' ]]; then | ||
if ! curl ${PROXY} -s -o "${TMP_DIRECTORY}systemd/system/[email protected]" 'https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/[email protected]'; then | ||
echo 'error: Failed to start service file download! Please check your network or try again.' | ||
exit 1 | ||
fi | ||
|