Merge remote-tracking branch 'upstream/develop' into HEAD
commit
bc77ec4255
|
@ -13,10 +13,10 @@
|
||||||
# https://github.com/v2fly/fhs-install-v2ray/issues
|
# https://github.com/v2fly/fhs-install-v2ray/issues
|
||||||
|
|
||||||
# If you modify the following variables, you also need to modify the unit file yourself:
|
# If you modify the following variables, you also need to modify the unit file yourself:
|
||||||
# You can modify it to /usr/local/lib/v2ray/
|
# You can modify it to /usr/local/lib/v2ray
|
||||||
DAT_PATH='/usr/local/share/v2ray/'
|
DAT_PATH='/usr/local/share/v2ray'
|
||||||
# You can modify it to /etc/v2ray/
|
# You can modify it to /etc/v2ray
|
||||||
JSON_PATH='/usr/local/etc/v2ray/'
|
JSON_PATH='/usr/local/etc/v2ray'
|
||||||
|
|
||||||
check_if_running_as_root() {
|
check_if_running_as_root() {
|
||||||
# If you want to run as another user, please modify $UID to be owned by this user
|
# If you want to run as another user, please modify $UID to be owned by this user
|
||||||
|
@ -41,7 +41,7 @@ identify_the_operating_system_and_architecture() {
|
||||||
'armv6l')
|
'armv6l')
|
||||||
MACHINE='arm32-v6'
|
MACHINE='arm32-v6'
|
||||||
;;
|
;;
|
||||||
'armv7' | 'armv7l' )
|
'armv7' | 'armv7l')
|
||||||
MACHINE='arm32-v7a'
|
MACHINE='arm32-v7a'
|
||||||
;;
|
;;
|
||||||
'armv8' | 'aarch64')
|
'armv8' | 'aarch64')
|
||||||
|
@ -107,8 +107,9 @@ identify_the_operating_system_and_architecture() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Demo function for processing parameters
|
||||||
judgment_parameters() {
|
judgment_parameters() {
|
||||||
if [[ "$#" -gt '0' ]]; then
|
while [[ "$#" -gt '0' ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'--remove')
|
'--remove')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
if [[ "$#" -gt '1' ]]; then
|
||||||
|
@ -118,111 +119,52 @@ judgment_parameters() {
|
||||||
REMOVE='1'
|
REMOVE='1'
|
||||||
;;
|
;;
|
||||||
'--version')
|
'--version')
|
||||||
if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
|
VERSION="${2:?error: Please specify the correct version.}"
|
||||||
echo 'error: Please specify the correct version.'
|
break
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION="$2"
|
|
||||||
;;
|
;;
|
||||||
'-c' | '--check')
|
'-c' | '--check')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CHECK='1'
|
CHECK='1'
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-f' | '--force')
|
'-f' | '--force')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
FORCE='1'
|
FORCE='1'
|
||||||
;;
|
break
|
||||||
|
;;
|
||||||
'-h' | '--help')
|
'-h' | '--help')
|
||||||
if [[ "$#" -gt '1' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
HELP='1'
|
HELP='1'
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-l' | '--local')
|
'-l' | '--local')
|
||||||
if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
|
|
||||||
echo 'error: Please specify the correct local file.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
LOCAL_FILE="$2"
|
|
||||||
LOCAL_INSTALL='1'
|
LOCAL_INSTALL='1'
|
||||||
|
LOCAL_FILE="${2:?error: Please specify the correct local file.}"
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
'-p' | '--proxy')
|
'-p' | '--proxy')
|
||||||
case "$2" in
|
if echo "${2:?undefine var}" | grep -qEo '^(https?|socks4a?|socks5h?):\/\/'; then
|
||||||
'http://'*)
|
echo 'error: Please specify the correct proxy server address.'
|
||||||
;;
|
exit 1
|
||||||
'https://'*)
|
|
||||||
;;
|
|
||||||
'socks4://'*)
|
|
||||||
;;
|
|
||||||
'socks4a://'*)
|
|
||||||
;;
|
|
||||||
'socks5://'*)
|
|
||||||
;;
|
|
||||||
'socks5h://'*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo 'error: Please specify the correct proxy server address.'
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
PROXY="-x$2"
|
|
||||||
# Parameters available through a proxy server
|
|
||||||
if [[ "$#" -gt '2' ]]; then
|
|
||||||
case "$3" in
|
|
||||||
'--version')
|
|
||||||
if [[ "$#" -gt '4' ]] || [[ -z "$4" ]]; then
|
|
||||||
echo 'error: Please specify the correct version.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION="$2"
|
|
||||||
;;
|
|
||||||
'-c' | '--check')
|
|
||||||
if [[ "$#" -gt '3' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CHECK='1'
|
|
||||||
;;
|
|
||||||
'-f' | '--force')
|
|
||||||
if [[ "$#" -gt '3' ]]; then
|
|
||||||
echo 'error: Please enter the correct parameters.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
FORCE='1'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "$0: unknown option -- -"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
PROXY="-x$2"
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$0: unknown option -- -"
|
echo "$0: unknown option -- -"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
shift
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
install_software() {
|
install_software() {
|
||||||
COMPONENT="$1"
|
COMPONENT="$1"
|
||||||
if [[ -n "$(command -v "$COMPONENT")" ]]; then
|
command -v "$COMPONENT" > /dev/null 2>&1 && return
|
||||||
return
|
if ${PACKAGE_MANAGEMENT_INSTALL} "$COMPONENT"; then
|
||||||
fi
|
echo "info: $COMPONENT is installed."
|
||||||
${PACKAGE_MANAGEMENT_INSTALL} "$COMPONENT"
|
else
|
||||||
if [[ "$?" -ne '0' ]]; then
|
|
||||||
echo "error: Installation of $COMPONENT failed, please check your network."
|
echo "error: Installation of $COMPONENT failed, please check your network."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "info: $COMPONENT is installed."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version_number() {
|
version_number() {
|
||||||
|
@ -240,66 +182,64 @@ get_version() {
|
||||||
# 0: Install or update V2Ray.
|
# 0: Install or update V2Ray.
|
||||||
# 1: Installed or no new version of V2Ray.
|
# 1: Installed or no new version of V2Ray.
|
||||||
# 2: Install the specified version of V2Ray.
|
# 2: Install the specified version of V2Ray.
|
||||||
if [[ -z "$VERSION" ]]; then
|
if [[ -n "$VERSION" ]]; then
|
||||||
# Determine the version number for V2Ray installed from a local file
|
RELEASE_VERSION="$(version_number "$VERSION")"
|
||||||
if [[ -f '/usr/local/bin/v2ray' ]]; then
|
return 2
|
||||||
VERSION="$(/usr/local/bin/v2ray -version)"
|
fi
|
||||||
CURRENT_VERSION="$(version_number $(echo "$VERSION" | head -n 1 | awk -F ' ' '{print $2}'))"
|
# Determine the version number for V2Ray installed from a local file
|
||||||
if [[ "$LOCAL_INSTALL" -eq '1' ]]; then
|
if [[ -f '/usr/local/bin/v2ray' ]]; then
|
||||||
RELEASE_VERSION="$CURRENT_VERSION"
|
VERSION="$(/usr/local/bin/v2ray -version)"
|
||||||
return
|
CURRENT_VERSION="$(version_number "$(echo "$VERSION" | awk 'NR==1 {print $2}')")"
|
||||||
fi
|
if [[ "$LOCAL_INSTALL" -eq '1' ]]; then
|
||||||
|
RELEASE_VERSION="$CURRENT_VERSION"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
# Get V2Ray release version number
|
fi
|
||||||
TMP_FILE="$(mktemp)"
|
# Get V2Ray release version number
|
||||||
install_software curl
|
TMP_FILE="$(mktemp)"
|
||||||
# DO NOT QUOTE THESE `${PROXY}` VARIABLES!
|
install_software curl
|
||||||
if ! "curl" ${PROXY} -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then
|
# DO NOT QUOTE THESE `${PROXY}` VARIABLES!
|
||||||
"rm" "$TMP_FILE"
|
if ! "curl" ${PROXY} -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then
|
||||||
echo 'error: Failed to get release list, please check your network.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')"
|
|
||||||
"rm" "$TMP_FILE"
|
"rm" "$TMP_FILE"
|
||||||
RELEASE_VERSION="$(version_number "$RELEASE_LATEST")"
|
echo 'error: Failed to get release list, please check your network.'
|
||||||
# Compare V2Ray version numbers
|
exit 1
|
||||||
if [[ "$RELEASE_VERSION" != "$CURRENT_VERSION" ]]; then
|
fi
|
||||||
RELEASE_VERSIONSION_NUMBER="${RELEASE_VERSION#v}"
|
RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')"
|
||||||
RELEASE_MAJOR_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER%%.*}"
|
"rm" "$TMP_FILE"
|
||||||
RELEASE_MINOR_VERSION_NUMBER="$(echo "$RELEASE_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')"
|
RELEASE_VERSION="$(version_number "$RELEASE_LATEST")"
|
||||||
RELEASE_MINIMUM_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER##*.}"
|
# Compare V2Ray version numbers
|
||||||
CURRENT_VERSIONSION_NUMBER="$(echo "${CURRENT_VERSION#v}" | sed 's/-.*//')"
|
if [[ "$RELEASE_VERSION" != "$CURRENT_VERSION" ]]; then
|
||||||
CURRENT_MAJOR_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER%%.*}"
|
RELEASE_VERSIONSION_NUMBER="${RELEASE_VERSION#v}"
|
||||||
CURRENT_MINOR_VERSION_NUMBER="$(echo "$CURRENT_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')"
|
RELEASE_MAJOR_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER%%.*}"
|
||||||
CURRENT_MINIMUM_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER##*.}"
|
RELEASE_MINOR_VERSION_NUMBER="$(echo "$RELEASE_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')"
|
||||||
if [[ "$RELEASE_MAJOR_VERSION_NUMBER" -gt "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
|
RELEASE_MINIMUM_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER##*.}"
|
||||||
|
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_MINIMUM_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER##*.}"
|
||||||
|
if [[ "$RELEASE_MAJOR_VERSION_NUMBER" -gt "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ "$RELEASE_MAJOR_VERSION_NUMBER" -eq "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
|
||||||
|
if [[ "$RELEASE_MINOR_VERSION_NUMBER" -gt "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ "$RELEASE_MAJOR_VERSION_NUMBER" -eq "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
|
elif [[ "$RELEASE_MINOR_VERSION_NUMBER" -eq "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
|
||||||
if [[ "$RELEASE_MINOR_VERSION_NUMBER" -gt "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
|
if [[ "$RELEASE_MINIMUM_VERSION_NUMBER" -gt "$CURRENT_MINIMUM_VERSION_NUMBER" ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ "$RELEASE_MINOR_VERSION_NUMBER" -eq "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
|
|
||||||
if [[ "$RELEASE_MINIMUM_VERSION_NUMBER" -gt "$CURRENT_MINIMUM_VERSION_NUMBER" ]]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
elif [[ "$RELEASE_VERSION" == "$CURRENT_VERSION" ]]; then
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
elif [[ "$RELEASE_VERSION" == "$CURRENT_VERSION" ]]; then
|
||||||
RELEASE_VERSION="$(version_number "$VERSION")"
|
return 1
|
||||||
return 2
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
download_v2ray() {
|
download_v2ray() {
|
||||||
"mkdir" -p "$TMP_DIRECTORY"
|
|
||||||
DOWNLOAD_LINK="https://github.com/v2fly/v2ray-core/releases/download/$RELEASE_VERSION/v2ray-linux-$MACHINE.zip"
|
DOWNLOAD_LINK="https://github.com/v2fly/v2ray-core/releases/download/$RELEASE_VERSION/v2ray-linux-$MACHINE.zip"
|
||||||
echo "Downloading V2Ray archive: $DOWNLOAD_LINK"
|
echo "Downloading V2Ray archive: $DOWNLOAD_LINK"
|
||||||
if ! "curl" ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then
|
if ! "curl" ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then
|
||||||
|
@ -342,7 +282,7 @@ install_file() {
|
||||||
if [[ "$NAME" == 'v2ray' ]] || [[ "$NAME" == 'v2ctl' ]]; then
|
if [[ "$NAME" == 'v2ray' ]] || [[ "$NAME" == 'v2ctl' ]]; then
|
||||||
install -m 755 "${TMP_DIRECTORY}/$NAME" "/usr/local/bin/$NAME"
|
install -m 755 "${TMP_DIRECTORY}/$NAME" "/usr/local/bin/$NAME"
|
||||||
elif [[ "$NAME" == 'geoip.dat' ]] || [[ "$NAME" == 'geosite.dat' ]]; then
|
elif [[ "$NAME" == 'geoip.dat' ]] || [[ "$NAME" == 'geosite.dat' ]]; then
|
||||||
install -m 644 "${TMP_DIRECTORY}/$NAME" "${DAT_PATH}$NAME"
|
install -m 644 "${TMP_DIRECTORY}/$NAME" "${DAT_PATH}/$NAME"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +292,7 @@ install_v2ray() {
|
||||||
install_file v2ctl
|
install_file v2ctl
|
||||||
install -d "$DAT_PATH"
|
install -d "$DAT_PATH"
|
||||||
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
# If the file exists, geoip.dat and geosite.dat will not be installed or updated
|
||||||
if [[ ! -f "${DAT_PATH}.undat" ]]; then
|
if [[ ! -f "${DAT_PATH}/.undat" ]]; then
|
||||||
install_file geoip.dat
|
install_file geoip.dat
|
||||||
install_file geosite.dat
|
install_file geosite.dat
|
||||||
fi
|
fi
|
||||||
|
@ -360,7 +300,7 @@ install_v2ray() {
|
||||||
# Install V2Ray configuration file to $JSON_PATH
|
# Install V2Ray configuration file to $JSON_PATH
|
||||||
if [[ ! -d "$JSON_PATH" ]]; then
|
if [[ ! -d "$JSON_PATH" ]]; then
|
||||||
install -d "$JSON_PATH"
|
install -d "$JSON_PATH"
|
||||||
echo "{}" > "${JSON_PATH}config.json"
|
echo "{}" > "${JSON_PATH}/config.json"
|
||||||
CONFIG_NEW='1'
|
CONFIG_NEW='1'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -388,17 +328,13 @@ install_startup_service_file() {
|
||||||
|
|
||||||
start_v2ray() {
|
start_v2ray() {
|
||||||
if [[ -f '/etc/systemd/system/v2ray.service' ]]; then
|
if [[ -f '/etc/systemd/system/v2ray.service' ]]; then
|
||||||
if [[ -z "$V2RAY_CUSTOMIZE" ]]; then
|
if systemctl start "${V2RAY_CUSTOMIZE:-v2ray}"; then
|
||||||
systemctl start v2ray
|
echo 'info: Start the V2Ray service.'
|
||||||
else
|
else
|
||||||
systemctl start "$V2RAY_CUSTOMIZE"
|
echo 'error: Failed to start V2Ray service.'
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
echo 'error: Failed to start V2Ray service.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo 'info: Start the V2Ray service.'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_v2ray() {
|
stop_v2ray() {
|
||||||
|
@ -488,7 +424,7 @@ main() {
|
||||||
[[ "$REMOVE" -eq '1' ]] && remove_v2ray
|
[[ "$REMOVE" -eq '1' ]] && remove_v2ray
|
||||||
|
|
||||||
# Two very important variables
|
# Two very important variables
|
||||||
TMP_DIRECTORY="$(mktemp -du)"
|
TMP_DIRECTORY="$(mktemp -d)"
|
||||||
ZIP_FILE="${TMP_DIRECTORY}/v2ray-linux-$MACHINE.zip"
|
ZIP_FILE="${TMP_DIRECTORY}/v2ray-linux-$MACHINE.zip"
|
||||||
|
|
||||||
# Install V2Ray from a local file, but still need to make sure the network is available
|
# Install V2Ray from a local file, but still need to make sure the network is available
|
||||||
|
@ -497,7 +433,6 @@ main() {
|
||||||
echo -n 'warn: Please make sure the file is valid because we cannot confirm it. (Press any key) ...'
|
echo -n 'warn: Please make sure the file is valid because we cannot confirm it. (Press any key) ...'
|
||||||
read
|
read
|
||||||
install_software unzip
|
install_software unzip
|
||||||
"mkdir" -p "$TMP_DIRECTORY"
|
|
||||||
decompression "$LOCAL_FILE"
|
decompression "$LOCAL_FILE"
|
||||||
else
|
else
|
||||||
# Normal way
|
# Normal way
|
||||||
|
@ -531,9 +466,9 @@ main() {
|
||||||
echo 'installed: /usr/local/bin/v2ray'
|
echo 'installed: /usr/local/bin/v2ray'
|
||||||
echo 'installed: /usr/local/bin/v2ctl'
|
echo 'installed: /usr/local/bin/v2ctl'
|
||||||
# If the file exists, the content output of installing or updating geoip.dat and geosite.dat will not be displayed
|
# If the file exists, the content output of installing or updating geoip.dat and geosite.dat will not be displayed
|
||||||
if [[ ! -f "${DAT_PATH}.undat" ]]; then
|
if [[ ! -f "${DAT_PATH}/.undat" ]]; then
|
||||||
echo "installed: ${DAT_PATH}geoip.dat"
|
echo "installed: ${DAT_PATH}/geoip.dat"
|
||||||
echo "installed: ${DAT_PATH}geosite.dat"
|
echo "installed: ${DAT_PATH}/geosite.dat"
|
||||||
fi
|
fi
|
||||||
if [[ "$CONFIG_NEW" -eq '1' ]]; then
|
if [[ "$CONFIG_NEW" -eq '1' ]]; then
|
||||||
echo "installed: ${JSON_PATH}config.json"
|
echo "installed: ${JSON_PATH}config.json"
|
||||||
|
|
Loading…
Reference in New Issue