v2ray_ss_conf.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #!/bin/bash
  2. # Easy Install Shadowsocks & V2Ray : Generate and display QR_code URL: https://git.io/v2ray_ss.sh
  3. # Usage: bash <(curl -L -s https://git.io/v2ray_ss.sh)
  4. let v2ray_port=$RANDOM+9999
  5. UUID=$(cat /proc/sys/kernel/random/uuid)
  6. let ss_port=$RANDOM+8888
  7. ss_passwd=$(date | md5sum | head -c 6)
  8. cur_dir=$(pwd)
  9. if [ ! -e '/var/ip_addr' ]; then
  10. echo -n $(curl -4 ip.sb) > /var/ip_addr
  11. fi
  12. serverip=$(cat /var/ip_addr)
  13. # Modify Port Number
  14. setport(){
  15. echo_SkyBlue ":: 1. Please Modify the V2ray Server Port Number, Random Port: ${RedBG} ${v2ray_port} "
  16. read -p "Please Enter the Number, Press Enter to not Modify(100--60000): " num
  17. if [[ ${num} -ge 100 ]] && [[ ${num} -le 60000 ]]; then
  18. v2ray_port=$num
  19. fi
  20. }
  21. # debian 9 bbr Setting open
  22. sysctl_config() {
  23. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  24. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  25. echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
  26. echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
  27. sysctl -p >/dev/null 2>&1
  28. }
  29. ss_enable(){
  30. cat <<EOF >/etc/rc.local
  31. #!/bin/sh -e
  32. ss-server -s 0.0.0.0 -p 40000 -k ${ss_passwd} -m aes-256-gcm -t 300 -s ::0 >> /var/log/ss-server.log &
  33. exit 0
  34. EOF
  35. }
  36. conf_shadowsocks(){
  37. echo_SkyBlue ":: 2. Please Modify the Shadowsocks Server Port Number, Random Port: ${RedBG} ${ss_port} "
  38. read -p "Please Enter the Number, Press Enter to not Modify(100--60000): " num
  39. if [[ ${num} -ge 100 ]] && [[ ${num} -le 60000 ]]; then
  40. ss_port=$num
  41. fi
  42. echo_SkyBlue ":: 3. Please Modify the Password of Shadowsocks, Random Password: ${RedBG} ${ss_passwd} "
  43. read -p "Now, You can change the Password, Press Enter to not Modify: " new
  44. if [[ ! -z "${new}" ]]; then
  45. ss_passwd="${new}"
  46. echo -e "Now, New Password: ${GreenBG} ${ss_passwd} ${Font}"
  47. fi
  48. # If Shadowsocks not install, Now install.
  49. if [ ! -e '/usr/local/bin/ss-server' ]; then
  50. sysctl_config
  51. ss_enable
  52. bash <(curl -L -s git.io/fhExJ)
  53. fi
  54. old_ss_port=$(cat /etc/rc.local | grep ss-server | awk '{print $5}')
  55. old_passwd=$(cat /etc/rc.local | grep ss-server | awk '{print $7}')
  56. method=$(cat /etc/rc.local | grep ss-server | awk '{print $9}')
  57. sed -i "s/${old_ss_port}/${ss_port}/g" "/etc/rc.local"
  58. sed -i "s/${old_passwd}/${ss_passwd}/g" "/etc/rc.local"
  59. sed -i "s/ss-server -s 127.0.0.1/ss-server -s 0.0.0.0/g" "/etc/rc.local"
  60. systemctl stop rc-local
  61. # Simple Judgment System: Debian / Centos
  62. if [ -e '/etc/redhat-release' ]; then
  63. mv /etc/rc.local /etc/rc.d/rc.local
  64. ln -s /etc/rc.d/rc.local /etc/rc.local
  65. chmod +x /etc/rc.d/rc.local
  66. systemctl enable rc-local
  67. else
  68. chmod +x /etc/rc.local
  69. systemctl enable rc-local
  70. fi
  71. systemctl restart rc-local
  72. echo_Yellow ":: Info: Shadowsocks Server, Encrypt_Method / Password / IP / Port"
  73. # ss://<<base64_shadowsocks.conf>>
  74. echo "${method}:${ss_passwd}@${serverip}:${ss_port}" | tee ${cur_dir}/base64_shadowsocks.conf
  75. echo
  76. }
  77. conf_v2ray(){
  78. # If V2ray not install, Now install.
  79. if [ ! -e '/etc/v2ray/config.json' ]; then
  80. bash <(curl -L -s https://install.direct/go.sh)
  81. fi
  82. echo_SkyBlue ":: Info: V2ray Server, IP / Port / UUID"
  83. # vmess://<<base64_v2ray_vmess.json>>
  84. cat <<EOF | tee ${cur_dir}/base64_v2ray_vmess.json
  85. {
  86. "v": "2",
  87. "ps": "v2ray",
  88. "add": "${serverip}",
  89. "port": "${v2ray_port}",
  90. "id": "${UUID}",
  91. "aid": "64",
  92. "net": "kcp",
  93. "type": "srtp",
  94. "host": "",
  95. "path": "",
  96. "tls": ""
  97. }
  98. EOF
  99. echo
  100. # v2ray Server mKcp config_file: /etc/v2ray/config.json
  101. cat <<EOF >/etc/v2ray/config.json
  102. {
  103. "inbounds": [
  104. {
  105. "port": $v2ray_port,
  106. "protocol": "vmess",
  107. "settings": {
  108. "clients": [
  109. {
  110. "id": "${UUID}",
  111. "level": 1,
  112. "alterId": 64
  113. }
  114. ]
  115. },
  116. "streamSettings": {
  117. "tcpSettings": {},
  118. "quicSettings": {},
  119. "tlsSettings": {},
  120. "network": "kcp",
  121. "kcpSettings": {
  122. "mtu": 1350,
  123. "tti": 50,
  124. "header": {
  125. "type": "srtp"
  126. },
  127. "readBufferSize": 2,
  128. "writeBufferSize": 2,
  129. "downlinkCapacity": 100,
  130. "congestion": false,
  131. "uplinkCapacity": 100
  132. },
  133. "wsSettings": {},
  134. "httpSettings": {},
  135. "security": "none"
  136. }
  137. }
  138. ],
  139. "log": {
  140. "access": "/var/log/v2ray/access.log",
  141. "loglevel": "info",
  142. "error": "/var/log/v2ray/error.log"
  143. },
  144. "routing": {
  145. "rules": [
  146. {
  147. "ip": [
  148. "0.0.0.0/8",
  149. "10.0.0.0/8",
  150. "100.64.0.0/10",
  151. "169.254.0.0/16",
  152. "172.16.0.0/12",
  153. "192.0.0.0/24",
  154. "192.0.2.0/24",
  155. "192.168.0.0/16",
  156. "198.18.0.0/15",
  157. "198.51.100.0/24",
  158. "203.0.113.0/24",
  159. "::1/128",
  160. "fc00::/7",
  161. "fe80::/10"
  162. ],
  163. "type": "field",
  164. "outboundTag": "blocked"
  165. }
  166. ]
  167. },
  168. "outbounds": [
  169. {
  170. "protocol": "freedom",
  171. "settings": {}
  172. },
  173. {
  174. "protocol": "blackhole",
  175. "tag": "blocked",
  176. "settings": {}
  177. }
  178. ]
  179. }
  180. EOF
  181. systemctl restart v2ray
  182. }
  183. # Definition Display Text Color
  184. Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
  185. Font="\033[0m" && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"
  186. echo_SkyBlue(){
  187. echo -e "${SkyBlue}$1${Font}"
  188. }
  189. echo_Yellow(){
  190. echo -e "${Yellow}$1${Font}"
  191. }
  192. # Display Mobile client QR_code
  193. conf_QRcode(){
  194. st="$(cat ${cur_dir}/base64_shadowsocks.conf)"
  195. ss_b64=$(echo -n $st | base64)
  196. shadowsocks_ss="ss://${ss_b64}"
  197. v2_b64=$(base64 -w0 ${cur_dir}/base64_v2ray_vmess.json)
  198. v2ray_vmess="vmess://${v2_b64}"
  199. echo_SkyBlue ":: Shadowsocks Client Configuration for Mobile QR_code!"
  200. echo -n $shadowsocks_ss | qrencode -o - -t UTF8
  201. echo_Yellow $shadowsocks_ss
  202. echo
  203. echo_SkyBlue ":: V2rayNG Client Configuration for Mobile QR_code!"
  204. echo -n $v2ray_vmess | qrencode -o - -t UTF8
  205. echo_SkyBlue ":: V2rayN Windows Client Vmess Protocol Configuration"
  206. echo $v2ray_vmess
  207. echo
  208. echo_Yellow ":: Usage: ${RedBG} bash <(curl -L -s https://git.io/v2ray_ss.sh) setup ${Font} to Modified Port Password and UUID"
  209. }
  210. # Set v2ray port and UUID
  211. set_v2ray_ss(){
  212. setport
  213. conf_shadowsocks
  214. conf_v2ray
  215. }
  216. clear
  217. # Run the script for the first time, set the port and UUID
  218. if [ ! -e 'base64_v2ray_vmess.json' ]; then
  219. # Simple Judgment System: Debian / Centos
  220. if [ -e '/etc/redhat-release' ]; then
  221. yum update -y && yum install -y qrencode wget vim
  222. else
  223. apt update && apt install -y qrencode
  224. fi
  225. set_v2ray_ss
  226. fi
  227. # Parameter 'setup' setting port and UUID
  228. if [[ $# > 0 ]]; then
  229. key="$1"
  230. case $key in
  231. setup)
  232. set_v2ray_ss
  233. ;;
  234. esac
  235. fi
  236. echo_SkyBlue ":: Easy Install Shadowsocks & V2Ray : Generate and display QR_code By 蘭雅sRGB "
  237. echo_Yellow ":: Usage: bash <(curl -L -s https://git.io/v2ray_ss.sh) "
  238. # Output ss and v2ray configuration and QR code
  239. conf_QRcode 2>&1 | tee ${cur_dir}/v2ray_ss.log