install-release.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. SOFTWARE_UPDATED=0
  28. function update_software() {
  29. if [ ${SOFTWARE_UPDATED} -eq 1 ]; then
  30. return
  31. fi
  32. if [ -n "${YUM_CMD}" ]; then
  33. echo "Updating software repo via yum."
  34. ${YUM_CMD} -q makecache
  35. elif [ -n "${APT_CMD}" ]; then
  36. echo "Updating software repo via apt-get."
  37. ${APT_CMD} -qq update
  38. fi
  39. SOFTWARE_UPDATED=1
  40. }
  41. function install_component() {
  42. update_software
  43. local COMPONENT=$1
  44. if [ -n "${YUM_CMD}" ]; then
  45. echo "Installing ${COMPONENT} via yum."
  46. ${YUM_CMD} -y -q install $COMPONENT
  47. elif [ -n "${APT_CMD}" ]; then
  48. echo "Installing ${COMPONENT} via apt-get."
  49. ${APT_CMD} -y -qq install $COMPONENT
  50. fi
  51. }
  52. VER="v1.7"
  53. ARCH=$(uname -m)
  54. VDIS="64"
  55. if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]]; then
  56. VDIS="32"
  57. elif [[ "$ARCH" == *"armv7"* ]]; then
  58. VDIS="arm"
  59. elif [[ "$ARCH" == *"armv8"* ]]; then
  60. VDIS="arm64"
  61. fi
  62. DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${VER}/v2ray-linux-${VDIS}.zip"
  63. rm -rf /tmp/v2ray
  64. mkdir -p /tmp/v2ray
  65. install_component "curl"
  66. install_component "unzip"
  67. if [ -n "${PROXY}" ]; then
  68. curl -x ${PROXY} -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
  69. else
  70. curl -L -o "/tmp/v2ray/v2ray.zip" ${DOWNLOAD_LINK}
  71. fi
  72. unzip "/tmp/v2ray/v2ray.zip" -d "/tmp/v2ray/"
  73. # Create folder for V2Ray log.
  74. mkdir -p /var/log/v2ray
  75. # Stop v2ray daemon if necessary.
  76. SYSTEMCTL_CMD=$(command -v systemctl)
  77. SERVICE_CMD=$(command -v service)
  78. ISRUN_CMD=$(ps x | grep -c v2ray)
  79. if [ ${ISRUN_CMD} -eq 2 ]; then
  80. if [ -n "${SYSTEMCTL_CMD}" ]; then
  81. if [ -f "/lib/systemd/system/v2ray.service" ]; then
  82. systemctl stop v2ray
  83. fi
  84. elif [ -n "${SERVICE_CMD}" ]; then
  85. if [ -f "/etc/init.d/v2ray" ]; then
  86. service v2ray stop
  87. fi
  88. fi
  89. fi
  90. # Install V2Ray binary to /usr/bin/v2ray
  91. mkdir -p /usr/bin/v2ray
  92. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/v2ray" "/usr/bin/v2ray/v2ray"
  93. chmod +x "/usr/bin/v2ray/v2ray"
  94. # Install V2Ray server config to /etc/v2ray
  95. mkdir -p /etc/v2ray
  96. if [ ! -f "/etc/v2ray/config.json" ]; then
  97. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
  98. let PORT=$RANDOM+10000
  99. sed -i "s/38291/${PORT}/g" "/etc/v2ray/config.json"
  100. UUID=$(cat /proc/sys/kernel/random/uuid)
  101. sed -i "s/8833948b-5861-4a0f-a1d6-83c5606881ff/${UUID}/g" "/etc/v2ray/config.json"
  102. echo "PORT:${PORT}"
  103. echo "UUID:${UUID}"
  104. fi
  105. if [ -n "${SYSTEMCTL_CMD}" ]; then
  106. if [ ! -f "/lib/systemd/system/v2ray.service" ]; then
  107. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemd/v2ray.service" "/lib/systemd/system/"
  108. systemctl enable v2ray
  109. else
  110. if [ ${ISRUN_CMD} -eq 2 ]; then
  111. systemctl start v2ray
  112. fi
  113. fi
  114. elif [ -n "${SERVICE_CMD}" ]; then # Configure SysV if necessary.
  115. if [ ! -f "/etc/init.d/v2ray" ]; then
  116. install_component "daemon"
  117. cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemv/v2ray" "/etc/init.d/v2ray"
  118. chmod +x "/etc/init.d/v2ray"
  119. update-rc.d v2ray defaults
  120. else
  121. if [ ${ISRUN_CMD} -eq 2 ]; then
  122. service v2ray start
  123. fi
  124. fi
  125. fi