shadowsocks-all.sh 45 KB

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