imKobz

v2ray

May 25th, 2021 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 21.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # The files installed by the script conform to the Filesystem Hierarchy Standard:
  4. # https://wiki.linuxfoundation.org/lsb/fhs
  5.  
  6. # The URL of the script project is:
  7. # https://github.com/v2fly/fhs-install-v2ray
  8.  
  9. # The URL of the script is:
  10. # https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
  11.  
  12. # If the script executes incorrectly, go to:
  13. # https://github.com/v2fly/fhs-install-v2ray/issues
  14.  
  15. # If you modify the following variables, you also need to modify the unit file yourself:
  16. # You can modify it to /usr/local/lib/v2ray/
  17. DAT_PATH='/usr/local/lib/v2ray/'
  18. # You can modify it to /etc/v2ray/
  19. JSON_PATH='/etc/v2ray/'
  20.  
  21. check_if_running_as_root() {
  22.     # If you want to run as another user, please modify $UID to be owned by this user
  23.     if [[ "$UID" -ne '0' ]]; then
  24.         echo "error: You must run this script as root!"
  25.         exit 1
  26.     fi
  27. }
  28.  
  29. identify_the_operating_system_and_architecture() {
  30.     if [[ "$(uname)" == 'Linux' ]]; then
  31.         case "$(uname -m)" in
  32.             'i386' | 'i686')
  33.                 MACHINE='32'
  34.                 ;;
  35.             'amd64' | 'x86_64')
  36.                 MACHINE='64'
  37.                 ;;
  38.             'armv5tel')
  39.                 MACHINE='arm32-v5'
  40.                 ;;
  41.             'armv6l')
  42.                 MACHINE='arm32-v6'
  43.                 ;;
  44.             'armv7' | 'armv7l' )
  45.                 MACHINE='arm32-v7a'
  46.                 ;;
  47.             'armv8' | 'aarch64')
  48.                 MACHINE='arm64-v8a'
  49.                 ;;
  50.             'mips')
  51.                 MACHINE='mips32'
  52.                 ;;
  53.             'mipsle')
  54.                 MACHINE='mips32le'
  55.                 ;;
  56.             'mips64')
  57.                 MACHINE='mips64'
  58.                 ;;
  59.             'mips64le')
  60.                 MACHINE='mips64le'
  61.                 ;;
  62.             'ppc64')
  63.                 MACHINE='ppc64'
  64.                 ;;
  65.             'ppc64le')
  66.                 MACHINE='ppc64le'
  67.                 ;;
  68.             'riscv64')
  69.                 MACHINE='riscv64'
  70.                 ;;
  71.             's390x')
  72.                 MACHINE='s390x'
  73.                 ;;
  74.             *)
  75.                 echo "error: The architecture is not supported."
  76.                 exit 1
  77.                 ;;
  78.         esac
  79.         if [[ ! -f '/etc/os-release' ]]; then
  80.             echo "error: Don't use outdated Linux distributions."
  81.             exit 1
  82.         fi
  83.         if [[ -z "$(ls -l /sbin/init | grep systemd)" ]]; then
  84.             echo "error: Only Linux distributions using systemd are supported."
  85.             exit 1
  86.         fi
  87.         if [[ "$(command -v apt)" ]]; then
  88.             PACKAGE_MANAGEMENT_INSTALL='apt install'
  89.             PACKAGE_MANAGEMENT_REMOVE='apt remove'
  90.         elif [[ "$(command -v yum)" ]]; then
  91.             PACKAGE_MANAGEMENT_INSTALL='yum install'
  92.             PACKAGE_MANAGEMENT_REMOVE='yum remove'
  93.             if [[ "$(command -v dnf)" ]]; then
  94.                 PACKAGE_MANAGEMENT_INSTALL='dnf install'
  95.                 PACKAGE_MANAGEMENT_REMOVE='dnf remove'
  96.             fi
  97.         elif [[ "$(command -v zypper)" ]]; then
  98.             PACKAGE_MANAGEMENT_INSTALL='zypper install'
  99.             PACKAGE_MANAGEMENT_REMOVE='zypper remove'
  100.         else
  101.             echo "error: The script does not support the package manager in this operating system."
  102.             exit 1
  103.         fi
  104.     else
  105.         echo "error: This operating system is not supported."
  106.         exit 1
  107.     fi
  108. }
  109.  
  110. judgment_parameters() {
  111.     if [[ "$#" -gt '0' ]]; then
  112.         case "$1" in
  113.             '--remove')
  114.                 if [[ "$#" -gt '1' ]]; then
  115.                     echo 'error: Please enter the correct parameters.'
  116.                     exit 1
  117.                 fi
  118.                 REMOVE='1'
  119.                 ;;
  120.             '--version')
  121.                 if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
  122.                     echo 'error: Please specify the correct version.'
  123.                     exit 1
  124.                 fi
  125.                 VERSION="$2"
  126.                 ;;
  127.             '-c' | '--check')
  128.                 if [[ "$#" -gt '1' ]]; then
  129.                     echo 'error: Please enter the correct parameters.'
  130.                     exit 1
  131.                 fi
  132.                 CHECK='1'
  133.                 ;;
  134.             '-f' | '--force')
  135.                 if [[ "$#" -gt '1' ]]; then
  136.                     echo 'error: Please enter the correct parameters.'
  137.                     exit 1
  138.                 fi
  139.                 FORCE='1'
  140.                 ;;
  141.             '-h' | '--help')
  142.                 if [[ "$#" -gt '1' ]]; then
  143.                     echo 'error: Please enter the correct parameters.'
  144.                     exit 1
  145.                 fi
  146.                 HELP='1'
  147.                 ;;
  148.             '-l' | '--local')
  149.                 if [[ "$#" -gt '2' ]] || [[ -z "$2" ]]; then
  150.                     echo 'error: Please specify the correct local file.'
  151.                     exit 1
  152.                 fi
  153.                 LOCAL_FILE="$2"
  154.                 LOCAL_INSTALL='1'
  155.                 ;;
  156.             '-p' | '--proxy')
  157.                 case "$2" in
  158.                     'http://'*)
  159.                         ;;
  160.                     'https://'*)
  161.                         ;;
  162.                     'socks4://'*)
  163.                         ;;
  164.                     'socks4a://'*)
  165.                         ;;
  166.                     'socks5://'*)
  167.                         ;;
  168.                     'socks5h://'*)
  169.                         ;;
  170.                     *)
  171.                         echo 'error: Please specify the correct proxy server address.'
  172.                         exit 1
  173.                         ;;
  174.                 esac
  175.                 PROXY="-x$2"
  176.                 # Parameters available through a proxy server
  177.                 if [[ "$#" -gt '2' ]]; then
  178.                     case "$3" in
  179.                         '--version')
  180.                             if [[ "$#" -gt '4' ]] || [[ -z "$4" ]]; then
  181.                                 echo 'error: Please specify the correct version.'
  182.                                 exit 1
  183.                             fi
  184.                             VERSION="$2"
  185.                             ;;
  186.                         '-c' | '--check')
  187.                             if [[ "$#" -gt '3' ]]; then
  188.                                 echo 'error: Please enter the correct parameters.'
  189.                                 exit 1
  190.                             fi
  191.                             CHECK='1'
  192.                             ;;
  193.                         '-f' | '--force')
  194.                             if [[ "$#" -gt '3' ]]; then
  195.                                 echo 'error: Please enter the correct parameters.'
  196.                                 exit 1
  197.                             fi
  198.                             FORCE='1'
  199.                             ;;
  200.                         *)
  201.                             echo "$0: unknown option -- -"
  202.                             exit 1
  203.                             ;;
  204.                     esac
  205.                 fi
  206.                 ;;
  207.             *)
  208.                 echo "$0: unknown option -- -"
  209.                 exit 1
  210.                 ;;
  211.         esac
  212.     fi
  213. }
  214.  
  215. install_software() {
  216.     COMPONENT="$1"
  217.     if [[ -n "$(command -v "$COMPONENT")" ]]; then
  218.         return
  219.     fi
  220.     ${PACKAGE_MANAGEMENT_INSTALL} "$COMPONENT"
  221.     if [[ "$?" -ne '0' ]]; then
  222.         echo "error: Installation of $COMPONENT failed, please check your network."
  223.         exit 1
  224.     fi
  225.     echo "info: $COMPONENT is installed."
  226. }
  227.  
  228. version_number() {
  229.     case "$1" in
  230.         'v'*)
  231.             echo "$1"
  232.             ;;
  233.         *)
  234.             echo "v$1"
  235.             ;;
  236.     esac
  237. }
  238.  
  239. get_version() {
  240.     # 0: Install or update V2Ray.
  241.     # 1: Installed or no new version of V2Ray.
  242.     # 2: Install the specified version of V2Ray.
  243.     if [[ -z "$VERSION" ]]; then
  244.         # Determine the version number for V2Ray installed from a local file
  245.         if [[ -f '/usr/local/bin/v2ray' ]]; then
  246.             VERSION="$(/usr/local/bin/v2ray -version)"
  247.             CURRENT_VERSION="$(version_number $(echo "$VERSION" | head -n 1 | awk -F ' ' '{print $2}'))"
  248.             if [[ "$LOCAL_INSTALL" -eq '1' ]]; then
  249.                 RELEASE_VERSION="$CURRENT_VERSION"
  250.                 return
  251.             fi
  252.         fi
  253.         # Get V2Ray release version number
  254.         TMP_FILE="$(mktemp)"
  255.         install_software curl
  256.         # DO NOT QUOTE THESE `${PROXY}` VARIABLES!
  257.         if ! curl ${PROXY} -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then
  258.             rm "$TMP_FILE"
  259.             echo 'error: Failed to get release list, please check your network.'
  260.             exit 1
  261.         fi
  262.         RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')"
  263.         rm "$TMP_FILE"
  264.         RELEASE_VERSION="$(version_number "$RELEASE_LATEST")"
  265.         # Compare V2Ray version numbers
  266.         if [[ "$RELEASE_VERSION" != "$CURRENT_VERSION" ]]; then
  267.             RELEASE_VERSIONSION_NUMBER="${RELEASE_VERSION#v}"
  268.             RELEASE_MAJOR_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER%%.*}"
  269.             RELEASE_MINOR_VERSION_NUMBER="$(echo "$RELEASE_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')"
  270.             RELEASE_MINIMUM_VERSION_NUMBER="${RELEASE_VERSIONSION_NUMBER##*.}"
  271.             CURRENT_VERSIONSION_NUMBER="$(echo "${CURRENT_VERSION#v}" | sed 's/-.*//')"
  272.             CURRENT_MAJOR_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER%%.*}"
  273.             CURRENT_MINOR_VERSION_NUMBER="$(echo "$CURRENT_VERSIONSION_NUMBER" | awk -F '.' '{print $2}')"
  274.             CURRENT_MINIMUM_VERSION_NUMBER="${CURRENT_VERSIONSION_NUMBER##*.}"
  275.             if [[ "$RELEASE_MAJOR_VERSION_NUMBER" -gt "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
  276.                 return 0
  277.             elif [[ "$RELEASE_MAJOR_VERSION_NUMBER" -eq "$CURRENT_MAJOR_VERSION_NUMBER" ]]; then
  278.                 if [[ "$RELEASE_MINOR_VERSION_NUMBER" -gt "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
  279.                     return 0
  280.                 elif [[ "$RELEASE_MINOR_VERSION_NUMBER" -eq "$CURRENT_MINOR_VERSION_NUMBER" ]]; then
  281.                     if [[ "$RELEASE_MINIMUM_VERSION_NUMBER" -gt "$CURRENT_MINIMUM_VERSION_NUMBER" ]]; then
  282.                         return 0
  283.                     else
  284.                         return 1
  285.                     fi
  286.                 else
  287.                     return 1
  288.                 fi
  289.             else
  290.                 return 1
  291.             fi
  292.         elif [[ "$RELEASE_VERSION" == "$CURRENT_VERSION" ]]; then
  293.             return 1
  294.         fi
  295.     else
  296.         RELEASE_VERSION="$(version_number "$VERSION")"
  297.         return 2
  298.     fi
  299. }
  300.  
  301. download_v2ray() {
  302.     mkdir "$TMP_DIRECTORY"
  303.     DOWNLOAD_LINK="https://github.com/v2fly/v2ray-core/releases/download/$RELEASE_VERSION/v2ray-linux-$MACHINE.zip"
  304.     echo "Downloading V2Ray archive: $DOWNLOAD_LINK"
  305.     if ! curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then
  306.         echo 'error: Download failed! Please check your network or try again.'
  307.         return 1
  308.     fi
  309.     echo "Downloading verification file for V2Ray archive: $DOWNLOAD_LINK.dgst"
  310.     if ! curl ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst"; then
  311.         echo 'error: Download failed! Please check your network or try again.'
  312.         return 1
  313.     fi
  314.     if [[ "$(cat "$ZIP_FILE".dgst)" == 'Not Found' ]]; then
  315.         echo 'error: This version does not support verification. Please replace with another version.'
  316.         return 1
  317.     fi
  318.  
  319.     # Verification of V2Ray archive
  320.     for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do
  321.         SUM="$(${LISTSUM}sum "$ZIP_FILE" | sed 's/ .*//')"
  322.         CHECKSUM="$(grep ${LISTSUM^^} "$ZIP_FILE".dgst | grep "$SUM" -o -a | uniq)"
  323.         if [[ "$SUM" != "$CHECKSUM" ]]; then
  324.             echo 'error: Check failed! Please check your network or try again.'
  325.             return 1
  326.         fi
  327.     done
  328. }
  329.  
  330. decompression() {
  331.     if ! unzip -q "$1" -d "$TMP_DIRECTORY"; then
  332.         echo 'error: V2Ray decompression failed.'
  333.         rm -r "$TMP_DIRECTORY"
  334.         echo "removed: $TMP_DIRECTORY"
  335.         exit 1
  336.     fi
  337.     echo "info: Extract the V2Ray package to $TMP_DIRECTORY and prepare it for installation."
  338. }
  339.  
  340. install_file() {
  341.     NAME="$1"
  342.     if [[ "$NAME" == 'v2ray' ]] || [[ "$NAME" == 'v2ctl' ]]; then
  343.         install -m 755 "${TMP_DIRECTORY}$NAME" "/usr/local/bin/$NAME"
  344.     elif [[ "$NAME" == 'geoip.dat' ]] || [[ "$NAME" == 'geosite.dat' ]]; then
  345.         install -m 644 "${TMP_DIRECTORY}$NAME" "${DAT_PATH}$NAME"
  346.     fi
  347. }
  348.  
  349. install_v2ray() {
  350.     # Install V2Ray binary to /usr/local/bin/ and $DAT_PATH
  351.     install_file v2ray
  352.     install_file v2ctl
  353.     install -d "$DAT_PATH"
  354.     # If the file exists, geoip.dat and geosite.dat will not be installed or updated
  355.     if [[ ! -f "${DAT_PATH}.undat" ]]; then
  356.         install_file geoip.dat
  357.         install_file geosite.dat
  358.     fi
  359.  
  360.     # Install V2Ray configuration file to $JSON_PATH
  361.     if [[ ! -d "$JSON_PATH" ]]; then
  362.         install -d "$JSON_PATH"
  363.         echo "{}" > "${JSON_PATH}config.json"
  364.         CONFIG_NEW='1'
  365.     fi
  366.  
  367.     # Used to store V2Ray log files
  368.     if [[ ! -d '/var/log/v2ray/' ]]; then
  369.         if [[ -n "$(id nobody | grep nogroup)" ]]; then
  370.             install -d -m 755 -o root -g root /var/log/v2ray/
  371.             install -m 644 -o root -g root /dev/null /var/log/v2ray/access.log
  372.             install -m 644 -o root -g root /dev/null /var/log/v2ray/error.log
  373.         else
  374.             install -d -m 755 -o root -g root /var/log/v2ray/
  375.             install -m 644 -o root -g root /dev/null /var/log/v2ray/access.log
  376.             install -m 644 -o root -g root /dev/null /var/log/v2ray/error.log
  377.         fi
  378.         LOG='1'
  379.     fi
  380. }
  381.  
  382. install_startup_service_file() {
  383.     if [[ ! -f '/etc/systemd/system/v2ray.service' ]]; then
  384.         mkdir "${TMP_DIRECTORY}systemd/system/"
  385.         install_software curl
  386.         cat > "${TMP_DIRECTORY}systemd/system/v2ray.service" <<-EOF
  387. [Unit]
  388. Description=V2Ray Service
  389. After=network.target nss-lookup.target
  390.  
  391. [Service]
  392. User=root
  393. CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  394. AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  395. NoNewPrivileges=true
  396. Environment=V2RAY_LOCATION_ASSET=/usr/local/lib/v2ray/
  397. ExecStart=/usr/local/bin/v2ray -config /etc/v2ray/config.json
  398. Restart=on-failure
  399.  
  400. [Install]
  401. WantedBy=multi-user.target
  402. EOF
  403.         cat > "${TMP_DIRECTORY}systemd/system/v2ray@.service" <<-EOF
  404. [Unit]
  405. Description=V2Ray Service
  406. After=network.target nss-lookup.target
  407.  
  408. [Service]
  409. User=root
  410. CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  411. AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  412. NoNewPrivileges=true
  413. Environment=V2RAY_LOCATION_ASSET=/usr/local/lib/v2ray/
  414. ExecStart=/usr/local/bin/v2ray -config /etc/v2ray/%i.json
  415. Restart=on-failure
  416.  
  417. [Install]
  418. WantedBy=multi-user.target
  419. EOF
  420.         install -m 644 "${TMP_DIRECTORY}systemd/system/v2ray.service" /etc/systemd/system/v2ray.service
  421.         install -m 644 "${TMP_DIRECTORY}systemd/system/v2ray@.service" /etc/systemd/system/v2ray@.service
  422.         SYSTEMD='1'
  423.     fi
  424. }
  425.  
  426. start_v2ray() {
  427.     if [[ -f '/etc/systemd/system/v2ray.service' ]]; then
  428.         if [[ -z "$V2RAY_CUSTOMIZE" ]]; then
  429.             systemctl start v2ray
  430.         else
  431.             systemctl start "$V2RAY_CUSTOMIZE"
  432.         fi
  433.     fi
  434.     if [[ "$?" -ne 0 ]]; then
  435.         echo 'error: Failed to start V2Ray service.'
  436.         exit 1
  437.     fi
  438.     echo 'info: Start the V2Ray service.'
  439. }
  440.  
  441. stop_v2ray() {
  442.     V2RAY_CUSTOMIZE="$(systemctl list-units | grep 'v2ray@' | awk -F ' ' '{print $1}')"
  443.     if [[ -z "$V2RAY_CUSTOMIZE" ]]; then
  444.         systemctl stop v2ray
  445.     else
  446.         systemctl stop "$V2RAY_CUSTOMIZE"
  447.     fi
  448.     if [[ "$?" -ne '0' ]]; then
  449.         echo 'error: Stopping the V2Ray service failed.'
  450.         exit 1
  451.     fi
  452.     echo 'info: Stop the V2Ray service.'
  453. }
  454.  
  455. check_update() {
  456.     if [[ -f '/etc/systemd/system/v2ray.service' ]]; then
  457.         get_version
  458.         if [[ "$?" -eq '0' ]]; then
  459.             echo "info: Found the latest release of V2Ray $RELEASE_VERSION . (Current release: $CURRENT_VERSION)"
  460.         elif [[ "$?" -eq '1' ]]; then
  461.             echo "info: No new version. The current version of V2Ray is $CURRENT_VERSION ."
  462.         fi
  463.         exit 0
  464.     else
  465.         echo 'error: V2Ray is not installed.'
  466.         exit 1
  467.     fi
  468. }
  469.  
  470. remove_v2ray() {
  471.     if [[ -n "$(systemctl list-unit-files | grep 'v2ray')" ]]; then
  472.         if [[ -n "$(pidof v2ray)" ]]; then
  473.             stop_v2ray
  474.         fi
  475.         NAME="$1"
  476.         rm /usr/local/bin/v2ray
  477.         rm /usr/local/bin/v2ctl
  478.         rm -r "$DAT_PATH"
  479.         rm /etc/systemd/system/v2ray.service
  480.         rm /etc/systemd/system/v2ray@.service
  481.         if [[ "$?" -ne '0' ]]; then
  482.             echo 'error: Failed to remove V2Ray.'
  483.             exit 1
  484.         else
  485.             echo 'removed: /usr/local/bin/v2ray'
  486.             echo 'removed: /usr/local/bin/v2ctl'
  487.             echo "removed: $DAT_PATH"
  488.             echo 'removed: /etc/systemd/system/v2ray.service'
  489.             echo 'removed: /etc/systemd/system/v2ray@.service'
  490.             echo 'Please execute the command: systemctl disable v2ray'
  491.             echo "You may need to execute a command to remove dependent software: $PACKAGE_MANAGEMENT_REMOVE curl unzip"
  492.             echo 'info: V2Ray has been removed.'
  493.             echo 'info: If necessary, manually delete the configuration and log files.'
  494.             echo "info: e.g., $JSON_PATH and /var/log/v2ray/ ..."
  495.             exit 0
  496.         fi
  497.     else
  498.         echo 'error: V2Ray is not installed.'
  499.         exit 1
  500.     fi
  501. }
  502.  
  503. # Explanation of parameters in the script
  504. show_help() {
  505.     echo "usage: $0 [--remove | --version number | -c | -f | -h | -l | -p]"
  506.     echo '  [-p address] [--version number | -c | -f]'
  507.     echo '  --remove        Remove V2Ray'
  508.     echo '  --version       Install the specified version of V2Ray, e.g., --version v4.18.0'
  509.     echo '  -c, --check     Check if V2Ray can be updated'
  510.     echo '  -f, --force     Force installation of the latest version of V2Ray'
  511.     echo '  -h, --help      Show help'
  512.     echo '  -l, --local     Install V2Ray from a local file'
  513.     echo '  -p, --proxy     Download through a proxy server, e.g., -p http://127.0.0.1:8118 or -p socks5://127.0.0.1:1080'
  514.     exit 0
  515. }
  516.  
  517. main() {
  518.     check_if_running_as_root
  519.     identify_the_operating_system_and_architecture
  520.     judgment_parameters "$@"
  521.  
  522.     # Parameter information
  523.     [[ "$HELP" -eq '1' ]] && show_help
  524.     [[ "$CHECK" -eq '1' ]] && check_update
  525.     [[ "$REMOVE" -eq '1' ]] && remove_v2ray
  526.  
  527.     # Two very important variables
  528.     TMP_DIRECTORY="$(mktemp -du)/"
  529.     ZIP_FILE="${TMP_DIRECTORY}v2ray-linux-$MACHINE.zip"
  530.  
  531.     # Install V2Ray from a local file, but still need to make sure the network is available
  532.     if [[ "$LOCAL_INSTALL" -eq '1' ]]; then
  533.         echo 'warn: Install V2Ray from a local file, but still need to make sure the network is available.'
  534.         echo -n 'warn: Please make sure the file is valid because we cannot confirm it. (Press any key) ...'
  535.         read
  536.         install_software unzip
  537.         mkdir "$TMP_DIRECTORY"
  538.         decompression "$LOCAL_FILE"
  539.     else
  540.         # Normal way
  541.         get_version
  542.         NUMBER="$?"
  543.         if [[ "$NUMBER" -eq '0' ]] || [[ "$FORCE" -eq '1' ]] || [[ "$NUMBER" -eq 2 ]]; then
  544.             echo "info: Installing V2Ray $RELEASE_VERSION for $(uname -m)"
  545.             download_v2ray
  546.             if [[ "$?" -eq '1' ]]; then
  547.                 rm -r "$TMP_DIRECTORY"
  548.                 echo "removed: $TMP_DIRECTORY"
  549.                 exit 0
  550.             fi
  551.             install_software unzip
  552.             decompression "$ZIP_FILE"
  553.         elif [[ "$NUMBER" -eq '1' ]]; then
  554.             echo "info: No new version. The current version of V2Ray is $CURRENT_VERSION ."
  555.             exit 0
  556.         fi
  557.     fi
  558.  
  559.     # Determine if V2Ray is running
  560.     if [[ -n "$(systemctl list-unit-files | grep 'v2ray')" ]]; then
  561.         if [[ -n "$(pidof v2ray)" ]]; then
  562.             stop_v2ray
  563.             V2RAY_RUNNING='1'
  564.         fi
  565.     fi
  566.     install_v2ray
  567.     install_startup_service_file
  568.     echo 'installed: /usr/local/bin/v2ray'
  569.     echo 'installed: /usr/local/bin/v2ctl'
  570.     # If the file exists, the content output of installing or updating geoip.dat and geosite.dat will not be displayed
  571.     if [[ ! -f "${DAT_PATH}.undat" ]]; then
  572.         echo "installed: ${DAT_PATH}geoip.dat"
  573.         echo "installed: ${DAT_PATH}geosite.dat"
  574.     fi
  575.     if [[ "$CONFIG_NEW" -eq '1' ]]; then
  576.         echo "installed: ${JSON_PATH}config.json"
  577.     fi
  578.     if [[ "$CONFDIR" -eq '1' ]]; then
  579.         echo "installed: ${JSON_PATH}00_log.json"
  580.         echo "installed: ${JSON_PATH}01_api.json"
  581.         echo "installed: ${JSON_PATH}02_dns.json"
  582.         echo "installed: ${JSON_PATH}03_routing.json"
  583.         echo "installed: ${JSON_PATH}04_policy.json"
  584.         echo "installed: ${JSON_PATH}05_inbounds.json"
  585.         echo "installed: ${JSON_PATH}06_outbounds.json"
  586.         echo "installed: ${JSON_PATH}07_transport.json"
  587.         echo "installed: ${JSON_PATH}08_stats.json"
  588.         echo "installed: ${JSON_PATH}09_reverse.json"
  589.     fi
  590.     if [[ "$LOG" -eq '1' ]]; then
  591.         echo 'installed: /var/log/v2ray/'
  592.         echo 'installed: /var/log/v2ray/access.log'
  593.         echo 'installed: /var/log/v2ray/error.log'
  594.     fi
  595.     if [[ "$SYSTEMD" -eq '1' ]]; then
  596.         echo 'installed: /etc/systemd/system/v2ray.service'
  597.         echo 'installed: /etc/systemd/system/v2ray@.service'
  598.     fi
  599.     rm -r "$TMP_DIRECTORY"
  600.     echo "removed: $TMP_DIRECTORY"
  601.     if [[ "$LOCAL_INSTALL" -eq '1' ]]; then
  602.         get_version
  603.     fi
  604.     echo "info: V2Ray $RELEASE_VERSION is installed."
  605.     echo "You may need to execute a command to remove dependent software: $PACKAGE_MANAGEMENT_REMOVE curl unzip"
  606.     if [[ "$V2RAY_RUNNING" -eq '1' ]]; then
  607.         start_v2ray
  608.     else
  609.         echo 'Please execute the command: systemctl enable v2ray; systemctl start v2ray'
  610.     fi
  611. }
  612.  
  613. main "$@"
Add Comment
Please, Sign In to add comment