install-release.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. YUM_CMD=$(command -v yum)
  3. APT_CMD=$(command -v apt-get)
  4. if [ -n "${YUM_CMD}" ]; then
  5. echo "Installing unzip and daemon via yum."
  6. ${YUM_CMD} -q makecache
  7. ${YUM_CMD} -y -q install unzip daemon
  8. elif [ -n "${APT_CMD}" ]; then
  9. echo "Installing unzip and daemon via apt-get."
  10. ${APT_CMD} -qq update
  11. ${APT_CMD} -y -qq install unzip daemon
  12. else
  13. echo "Please make sure unzip and daemon are installed."
  14. fi
  15. VER="v1.7"
  16. ARCH=$(uname -m)
  17. VDIS="64"
  18. if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]]; then
  19. VDIS="32"
  20. elif [[ "$ARCH" == *"armv7"* ]]; then
  21. VDIS="arm"
  22. elif [[ "$ARCH" == *"armv8"* ]]; then
  23. VDIS="arm64"
  24. fi
  25. DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${VER}/v2ray-linux-${VDIS}.zip"
  26. rm -rf /tmp/v2ray
  27. mkdir -p /tmp/v2ray
  28. # Download release with proxy or not
  29. echo 'Direct start downloading release,'
  30. echo 'Or Enter a proxy URI for Downloading release.'
  31. echo 'ex: socks5://127.0.0.1:1080'
  32. echo 'ex: http://127.0.0.1:3128'
  33. read PROXY_URI
  34. if [ -n "${PROXY_URI}" ]; then
  35. curl -x ${PROXY_URI} -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
  36. else
  37. curl -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
  38. fi
  39. unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/"
  40. # Create folder for V2Ray log.
  41. mkdir -p /var/log/v2ray
  42. # Stop v2ray daemon if necessary.
  43. SYSTEMCTL_CMD=$(command -v systemctl)
  44. SERVICE_CMD=$(command -v service)
  45. ISRUN_CMD=$(ps x | grep -c v2ray)
  46. if [ ${ISRUN_CMD} -eq 2 ]; then
  47. if [ -n "${SYSTEMCTL_CMD}" ]; then
  48. if [ -f "/lib/systemd/system/v2ray.service" ]; then
  49. systemctl stop v2ray
  50. fi
  51. elif [ -n "${SERVICE_CMD}" ]; then
  52. if [ -f "/etc/init.d/v2ray" ]; then
  53. service v2ray stop
  54. fi
  55. fi
  56. fi
  57. # Install V2Ray binary to /usr/bin/v2ray
  58. mkdir -p /usr/bin/v2ray
  59. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/v2ray" "/usr/bin/v2ray/v2ray"
  60. chmod +x "/usr/bin/v2ray/v2ray"
  61. # Install V2Ray server config to /etc/v2ray
  62. mkdir -p /etc/v2ray
  63. if [ ! -f "/etc/v2ray/config.json" ]; then
  64. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
  65. let PORT=$RANDOM+10000
  66. sed -i "s/37192/${PORT}/g" "/etc/v2ray/config.json"
  67. UUID=$(cat /proc/sys/kernel/random/uuid)
  68. sed -i "s/3b129dec-72a3-4d28-aeee-028a0fe86e22/${UUID}/g" "/etc/v2ray/config.json"
  69. echo "PORT:${PORT}"
  70. echo "UUID:${UUID}"
  71. fi
  72. if [ -n "${SYSTEMCTL_CMD}" ]; then
  73. if [ ! -f "/lib/systemd/system/v2ray.service" ]; then
  74. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemd/v2ray.service" "/lib/systemd/system/"
  75. systemctl enable v2ray
  76. else
  77. if [ ${ISRUN_CMD} -eq 2 ]; then
  78. systemctl start v2ray
  79. fi
  80. fi
  81. elif [ -n "${SERVICE_CMD}" ]; then # Configure SysV if necessary.
  82. if [ ! -f "/etc/init.d/v2ray" ]; then
  83. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemv/v2ray" "/etc/init.d/v2ray"
  84. chmod +x "/etc/init.d/v2ray"
  85. update-rc.d v2ray defaults
  86. else
  87. if [ ${ISRUN_CMD} -eq 2 ]; then
  88. service v2ray start
  89. fi
  90. fi
  91. fi