install-release.sh 3.1 KB

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