install-release.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.6"
  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. curl -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
  29. unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/"
  30. # Create folder for V2Ray log.
  31. mkdir -p /var/log/v2ray
  32. # Install V2Ray binary to /usr/bin/v2ray
  33. mkdir -p /usr/bin/v2ray
  34. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/v2ray" "/usr/bin/v2ray/v2ray"
  35. chmod +x "/usr/bin/v2ray/v2ray"
  36. # Install V2Ray server config to /etc/v2ray
  37. mkdir -p /etc/v2ray
  38. if [ ! -f "/etc/v2ray/config.json" ]; then
  39. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
  40. let PORT=$RANDOM+10000
  41. sed -i "s/37192/${PORT}/g" "/etc/v2ray/config.json"
  42. UUID=$(cat /proc/sys/kernel/random/uuid)
  43. sed -i "s/3b129dec-72a3-4d28-aeee-028a0fe86e22/${UUID}/g" "/etc/v2ray/config.json"
  44. echo "PORT:${PORT}"
  45. echo "UUID:${UUID}"
  46. fi
  47. SYSTEMCTL_CMD=$(command -v systemctl)
  48. SERVICE_CMD=$(command -v service)
  49. if [ -n "${SYSTEMCTL_CMD}" ]; then
  50. if [ ! -f "/lib/systemd/system/v2ray.service" ]; then
  51. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemd/v2ray.service" "/lib/systemd/system/"
  52. systemctl enable v2ray
  53. fi
  54. elif [ -n "${SERVICE_CMD}" ]; then # Configure SysV if necessary.
  55. if [ ! -f "/etc/init.d/v2ray" ]; then
  56. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemv/v2ray" "/etc/init.d/v2ray"
  57. chmod +x "/etc/init.d/v2ray"
  58. update-rc.d v2ray defaults
  59. fi
  60. fi