shadowsock.sh 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. #!/usr/bin/env bash
  2. #
  3. # Auto install Shadowsocks Server (all version)
  4. #
  5. # Copyright (C) 2016-2018 Teddysun <i@teddysun.com>
  6. #
  7. # System Required: CentOS 6+, Debian7+, Ubuntu12+
  8. #
  9. # Reference URL:
  10. # https://github.com/shadowsocks/shadowsocks
  11. # https://github.com/shadowsocks/shadowsocks-go
  12. # https://github.com/shadowsocks/shadowsocks-libev
  13. # https://github.com/shadowsocks/shadowsocks-windows
  14. # https://github.com/shadowsocksr-rm/shadowsocksr
  15. # https://github.com/shadowsocksrr/shadowsocksr
  16. # https://github.com/shadowsocksrr/shadowsocksr-csharp
  17. #
  18. # Thanks:
  19. # @clowwindy <https://twitter.com/clowwindy>
  20. # @breakwa11 <https://twitter.com/breakwa11>
  21. # @cyfdecyf <https://twitter.com/cyfdecyf>
  22. # @madeye <https://github.com/madeye>
  23. # @linusyang <https://github.com/linusyang>
  24. # @Akkariiin <https://github.com/Akkariiin>
  25. #
  26. # Intro: https://teddysun.com/486.html
  27. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  28. export PATH
  29. red='\033[0;31m'
  30. green='\033[0;32m'
  31. yellow='\033[0;33m'
  32. plain='\033[0m'
  33. [[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1
  34. cur_dir=$( pwd )
  35. software=(Shadowsocks-Python ShadowsocksR Shadowsocks-Go Shadowsocks-libev)
  36. libsodium_file="libsodium-1.0.16"
  37. libsodium_url="https://github.com/jedisct1/libsodium/releases/download/1.0.16/libsodium-1.0.16.tar.gz"
  38. mbedtls_file="mbedtls-2.6.0"
  39. mbedtls_url="https://tls.mbed.org/download/mbedtls-2.6.0-gpl.tgz"
  40. shadowsocks_python_file="shadowsocks-master"
  41. shadowsocks_python_url="https://github.com/shadowsocks/shadowsocks/archive/master.zip"
  42. shadowsocks_python_init="/etc/init.d/shadowsocks-python"
  43. shadowsocks_python_config="/etc/shadowsocks-python/config.json"
  44. shadowsocks_python_centos="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks"
  45. shadowsocks_python_debian="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-debian"
  46. shadowsocks_r_file="shadowsocksr-3.2.1"
  47. shadowsocks_r_url="https://github.com/shadowsocksrr/shadowsocksr/archive/3.2.1.tar.gz"
  48. shadowsocks_r_init="/etc/init.d/shadowsocks-r"
  49. shadowsocks_r_config="/etc/shadowsocks-r/config.json"
  50. shadowsocks_r_centos="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR"
  51. shadowsocks_r_debian="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR-debian"
  52. shadowsocks_go_file_64="shadowsocks-server-linux64-1.2.1"
  53. shadowsocks_go_url_64="https://dl.lamp.sh/shadowsocks/shadowsocks-server-linux64-1.2.1.gz"
  54. shadowsocks_go_file_32="shadowsocks-server-linux32-1.2.1"
  55. shadowsocks_go_url_32="https://dl.lamp.sh/shadowsocks/shadowsocks-server-linux32-1.2.1.gz"
  56. shadowsocks_go_init="/etc/init.d/shadowsocks-go"
  57. shadowsocks_go_config="/etc/shadowsocks-go/config.json"
  58. shadowsocks_go_centos="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go"
  59. shadowsocks_go_debian="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go-debian"
  60. shadowsocks_libev_init="/etc/init.d/shadowsocks-libev"
  61. shadowsocks_libev_config="/etc/shadowsocks-libev/config.json"
  62. shadowsocks_libev_centos="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev"
  63. shadowsocks_libev_debian="https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev-debian"
  64. # Stream Ciphers
  65. common_ciphers=(
  66. aes-256-gcm
  67. aes-192-gcm
  68. aes-128-gcm
  69. aes-256-ctr
  70. aes-192-ctr
  71. aes-128-ctr
  72. aes-256-cfb
  73. aes-192-cfb
  74. aes-128-cfb
  75. camellia-128-cfb
  76. camellia-192-cfb
  77. camellia-256-cfb
  78. xchacha20-ietf-poly1305
  79. chacha20-ietf-poly1305
  80. chacha20-ietf
  81. chacha20
  82. salsa20
  83. rc4-md5
  84. )
  85. go_ciphers=(
  86. aes-256-cfb
  87. aes-192-cfb
  88. aes-128-cfb
  89. aes-256-ctr
  90. aes-192-ctr
  91. aes-128-ctr
  92. chacha20-ietf
  93. chacha20
  94. salsa20
  95. rc4-md5
  96. )
  97. r_ciphers=(
  98. none
  99. aes-256-cfb
  100. aes-192-cfb
  101. aes-128-cfb
  102. aes-256-cfb8
  103. aes-192-cfb8
  104. aes-128-cfb8
  105. aes-256-ctr
  106. aes-192-ctr
  107. aes-128-ctr
  108. chacha20-ietf
  109. chacha20
  110. salsa20
  111. xchacha20
  112. xsalsa20
  113. rc4-md5
  114. )
  115. # Reference URL:
  116. # https://github.com/shadowsocksr-rm/shadowsocks-rss/blob/master/ssr.md
  117. # https://github.com/shadowsocksrr/shadowsocksr/commit/a3cf0254508992b7126ab1151df0c2f10bf82680
  118. # Protocol
  119. protocols=(
  120. origin
  121. verify_deflate
  122. auth_sha1_v4
  123. auth_sha1_v4_compatible
  124. auth_aes128_md5
  125. auth_aes128_sha1
  126. auth_chain_a
  127. auth_chain_b
  128. auth_chain_c
  129. auth_chain_d
  130. auth_chain_e
  131. auth_chain_f
  132. )
  133. # obfs
  134. obfs=(
  135. plain
  136. http_simple
  137. http_simple_compatible
  138. http_post
  139. http_post_compatible
  140. tls1.2_ticket_auth
  141. tls1.2_ticket_auth_compatible
  142. tls1.2_ticket_fastauth
  143. tls1.2_ticket_fastauth_compatible
  144. )
  145. # libev obfuscating
  146. obfs_libev=(http tls)
  147. # initialization parameter
  148. libev_obfs=""
  149. disable_selinux() {
  150. if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
  151. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  152. setenforce 0
  153. fi
  154. }
  155. check_sys() {
  156. local checkType=$1
  157. local value=$2
  158. local release=''
  159. local systemPackage=''
  160. if [ -f /etc/redhat-release ]; then
  161. release="centos"
  162. systemPackage="yum"
  163. elif cat /etc/issue | grep -Eqi "debian"; then
  164. release="debian"
  165. systemPackage="apt"
  166. elif cat /etc/issue | grep -Eqi "ubuntu"; then
  167. release="ubuntu"
  168. systemPackage="apt"
  169. elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
  170. release="centos"
  171. systemPackage="yum"
  172. elif cat /proc/version | grep -Eqi "debian"; then
  173. release="debian"
  174. systemPackage="apt"
  175. elif cat /proc/version | grep -Eqi "ubuntu"; then
  176. release="ubuntu"
  177. systemPackage="apt"
  178. elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
  179. release="centos"
  180. systemPackage="yum"
  181. fi
  182. if [ ${checkType} == "sysRelease" ]; then
  183. if [ "$value" == "$release" ]; then
  184. return 0
  185. else
  186. return 1
  187. fi
  188. elif [ ${checkType} == "packageManager" ]; then
  189. if [ "$value" == "$systemPackage" ]; then
  190. return 0
  191. else
  192. return 1
  193. fi
  194. fi
  195. }
  196. version_ge(){
  197. test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
  198. }
  199. version_gt(){
  200. test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
  201. }
  202. check_kernel_version() {
  203. local kernel_version=$(uname -r | cut -d- -f1)
  204. if version_gt ${kernel_version} 3.7.0; then
  205. return 0
  206. else
  207. return 1
  208. fi
  209. }
  210. getversion() {
  211. if [[ -s /etc/redhat-release ]]; then
  212. grep -oE "[0-9.]+" /etc/redhat-release
  213. else
  214. grep -oE "[0-9.]+" /etc/issue
  215. fi
  216. }
  217. centosversion() {
  218. if check_sys sysRelease centos; then
  219. local code=$1
  220. local version="$(getversion)"
  221. local main_ver=${version%%.*}
  222. if [ "$main_ver" == "$code" ]; then
  223. return 0
  224. else
  225. return 1
  226. fi
  227. else
  228. return 1
  229. fi
  230. }
  231. autoconf_version(){
  232. if [ ! "$(command -v autoconf)" ]; then
  233. echo -e "[${green}Info${plain}] Starting install autoconf..."
  234. if check_sys packageManager yum; then
  235. yum install -y autoconf > /dev/null 2>&1
  236. elif check_sys packageManager apt; then
  237. apt-get -y update > /dev/null 2>&1
  238. apt-get -y install autoconf > /dev/null 2>&1
  239. fi
  240. echo -e "[${green}Info${plain}] Install autoconf completed."
  241. fi
  242. local autoconf_ver=$(autoconf --version | grep autoconf | grep -oE "[0-9.]+")
  243. if version_ge ${autoconf_ver} 2.67; then
  244. return 0
  245. else
  246. return 1
  247. fi
  248. }
  249. get_ip() {
  250. local IP=$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )
  251. [ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
  252. [ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
  253. [ ! -z ${IP} ] && echo ${IP} || echo
  254. }
  255. get_ipv6(){
  256. local ipv6=$(wget -qO- -t1 -T2 ipv6.icanhazip.com)
  257. [ -z ${ipv6} ] && return 1 || return 0
  258. }
  259. get_libev_ver(){
  260. libev_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/shadowsocks-libev/releases/latest | grep 'tag_name' | cut -d\" -f4)
  261. [ -z ${libev_ver} ] && echo -e "[${red}Error${plain}] Get shadowsocks-libev latest version failed" && exit 1
  262. }
  263. get_opsy(){
  264. [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
  265. [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
  266. [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
  267. }
  268. is_64bit() {
  269. if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
  270. return 0
  271. else
  272. return 1
  273. fi
  274. }
  275. debianversion(){
  276. if check_sys sysRelease debian;then
  277. local version=$( get_opsy )
  278. local code=${1}
  279. local main_ver=$( echo ${version} | sed 's/[^0-9]//g')
  280. if [ "${main_ver}" == "${code}" ];then
  281. return 0
  282. else
  283. return 1
  284. fi
  285. else
  286. return 1
  287. fi
  288. }
  289. download() {
  290. local filename=$(basename $1)
  291. if [ -f ${1} ]; then
  292. echo "${filename} [found]"
  293. else
  294. echo "${filename} not found, download now..."
  295. wget --no-check-certificate -c -t3 -T60 -O ${1} ${2}
  296. if [ $? -ne 0 ]; then
  297. echo -e "[${red}Error${plain}] Download ${filename} failed."
  298. exit 1
  299. fi
  300. fi
  301. }
  302. download_files() {
  303. cd ${cur_dir}
  304. if [ "${selected}" == "1" ]; then
  305. download "${shadowsocks_python_file}.zip" "${shadowsocks_python_url}"
  306. if check_sys packageManager yum; then
  307. download "${shadowsocks_python_init}" "${shadowsocks_python_centos}"
  308. elif check_sys packageManager apt; then
  309. download "${shadowsocks_python_init}" "${shadowsocks_python_debian}"
  310. fi
  311. elif [ "${selected}" == "2" ]; then
  312. download "${shadowsocks_r_file}.tar.gz" "${shadowsocks_r_url}"
  313. if check_sys packageManager yum; then
  314. download "${shadowsocks_r_init}" "${shadowsocks_r_centos}"
  315. elif check_sys packageManager apt; then
  316. download "${shadowsocks_r_init}" "${shadowsocks_r_debian}"
  317. fi
  318. elif [ "${selected}" == "3" ]; then
  319. if is_64bit; then
  320. download "${shadowsocks_go_file_64}.gz" "${shadowsocks_go_url_64}"
  321. else
  322. download "${shadowsocks_go_file_32}.gz" "${shadowsocks_go_url_32}"
  323. fi
  324. if check_sys packageManager yum; then
  325. download "${shadowsocks_go_init}" "${shadowsocks_go_centos}"
  326. elif check_sys packageManager apt; then
  327. download "${shadowsocks_go_init}" "${shadowsocks_go_debian}"
  328. fi
  329. elif [ "${selected}" == "4" ]; then
  330. get_libev_ver
  331. shadowsocks_libev_file="shadowsocks-libev-$(echo ${libev_ver} | sed -e 's/^[a-zA-Z]//g')"
  332. shadowsocks_libev_url="https://github.com/shadowsocks/shadowsocks-libev/releases/download/${libev_ver}/${shadowsocks_libev_file}.tar.gz"
  333. download "${shadowsocks_libev_file}.tar.gz" "${shadowsocks_libev_url}"
  334. if check_sys packageManager yum; then
  335. download "${shadowsocks_libev_init}" "${shadowsocks_libev_centos}"
  336. elif check_sys packageManager apt; then
  337. download "${shadowsocks_libev_init}" "${shadowsocks_libev_debian}"
  338. fi
  339. fi
  340. }
  341. get_char() {
  342. SAVEDSTTY=`stty -g`
  343. stty -echo
  344. stty cbreak
  345. dd if=/dev/tty bs=1 count=1 2> /dev/null
  346. stty -raw
  347. stty echo
  348. stty $SAVEDSTTY
  349. }
  350. error_detect_depends(){
  351. local command=$1
  352. local depend=`echo "${command}" | awk '{print $4}'`
  353. ${command}
  354. if [ $? != 0 ]; then
  355. echo -e "[${red}Error${plain}] Failed to install ${red}${depend}${plain}"
  356. echo "Please visit: https://teddysun.com/486.html and contact."
  357. exit 1
  358. fi
  359. }
  360. config_firewall() {
  361. if centosversion 6; then
  362. /etc/init.d/iptables status > /dev/null 2>&1
  363. if [ $? -eq 0 ]; then
  364. iptables -L -n | grep -i ${shadowsocksport} > /dev/null 2>&1
  365. if [ $? -ne 0 ]; then
  366. iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksport} -j ACCEPT
  367. iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksport} -j ACCEPT
  368. /etc/init.d/iptables save
  369. /etc/init.d/iptables restart
  370. else
  371. echo -e "[${green}Info${plain}] port ${green}${shadowsocksport}${plain} already be enabled."
  372. fi
  373. else
  374. echo -e "[${yellow}Warning${plain}] iptables looks like not running or not installed, please enable port ${shadowsocksport} manually if necessary."
  375. fi
  376. elif centosversion 7; then
  377. systemctl status firewalld > /dev/null 2>&1
  378. if [ $? -eq 0 ]; then
  379. firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
  380. firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
  381. firewall-cmd --reload
  382. else
  383. echo -e "[${yellow}Warning${plain}] firewalld looks like not running or not installed, please enable port ${shadowsocksport} manually if necessary."
  384. fi
  385. fi
  386. }
  387. config_shadowsocks() {
  388. if check_kernel_version; then
  389. fast_open="true"
  390. else
  391. fast_open="false"
  392. fi
  393. if [ "${selected}" == "1" ]; then
  394. if [ ! -d "$(dirname ${shadowsocks_python_config})" ]; then
  395. mkdir -p $(dirname ${shadowsocks_python_config})
  396. fi
  397. cat > ${shadowsocks_python_config}<<-EOF
  398. {
  399. "server":"0.0.0.0",
  400. "server_port":${shadowsocksport},
  401. "local_address":"127.0.0.1",
  402. "local_port":1080,
  403. "password":"${shadowsockspwd}",
  404. "timeout":300,
  405. "method":"${shadowsockscipher}",
  406. "fast_open":${fast_open}
  407. }
  408. EOF
  409. elif [ "${selected}" == "2" ]; then
  410. if [ ! -d "$(dirname ${shadowsocks_r_config})" ]; then
  411. mkdir -p $(dirname ${shadowsocks_r_config})
  412. fi
  413. cat > ${shadowsocks_r_config}<<-EOF
  414. {
  415. "server":"0.0.0.0",
  416. "server_ipv6":"::",
  417. "server_port":${shadowsocksport},
  418. "local_address":"127.0.0.1",
  419. "local_port":1080,
  420. "password":"${shadowsockspwd}",
  421. "timeout":120,
  422. "method":"${shadowsockscipher}",
  423. "protocol":"${shadowsockprotocol}",
  424. "protocol_param":"",
  425. "obfs":"${shadowsockobfs}",
  426. "obfs_param":"",
  427. "redirect":"",
  428. "dns_ipv6":false,
  429. "fast_open":${fast_open},
  430. "workers":1
  431. }
  432. EOF
  433. elif [ "${selected}" == "3" ]; then
  434. if [ ! -d "$(dirname ${shadowsocks_go_config})" ]; then
  435. mkdir -p $(dirname ${shadowsocks_go_config})
  436. fi
  437. cat > ${shadowsocks_go_config}<<-EOF
  438. {
  439. "server":"0.0.0.0",
  440. "server_port":${shadowsocksport},
  441. "local_port":1080,
  442. "password":"${shadowsockspwd}",
  443. "method":"${shadowsockscipher}",
  444. "timeout":300
  445. }
  446. EOF
  447. elif [ "${selected}" == "4" ]; then
  448. local server_value="\"0.0.0.0\""
  449. if get_ipv6; then
  450. server_value="[\"[::0]\",\"0.0.0.0\"]"
  451. fi
  452. if [ ! -d "$(dirname ${shadowsocks_libev_config})" ]; then
  453. mkdir -p $(dirname ${shadowsocks_libev_config})
  454. fi
  455. if [ "${libev_obfs}" == "y" ] || [ "${libev_obfs}" == "Y" ]; then
  456. cat > ${shadowsocks_libev_config}<<-EOF
  457. {
  458. "server":${server_value},
  459. "server_port":${shadowsocksport},
  460. "local_address":"127.0.0.1",
  461. "local_port":1080,
  462. "password":"${shadowsockspwd}",
  463. "timeout":300,
  464. "method":"${shadowsockscipher}",
  465. "fast_open":${fast_open},
  466. "plugin":"obfs-server --obfs ${shadowsocklibev_obfs}"
  467. }
  468. EOF
  469. else
  470. cat > ${shadowsocks_libev_config}<<-EOF
  471. {
  472. "server":${server_value},
  473. "server_port":${shadowsocksport},
  474. "local_address":"127.0.0.1",
  475. "local_port":1080,
  476. "password":"${shadowsockspwd}",
  477. "timeout":300,
  478. "method":"${shadowsockscipher}",
  479. "fast_open":${fast_open}
  480. }
  481. EOF
  482. fi
  483. fi
  484. }
  485. install_dependencies() {
  486. if check_sys packageManager yum; then
  487. echo -e "[${green}Info${plain}] Checking the EPEL repository..."
  488. if [ ! -f /etc/yum.repos.d/epel.repo ]; then
  489. yum install -y -q epel-release
  490. fi
  491. [ ! -f /etc/yum.repos.d/epel.repo ] && echo -e "[${red}Error${plain}] Install EPEL repository failed, please check it." && exit 1
  492. [ ! "$(command -v yum-config-manager)" ] && yum install -y -q yum-utils
  493. if [ x"`yum-config-manager epel | grep -w enabled | awk '{print $3}'`" != x"True" ]; then
  494. yum-config-manager --enable epel
  495. fi
  496. echo -e "[${green}Info${plain}] Checking the EPEL repository complete..."
  497. yum_depends=(
  498. unzip gzip openssl openssl-devel gcc python python-devel python-setuptools pcre pcre-devel libtool libevent xmlto
  499. autoconf automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel asciidoc
  500. libev-devel c-ares-devel git qrencode
  501. )
  502. for depend in ${yum_depends[@]}; do
  503. error_detect_depends "yum -y install ${depend}"
  504. done
  505. elif check_sys packageManager apt; then
  506. apt_depends=(
  507. gettext build-essential unzip gzip python python-dev python-setuptools curl openssl libssl-dev
  508. autoconf automake libtool gcc make perl cpio libpcre3 libpcre3-dev zlib1g-dev libev-dev libc-ares-dev git qrencode
  509. )
  510. apt-get -y update
  511. for depend in ${apt_depends[@]}; do
  512. error_detect_depends "apt-get -y install ${depend}"
  513. done
  514. fi
  515. }
  516. install_check() {
  517. if check_sys packageManager yum || check_sys packageManager apt; then
  518. if centosversion 5; then
  519. return 1
  520. fi
  521. return 0
  522. else
  523. return 1
  524. fi
  525. }
  526. install_select() {
  527. if ! install_check; then
  528. echo -e "[${red}Error${plain}] Your OS is not supported to run it!"
  529. echo "Please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again."
  530. exit 1
  531. fi
  532. clear
  533. while true
  534. do
  535. echo "Which Shadowsocks server you'd select:"
  536. for ((i=1;i<=${#software[@]};i++ )); do
  537. hint="${software[$i-1]}"
  538. echo -e "${green}${i}${plain}) ${hint}"
  539. done
  540. read -p "Please enter a number (Default ${software[0]}):" selected
  541. [ -z "${selected}" ] && selected="1"
  542. case "${selected}" in
  543. 1|2|3|4)
  544. echo
  545. echo "You choose = ${software[${selected}-1]}"
  546. echo
  547. break
  548. ;;
  549. *)
  550. echo -e "[${red}Error${plain}] Please only enter a number [1-4]"
  551. ;;
  552. esac
  553. done
  554. }
  555. install_prepare_password() {
  556. echo "Please enter password for ${software[${selected}-1]}"
  557. read -p "(Default password: teddysun.com):" shadowsockspwd
  558. [ -z "${shadowsockspwd}" ] && shadowsockspwd="teddysun.com"
  559. echo
  560. echo "password = ${shadowsockspwd}"
  561. echo
  562. }
  563. install_prepare_port() {
  564. while true
  565. do
  566. dport=$(shuf -i 9000-19999 -n 1)
  567. echo -e "Please enter a port for ${software[${selected}-1]} [1-65535]"
  568. read -p "(Default port: ${dport}):" shadowsocksport
  569. [ -z "${shadowsocksport}" ] && shadowsocksport=${dport}
  570. expr ${shadowsocksport} + 1 &>/dev/null
  571. if [ $? -eq 0 ]; then
  572. if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ] && [ ${shadowsocksport:0:1} != 0 ]; then
  573. echo
  574. echo "port = ${shadowsocksport}"
  575. echo
  576. break
  577. fi
  578. fi
  579. echo -e "[${red}Error${plain}] Please enter a correct number [1-65535]"
  580. done
  581. }
  582. install_prepare_cipher() {
  583. while true
  584. do
  585. echo -e "Please select stream cipher for ${software[${selected}-1]}:"
  586. if [[ "${selected}" == "1" || "${selected}" == "4" ]]; then
  587. for ((i=1;i<=${#common_ciphers[@]};i++ )); do
  588. hint="${common_ciphers[$i-1]}"
  589. echo -e "${green}${i}${plain}) ${hint}"
  590. done
  591. read -p "Which cipher you'd select(Default: ${common_ciphers[0]}):" pick
  592. [ -z "$pick" ] && pick=1
  593. expr ${pick} + 1 &>/dev/null
  594. if [ $? -ne 0 ]; then
  595. echo -e "[${red}Error${plain}] Please enter a number"
  596. continue
  597. fi
  598. if [[ "$pick" -lt 1 || "$pick" -gt ${#common_ciphers[@]} ]]; then
  599. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#common_ciphers[@]}"
  600. continue
  601. fi
  602. shadowsockscipher=${common_ciphers[$pick-1]}
  603. elif [ "${selected}" == "2" ]; then
  604. for ((i=1;i<=${#r_ciphers[@]};i++ )); do
  605. hint="${r_ciphers[$i-1]}"
  606. echo -e "${green}${i}${plain}) ${hint}"
  607. done
  608. read -p "Which cipher you'd select(Default: ${r_ciphers[1]}):" pick
  609. [ -z "$pick" ] && pick=2
  610. expr ${pick} + 1 &>/dev/null
  611. if [ $? -ne 0 ]; then
  612. echo -e "[${red}Error${plain}] Please enter a number"
  613. continue
  614. fi
  615. if [[ "$pick" -lt 1 || "$pick" -gt ${#r_ciphers[@]} ]]; then
  616. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#r_ciphers[@]}"
  617. continue
  618. fi
  619. shadowsockscipher=${r_ciphers[$pick-1]}
  620. elif [ "${selected}" == "3" ]; then
  621. for ((i=1;i<=${#go_ciphers[@]};i++ )); do
  622. hint="${go_ciphers[$i-1]}"
  623. echo -e "${green}${i}${plain}) ${hint}"
  624. done
  625. read -p "Which cipher you'd select(Default: ${go_ciphers[0]}):" pick
  626. [ -z "$pick" ] && pick=1
  627. expr ${pick} + 1 &>/dev/null
  628. if [ $? -ne 0 ]; then
  629. echo -e "[${red}Error${plain}] Please enter a number"
  630. continue
  631. fi
  632. if [[ "$pick" -lt 1 || "$pick" -gt ${#go_ciphers[@]} ]]; then
  633. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#go_ciphers[@]}"
  634. continue
  635. fi
  636. shadowsockscipher=${go_ciphers[$pick-1]}
  637. fi
  638. echo
  639. echo "cipher = ${shadowsockscipher}"
  640. echo
  641. break
  642. done
  643. }
  644. install_prepare_protocol() {
  645. while true
  646. do
  647. echo -e "Please select protocol for ${software[${selected}-1]}:"
  648. for ((i=1;i<=${#protocols[@]};i++ )); do
  649. hint="${protocols[$i-1]}"
  650. echo -e "${green}${i}${plain}) ${hint}"
  651. done
  652. read -p "Which protocol you'd select(Default: ${protocols[0]}):" protocol
  653. [ -z "$protocol" ] && protocol=1
  654. expr ${protocol} + 1 &>/dev/null
  655. if [ $? -ne 0 ]; then
  656. echo -e "[${red}Error${plain}] Please enter a number"
  657. continue
  658. fi
  659. if [[ "$protocol" -lt 1 || "$protocol" -gt ${#protocols[@]} ]]; then
  660. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#protocols[@]}"
  661. continue
  662. fi
  663. shadowsockprotocol=${protocols[$protocol-1]}
  664. echo
  665. echo "protocol = ${shadowsockprotocol}"
  666. echo
  667. break
  668. done
  669. }
  670. install_prepare_obfs() {
  671. while true
  672. do
  673. echo -e "Please select obfs for ${software[${selected}-1]}:"
  674. for ((i=1;i<=${#obfs[@]};i++ )); do
  675. hint="${obfs[$i-1]}"
  676. echo -e "${green}${i}${plain}) ${hint}"
  677. done
  678. read -p "Which obfs you'd select(Default: ${obfs[0]}):" r_obfs
  679. [ -z "$r_obfs" ] && r_obfs=1
  680. expr ${r_obfs} + 1 &>/dev/null
  681. if [ $? -ne 0 ]; then
  682. echo -e "[${red}Error${plain}] Please enter a number"
  683. continue
  684. fi
  685. if [[ "$r_obfs" -lt 1 || "$r_obfs" -gt ${#obfs[@]} ]]; then
  686. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#obfs[@]}"
  687. continue
  688. fi
  689. shadowsockobfs=${obfs[$r_obfs-1]}
  690. echo
  691. echo "obfs = ${shadowsockobfs}"
  692. echo
  693. break
  694. done
  695. }
  696. install_prepare_libev_obfs() {
  697. if autoconf_version; then
  698. while true
  699. do
  700. echo -e "Do you want install simple-obfs for ${software[${selected}-1]}? [y/n]"
  701. read -p "(default: n):" libev_obfs
  702. [ -z "$libev_obfs" ] && libev_obfs=n
  703. case "${libev_obfs}" in
  704. y|Y|n|N)
  705. echo
  706. echo "You choose = ${libev_obfs}"
  707. echo
  708. break
  709. ;;
  710. *)
  711. echo -e "[${red}Error${plain}] Please only enter [y/n]"
  712. ;;
  713. esac
  714. done
  715. if [ "${libev_obfs}" == "y" ] || [ "${libev_obfs}" == "Y" ]; then
  716. while true
  717. do
  718. echo -e "Please select obfs for simple-obfs:"
  719. for ((i=1;i<=${#obfs_libev[@]};i++ )); do
  720. hint="${obfs_libev[$i-1]}"
  721. echo -e "${green}${i}${plain}) ${hint}"
  722. done
  723. read -p "Which obfs you'd select(Default: ${obfs_libev[0]}):" r_libev_obfs
  724. [ -z "$r_libev_obfs" ] && r_libev_obfs=1
  725. expr ${r_libev_obfs} + 1 &>/dev/null
  726. if [ $? -ne 0 ]; then
  727. echo -e "[${red}Error${plain}] Please enter a number"
  728. continue
  729. fi
  730. if [[ "$r_libev_obfs" -lt 1 || "$r_libev_obfs" -gt ${#obfs_libev[@]} ]]; then
  731. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#obfs_libev[@]}"
  732. continue
  733. fi
  734. shadowsocklibev_obfs=${obfs_libev[$r_libev_obfs-1]}
  735. echo
  736. echo "obfs = ${shadowsocklibev_obfs}"
  737. echo
  738. break
  739. done
  740. fi
  741. else
  742. echo -e "[${yellow}Warning${plain}] autoconf version is less than 2.67, simple-obfs for ${software[${selected}-1]} installation has been skipped"
  743. fi
  744. }
  745. install_prepare() {
  746. if [[ "${selected}" == "1" || "${selected}" == "3" || "${selected}" == "4" ]]; then
  747. install_prepare_password
  748. install_prepare_port
  749. install_prepare_cipher
  750. if [ "${selected}" == "4" ]; then
  751. install_prepare_libev_obfs
  752. fi
  753. elif [ "${selected}" == "2" ]; then
  754. install_prepare_password
  755. install_prepare_port
  756. install_prepare_cipher
  757. install_prepare_protocol
  758. install_prepare_obfs
  759. fi
  760. echo
  761. echo "Press any key to start...or Press Ctrl+C to cancel"
  762. char=`get_char`
  763. }
  764. install_libsodium() {
  765. if [ ! -f /usr/lib/libsodium.a ]; then
  766. cd ${cur_dir}
  767. download "${libsodium_file}.tar.gz" "${libsodium_url}"
  768. tar zxf ${libsodium_file}.tar.gz
  769. cd ${libsodium_file}
  770. ./configure --prefix=/usr && make && make install
  771. if [ $? -ne 0 ]; then
  772. echo -e "[${red}Error${plain}] ${libsodium_file} install failed."
  773. install_cleanup
  774. exit 1
  775. fi
  776. else
  777. echo -e "[${green}Info${plain}] ${libsodium_file} already installed."
  778. fi
  779. }
  780. install_mbedtls() {
  781. if [ ! -f /usr/lib/libmbedtls.a ]; then
  782. cd ${cur_dir}
  783. download "${mbedtls_file}-gpl.tgz" "${mbedtls_url}"
  784. tar xf ${mbedtls_file}-gpl.tgz
  785. cd ${mbedtls_file}
  786. make SHARED=1 CFLAGS=-fPIC
  787. make DESTDIR=/usr install
  788. if [ $? -ne 0 ]; then
  789. echo -e "[${red}Error${plain}] ${mbedtls_file} install failed."
  790. install_cleanup
  791. exit 1
  792. fi
  793. else
  794. echo -e "[${green}Info${plain}] ${mbedtls_file} already installed."
  795. fi
  796. }
  797. install_shadowsocks_python() {
  798. cd ${cur_dir}
  799. unzip -q ${shadowsocks_python_file}.zip
  800. if [ $? -ne 0 ];then
  801. echo -e "[${red}Error${plain}] unzip ${shadowsocks_python_file}.zip failed, please check unzip command."
  802. install_cleanup
  803. exit 1
  804. fi
  805. cd ${shadowsocks_python_file}
  806. python setup.py install --record /usr/local/shadowsocks_python.log
  807. if [ -f /usr/bin/ssserver ] || [ -f /usr/local/bin/ssserver ]; then
  808. chmod +x ${shadowsocks_python_init}
  809. local service_name=$(basename ${shadowsocks_python_init})
  810. if check_sys packageManager yum; then
  811. chkconfig --add ${service_name}
  812. chkconfig ${service_name} on
  813. elif check_sys packageManager apt; then
  814. update-rc.d -f ${service_name} defaults
  815. fi
  816. else
  817. echo
  818. echo -e "[${red}Error${plain}] ${software[0]} install failed."
  819. echo "Please visit: https://teddysun.com/486.html and contact."
  820. install_cleanup
  821. exit 1
  822. fi
  823. }
  824. install_shadowsocks_r() {
  825. cd ${cur_dir}
  826. tar zxf ${shadowsocks_r_file}.tar.gz
  827. mv ${shadowsocks_r_file}/shadowsocks /usr/local/
  828. if [ -f /usr/local/shadowsocks/server.py ]; then
  829. chmod +x ${shadowsocks_r_init}
  830. local service_name=$(basename ${shadowsocks_r_init})
  831. if check_sys packageManager yum; then
  832. chkconfig --add ${service_name}
  833. chkconfig ${service_name} on
  834. elif check_sys packageManager apt; then
  835. update-rc.d -f ${service_name} defaults
  836. fi
  837. else
  838. echo
  839. echo -e "[${red}Error${plain}] ${software[1]} install failed."
  840. echo "Please visit; https://teddysun.com/486.html and contact."
  841. install_cleanup
  842. exit 1
  843. fi
  844. }
  845. install_shadowsocks_go() {
  846. cd ${cur_dir}
  847. if is_64bit; then
  848. gzip -d ${shadowsocks_go_file_64}.gz
  849. if [ $? -ne 0 ];then
  850. echo -e "[${red}Error${plain}] Decompress ${shadowsocks_go_file_64}.gz failed."
  851. install_cleanup
  852. exit 1
  853. fi
  854. mv -f ${shadowsocks_go_file_64} /usr/bin/shadowsocks-server
  855. else
  856. gzip -d ${shadowsocks_go_file_32}.gz
  857. if [ $? -ne 0 ];then
  858. echo -e "[${red}Error${plain}] Decompress ${shadowsocks_go_file_32}.gz failed."
  859. install_cleanup
  860. exit 1
  861. fi
  862. mv -f ${shadowsocks_go_file_32} /usr/bin/shadowsocks-server
  863. fi
  864. if [ -f /usr/bin/shadowsocks-server ]; then
  865. chmod +x /usr/bin/shadowsocks-server
  866. chmod +x ${shadowsocks_go_init}
  867. local service_name=$(basename ${shadowsocks_go_init})
  868. if check_sys packageManager yum; then
  869. chkconfig --add ${service_name}
  870. chkconfig ${service_name} on
  871. elif check_sys packageManager apt; then
  872. update-rc.d -f ${service_name} defaults
  873. fi
  874. else
  875. echo
  876. echo -e "[${red}Error${plain}] ${software[2]} install failed."
  877. echo "Please visit: https://teddysun.com/486.html and contact."
  878. install_cleanup
  879. exit 1
  880. fi
  881. }
  882. install_shadowsocks_libev() {
  883. cd ${cur_dir}
  884. tar zxf ${shadowsocks_libev_file}.tar.gz
  885. cd ${shadowsocks_libev_file}
  886. ./configure --disable-documentation && make && make install
  887. if [ $? -eq 0 ]; then
  888. chmod +x ${shadowsocks_libev_init}
  889. local service_name=$(basename ${shadowsocks_libev_init})
  890. if check_sys packageManager yum; then
  891. chkconfig --add ${service_name}
  892. chkconfig ${service_name} on
  893. elif check_sys packageManager apt; then
  894. update-rc.d -f ${service_name} defaults
  895. fi
  896. else
  897. echo
  898. echo -e "[${red}Error${plain}] ${software[3]} install failed."
  899. echo "Please visit: https://teddysun.com/486.html and contact."
  900. install_cleanup
  901. exit 1
  902. fi
  903. }
  904. install_shadowsocks_libev_obfs() {
  905. if [ "${libev_obfs}" == "y" ] || [ "${libev_obfs}" == "Y" ]; then
  906. cd ${cur_dir}
  907. git clone https://github.com/shadowsocks/simple-obfs.git
  908. cd simple-obfs
  909. git submodule update --init --recursive
  910. ./autogen.sh
  911. ./configure --disable-documentation
  912. make
  913. make install
  914. if [ ! "$(command -v obfs-server)" ]; then
  915. echo -e "[${red}Error${plain}] simple-obfs for ${software[${selected}-1]} install failed."
  916. echo "Please visit: https://teddysun.com/486.html and contact."
  917. install_cleanup
  918. exit 1
  919. fi
  920. [ -f /usr/local/bin/obfs-server ] && ln -s /usr/local/bin/obfs-server /usr/bin
  921. fi
  922. }
  923. install_completed_python() {
  924. clear
  925. ${shadowsocks_python_init} start
  926. echo
  927. echo -e "Congratulations, ${green}${software[0]}${plain} server install completed!"
  928. echo -e "Your Server IP : ${red} $(get_ip) ${plain}"
  929. echo -e "Your Server Port : ${red} ${shadowsocksport} ${plain}"
  930. echo -e "Your Password : ${red} ${shadowsockspwd} ${plain}"
  931. echo -e "Your Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  932. }
  933. install_completed_r() {
  934. clear
  935. ${shadowsocks_r_init} start
  936. echo
  937. echo -e "Congratulations, ${green}${software[1]}${plain} server install completed!"
  938. echo -e "Your Server IP : ${red} $(get_ip) ${plain}"
  939. echo -e "Your Server Port : ${red} ${shadowsocksport} ${plain}"
  940. echo -e "Your Password : ${red} ${shadowsockspwd} ${plain}"
  941. echo -e "Your Protocol : ${red} ${shadowsockprotocol} ${plain}"
  942. echo -e "Your obfs : ${red} ${shadowsockobfs} ${plain}"
  943. echo -e "Your Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  944. }
  945. install_completed_go() {
  946. clear
  947. ${shadowsocks_go_init} start
  948. echo
  949. echo -e "Congratulations, ${green}${software[2]}${plain} server install completed!"
  950. echo -e "Your Server IP : ${red} $(get_ip) ${plain}"
  951. echo -e "Your Server Port : ${red} ${shadowsocksport} ${plain}"
  952. echo -e "Your Password : ${red} ${shadowsockspwd} ${plain}"
  953. echo -e "Your Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  954. }
  955. install_completed_libev() {
  956. clear
  957. ldconfig
  958. ${shadowsocks_libev_init} start
  959. echo
  960. echo -e "Congratulations, ${green}${software[3]}${plain} server install completed!"
  961. echo -e "Your Server IP : ${red} $(get_ip) ${plain}"
  962. echo -e "Your Server Port : ${red} ${shadowsocksport} ${plain}"
  963. echo -e "Your Password : ${red} ${shadowsockspwd} ${plain}"
  964. if [ "$(command -v obfs-server)" ]; then
  965. echo -e "Your obfs : ${red} ${shadowsocklibev_obfs} ${plain}"
  966. fi
  967. echo -e "Your Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  968. }
  969. qr_generate_python() {
  970. if [ "$(command -v qrencode)" ]; then
  971. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  972. local qr_code="ss://${tmp}"
  973. echo
  974. echo "Your QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  975. echo -e "${green} ${qr_code} ${plain}"
  976. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_python_qr.png
  977. echo "Your QR Code has been saved as a PNG file path:"
  978. echo -e "${green} ${cur_dir}/shadowsocks_python_qr.png ${plain}"
  979. fi
  980. }
  981. qr_generate_r() {
  982. if [ "$(command -v qrencode)" ]; then
  983. local tmp1=$(echo -n "${shadowsockspwd}" | base64 -w0 | sed 's/=//g;s/\//_/g;s/+/-/g')
  984. local tmp2=$(echo -n "$(get_ip):${shadowsocksport}:${shadowsockprotocol}:${shadowsockscipher}:${shadowsockobfs}:${tmp1}/?obfsparam=" | base64 -w0)
  985. local qr_code="ssr://${tmp2}"
  986. echo
  987. echo "Your QR Code: (For ShadowsocksR Windows, Android clients only)"
  988. echo -e "${green} ${qr_code} ${plain}"
  989. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_r_qr.png
  990. echo "Your QR Code has been saved as a PNG file path:"
  991. echo -e "${green} ${cur_dir}/shadowsocks_r_qr.png ${plain}"
  992. fi
  993. }
  994. qr_generate_go() {
  995. if [ "$(command -v qrencode)" ]; then
  996. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  997. local qr_code="ss://${tmp}"
  998. echo
  999. echo "Your QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  1000. echo -e "${green} ${qr_code} ${plain}"
  1001. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_go_qr.png
  1002. echo "Your QR Code has been saved as a PNG file path:"
  1003. echo -e "${green} ${cur_dir}/shadowsocks_go_qr.png ${plain}"
  1004. fi
  1005. }
  1006. qr_generate_libev() {
  1007. if [ "$(command -v qrencode)" ]; then
  1008. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  1009. local qr_code="ss://${tmp}"
  1010. echo
  1011. echo "Your QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  1012. echo -e "${green} ${qr_code} ${plain}"
  1013. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_libev_qr.png
  1014. echo "Your QR Code has been saved as a PNG file path:"
  1015. echo -e "${green} ${cur_dir}/shadowsocks_libev_qr.png ${plain}"
  1016. fi
  1017. }
  1018. install_main(){
  1019. install_libsodium
  1020. if ! ldconfig -p | grep -wq "/usr/lib"; then
  1021. echo "/usr/lib" > /etc/ld.so.conf.d/lib.conf
  1022. fi
  1023. ldconfig
  1024. if [ "${selected}" == "1" ]; then
  1025. install_shadowsocks_python
  1026. install_completed_python
  1027. qr_generate_python
  1028. elif [ "${selected}" == "2" ]; then
  1029. install_shadowsocks_r
  1030. install_completed_r
  1031. qr_generate_r
  1032. elif [ "${selected}" == "3" ]; then
  1033. install_shadowsocks_go
  1034. install_completed_go
  1035. qr_generate_go
  1036. elif [ "${selected}" == "4" ]; then
  1037. install_mbedtls
  1038. install_shadowsocks_libev
  1039. install_shadowsocks_libev_obfs
  1040. install_completed_libev
  1041. qr_generate_libev
  1042. fi
  1043. echo
  1044. echo "Welcome to visit: https://teddysun.com/486.html"
  1045. echo "Enjoy it!"
  1046. echo
  1047. }
  1048. install_cleanup(){
  1049. cd ${cur_dir}
  1050. rm -rf simple-obfs
  1051. rm -rf ${libsodium_file} ${libsodium_file}.tar.gz
  1052. rm -rf ${mbedtls_file} ${mbedtls_file}-gpl.tgz
  1053. rm -rf ${shadowsocks_python_file} ${shadowsocks_python_file}.zip
  1054. rm -rf ${shadowsocks_r_file} ${shadowsocks_r_file}.tar.gz
  1055. rm -rf ${shadowsocks_go_file_64}.gz ${shadowsocks_go_file_32}.gz
  1056. rm -rf ${shadowsocks_libev_file} ${shadowsocks_libev_file}.tar.gz
  1057. }
  1058. install_shadowsocks(){
  1059. disable_selinux
  1060. install_select
  1061. install_prepare
  1062. install_dependencies
  1063. download_files
  1064. config_shadowsocks
  1065. if check_sys packageManager yum; then
  1066. config_firewall
  1067. fi
  1068. install_main
  1069. install_cleanup
  1070. }
  1071. uninstall_shadowsocks_python() {
  1072. printf "Are you sure uninstall ${red}${software[0]}${plain}? [y/n]\n"
  1073. read -p "(default: n):" answer
  1074. [ -z ${answer} ] && answer="n"
  1075. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1076. ${shadowsocks_python_init} status > /dev/null 2>&1
  1077. if [ $? -eq 0 ]; then
  1078. ${shadowsocks_python_init} stop
  1079. fi
  1080. local service_name=$(basename ${shadowsocks_python_init})
  1081. if check_sys packageManager yum; then
  1082. chkconfig --del ${service_name}
  1083. elif check_sys packageManager apt; then
  1084. update-rc.d -f ${service_name} remove
  1085. fi
  1086. rm -fr $(dirname ${shadowsocks_python_config})
  1087. rm -f ${shadowsocks_python_init}
  1088. rm -f /var/log/shadowsocks.log
  1089. if [ -f /usr/local/shadowsocks_python.log ]; then
  1090. cat /usr/local/shadowsocks_python.log | xargs rm -rf
  1091. rm -f /usr/local/shadowsocks_python.log
  1092. fi
  1093. echo -e "[${green}Info${plain}] ${software[0]} uninstall success"
  1094. else
  1095. echo
  1096. echo -e "[${green}Info${plain}] ${software[0]} uninstall cancelled, nothing to do..."
  1097. echo
  1098. fi
  1099. }
  1100. uninstall_shadowsocks_r() {
  1101. printf "Are you sure uninstall ${red}${software[1]}${plain}? [y/n]\n"
  1102. read -p "(default: n):" answer
  1103. [ -z ${answer} ] && answer="n"
  1104. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1105. ${shadowsocks_r_init} status > /dev/null 2>&1
  1106. if [ $? -eq 0 ]; then
  1107. ${shadowsocks_r_init} stop
  1108. fi
  1109. local service_name=$(basename ${shadowsocks_r_init})
  1110. if check_sys packageManager yum; then
  1111. chkconfig --del ${service_name}
  1112. elif check_sys packageManager apt; then
  1113. update-rc.d -f ${service_name} remove
  1114. fi
  1115. rm -fr $(dirname ${shadowsocks_r_config})
  1116. rm -f ${shadowsocks_r_init}
  1117. rm -f /var/log/shadowsocks.log
  1118. rm -fr /usr/local/shadowsocks
  1119. echo -e "[${green}Info${plain}] ${software[1]} uninstall success"
  1120. else
  1121. echo
  1122. echo -e "[${green}Info${plain}] ${software[1]} uninstall cancelled, nothing to do..."
  1123. echo
  1124. fi
  1125. }
  1126. uninstall_shadowsocks_go() {
  1127. printf "Are you sure uninstall ${red}${software[2]}${plain}? [y/n]\n"
  1128. read -p "(default: n):" answer
  1129. [ -z ${answer} ] && answer="n"
  1130. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1131. ${shadowsocks_go_init} status > /dev/null 2>&1
  1132. if [ $? -eq 0 ]; then
  1133. ${shadowsocks_go_init} stop
  1134. fi
  1135. local service_name=$(basename ${shadowsocks_go_init})
  1136. if check_sys packageManager yum; then
  1137. chkconfig --del ${service_name}
  1138. elif check_sys packageManager apt; then
  1139. update-rc.d -f ${service_name} remove
  1140. fi
  1141. rm -fr $(dirname ${shadowsocks_go_config})
  1142. rm -f ${shadowsocks_go_init}
  1143. rm -f /usr/bin/shadowsocks-server
  1144. echo -e "[${green}Info${plain}] ${software[2]} uninstall success"
  1145. else
  1146. echo
  1147. echo -e "[${green}Info${plain}] ${software[2]} uninstall cancelled, nothing to do..."
  1148. echo
  1149. fi
  1150. }
  1151. uninstall_shadowsocks_libev() {
  1152. printf "Are you sure uninstall ${red}${software[3]}${plain}? [y/n]\n"
  1153. read -p "(default: n):" answer
  1154. [ -z ${answer} ] && answer="n"
  1155. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1156. ${shadowsocks_libev_init} status > /dev/null 2>&1
  1157. if [ $? -eq 0 ]; then
  1158. ${shadowsocks_libev_init} stop
  1159. fi
  1160. local service_name=$(basename ${shadowsocks_libev_init})
  1161. if check_sys packageManager yum; then
  1162. chkconfig --del ${service_name}
  1163. elif check_sys packageManager apt; then
  1164. update-rc.d -f ${service_name} remove
  1165. fi
  1166. rm -fr $(dirname ${shadowsocks_libev_config})
  1167. rm -f /usr/local/bin/ss-local
  1168. rm -f /usr/local/bin/ss-tunnel
  1169. rm -f /usr/local/bin/ss-server
  1170. rm -f /usr/local/bin/ss-manager
  1171. rm -f /usr/local/bin/ss-redir
  1172. rm -f /usr/local/bin/ss-nat
  1173. rm -f /usr/local/bin/obfs-local
  1174. rm -f /usr/local/bin/obfs-server
  1175. rm -f /usr/local/lib/libshadowsocks-libev.a
  1176. rm -f /usr/local/lib/libshadowsocks-libev.la
  1177. rm -f /usr/local/include/shadowsocks.h
  1178. rm -f /usr/local/lib/pkgconfig/shadowsocks-libev.pc
  1179. rm -f /usr/local/share/man/man1/ss-local.1
  1180. rm -f /usr/local/share/man/man1/ss-tunnel.1
  1181. rm -f /usr/local/share/man/man1/ss-server.1
  1182. rm -f /usr/local/share/man/man1/ss-manager.1
  1183. rm -f /usr/local/share/man/man1/ss-redir.1
  1184. rm -f /usr/local/share/man/man1/ss-nat.1
  1185. rm -f /usr/local/share/man/man8/shadowsocks-libev.8
  1186. rm -fr /usr/local/share/doc/shadowsocks-libev
  1187. rm -f ${shadowsocks_libev_init}
  1188. echo -e "[${green}Info${plain}] ${software[3]} uninstall success"
  1189. else
  1190. echo
  1191. echo -e "[${green}Info${plain}] ${software[3]} uninstall cancelled, nothing to do..."
  1192. echo
  1193. fi
  1194. }
  1195. uninstall_shadowsocks() {
  1196. while true
  1197. do
  1198. echo "Which Shadowsocks server you want to uninstall?"
  1199. for ((i=1;i<=${#software[@]};i++ )); do
  1200. hint="${software[$i-1]}"
  1201. echo -e "${green}${i}${plain}) ${hint}"
  1202. done
  1203. read -p "Please enter a number [1-4]:" un_select
  1204. case "${un_select}" in
  1205. 1|2|3|4)
  1206. echo
  1207. echo "You choose = ${software[${un_select}-1]}"
  1208. echo
  1209. break
  1210. ;;
  1211. *)
  1212. echo -e "[${red}Error${plain}] Please only enter a number [1-4]"
  1213. ;;
  1214. esac
  1215. done
  1216. if [ "${un_select}" == "1" ]; then
  1217. if [ -f ${shadowsocks_python_init} ]; then
  1218. uninstall_shadowsocks_python
  1219. else
  1220. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1221. echo
  1222. exit 1
  1223. fi
  1224. elif [ "${un_select}" == "2" ]; then
  1225. if [ -f ${shadowsocks_r_init} ]; then
  1226. uninstall_shadowsocks_r
  1227. else
  1228. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1229. echo
  1230. exit 1
  1231. fi
  1232. elif [ "${un_select}" == "3" ]; then
  1233. if [ -f ${shadowsocks_go_init} ]; then
  1234. uninstall_shadowsocks_go
  1235. else
  1236. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1237. echo
  1238. exit 1
  1239. fi
  1240. elif [ "${un_select}" == "4" ]; then
  1241. if [ -f ${shadowsocks_libev_init} ]; then
  1242. uninstall_shadowsocks_libev
  1243. else
  1244. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1245. echo
  1246. exit 1
  1247. fi
  1248. fi
  1249. }
  1250. # Initialization step
  1251. action=$1
  1252. [ -z $1 ] && action=install
  1253. case "$action" in
  1254. install|uninstall)
  1255. ${action}_shadowsocks
  1256. ;;
  1257. *)
  1258. echo "Arguments error! [${action}]"
  1259. echo "Usage: `basename $0` [install|uninstall]"
  1260. ;;
  1261. esac