1
0

Instalador-Shadowsocks-libev.sh 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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-1.0.17"
  37. libsodium_url="https://github.com/jedisct1/libsodium/releases/download/1.0.17/libsodium-1.0.17.tar.gz"
  38. mbedtls_file="mbedtls-2.16.0"
  39. mbedtls_url="https://tls.mbed.org/download/mbedtls-2.16.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.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. selected=4
  554. case "${selected}" in
  555. 1|2|3|4)
  556. msg -bar
  557. echo "Este Proceso instalara: ${software[${selected}-1]}"
  558. echo " ##Este proceso puede demorar unos minutos##"
  559. msg -bar
  560. break
  561. ;;
  562. *)
  563. echo -e "[${red}Error${plain}] Please only enter a number [1-4]"
  564. ;;
  565. esac
  566. done
  567. }
  568. install_prepare_password(){
  569. echo "Por favor, introduzca la contraseña para ${software[${selected}-1]}"
  570. read -p "(Default Contraseña: pro.sshyproxy.xyz):" shadowsockspwd
  571. [ -z "${shadowsockspwd}" ] && shadowsockspwd="pro.sshyproxy.xyz"
  572. msg -bar
  573. echo "Contraseña = ${shadowsockspwd}"
  574. msg -bar
  575. }
  576. install_prepare_port() {
  577. while true
  578. do
  579. dport=$(shuf -i 9000-19999 -n 1)
  580. echo -e "Por favor ingrese un puerto para ${software[${selected}-1]} [1-65535]"
  581. read -p "(Default port: ${dport}):" shadowsocksport
  582. [ -z "${shadowsocksport}" ] && shadowsocksport=${dport}
  583. expr ${shadowsocksport} + 1 &>/dev/null
  584. if [ $? -eq 0 ]; then
  585. if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ] && [ ${shadowsocksport:0:1} != 0 ]; then
  586. msg -bar
  587. echo "Puerto = ${shadowsocksport}"
  588. msg -bar
  589. break
  590. fi
  591. fi
  592. echo -e "[${red}Error${plain}] Please enter a correct number [1-65535]"
  593. done
  594. }
  595. install_prepare_cipher(){
  596. while true
  597. do
  598. echo -e "Por favor seleccione la secuencia de cifrado para ${software[${selected}-1]}:"
  599. msg -bar
  600. if [[ "${selected}" == "1" || "${selected}" == "4" ]]; then
  601. for ((i=1;i<=${#common_ciphers[@]};i++ )); do
  602. hint="${common_ciphers[$i-1]}"
  603. echo -e "${green}${i}${plain}) ${hint}"
  604. done
  605. msg -bar
  606. read -p "¿Qué cifrado elegirías?(Default: ${common_ciphers[0]}):" pick
  607. [ -z "$pick" ] && pick=1
  608. expr ${pick} + 1 &>/dev/null
  609. if [ $? -ne 0 ]; then
  610. echo -e "[${red}Error${plain}] Please enter a number"
  611. continue
  612. fi
  613. if [[ "$pick" -lt 1 || "$pick" -gt ${#common_ciphers[@]} ]]; then
  614. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#common_ciphers[@]}"
  615. continue
  616. fi
  617. shadowsockscipher=${common_ciphers[$pick-1]}
  618. elif [ "${selected}" == "2" ]; then
  619. for ((i=1;i<=${#r_ciphers[@]};i++ )); do
  620. hint="${r_ciphers[$i-1]}"
  621. echo -e "${green}${i}${plain}) ${hint}"
  622. done
  623. msg -bar
  624. read -p "¿Qué cifrado elegirías?(Default: ${r_ciphers[1]}):" pick
  625. [ -z "$pick" ] && pick=2
  626. expr ${pick} + 1 &>/dev/null
  627. if [ $? -ne 0 ]; then
  628. echo -e "[${red}Error${plain}] Please enter a number"
  629. continue
  630. fi
  631. if [[ "$pick" -lt 1 || "$pick" -gt ${#r_ciphers[@]} ]]; then
  632. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#r_ciphers[@]}"
  633. continue
  634. fi
  635. shadowsockscipher=${r_ciphers[$pick-1]}
  636. elif [ "${selected}" == "3" ]; then
  637. for ((i=1;i<=${#go_ciphers[@]};i++ )); do
  638. hint="${go_ciphers[$i-1]}"
  639. echo -e "${green}${i}${plain}) ${hint}"
  640. done
  641. msg -bar
  642. read -p "¿Qué cifrado elegirías?(Default: ${go_ciphers[0]}):" pick
  643. [ -z "$pick" ] && pick=1
  644. expr ${pick} + 1 &>/dev/null
  645. if [ $? -ne 0 ]; then
  646. echo -e "[${red}Error${plain}] Please enter a number"
  647. continue
  648. fi
  649. if [[ "$pick" -lt 1 || "$pick" -gt ${#go_ciphers[@]} ]]; then
  650. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#go_ciphers[@]}"
  651. continue
  652. fi
  653. shadowsockscipher=${go_ciphers[$pick-1]}
  654. fi
  655. msg -bar
  656. echo "Cifrado = ${shadowsockscipher}"
  657. msg -bar
  658. break
  659. done
  660. }
  661. install_prepare_protocol(){
  662. while true
  663. do
  664. echo -e "Please select protocol for ${software[${selected}-1]}:"
  665. for ((i=1;i<=${#protocols[@]};i++ )); do
  666. hint="${protocols[$i-1]}"
  667. echo -e "${green}${i}${plain}) ${hint}"
  668. done
  669. read -p "Which protocol you'd select(Default: ${protocols[0]}):" protocol
  670. [ -z "$protocol" ] && protocol=1
  671. expr ${protocol} + 1 &>/dev/null
  672. if [ $? -ne 0 ]; then
  673. echo -e "[${red}Error${plain}] Please enter a number"
  674. continue
  675. fi
  676. if [[ "$protocol" -lt 1 || "$protocol" -gt ${#protocols[@]} ]]; then
  677. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#protocols[@]}"
  678. continue
  679. fi
  680. shadowsockprotocol=${protocols[$protocol-1]}
  681. echo
  682. echo "protocol = ${shadowsockprotocol}"
  683. echo
  684. break
  685. done
  686. }
  687. install_prepare_obfs(){
  688. while true
  689. do
  690. echo -e "Por favor, seleccione obfs para ${software[${selected}-1]}:"
  691. msg -bar
  692. for ((i=1;i<=${#obfs[@]};i++ )); do
  693. hint="${obfs[$i-1]}"
  694. echo -e "${green}${i}${plain}) ${hint}"
  695. done
  696. msg -bar
  697. read -p "Qué objs elegirías(Default: ${obfs[0]}):" r_obfs
  698. [ -z "$r_obfs" ] && r_obfs=1
  699. expr ${r_obfs} + 1 &>/dev/null
  700. if [ $? -ne 0 ]; then
  701. echo -e "[${red}Error${plain}] Please enter a number"
  702. continue
  703. fi
  704. if [[ "$r_obfs" -lt 1 || "$r_obfs" -gt ${#obfs[@]} ]]; then
  705. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#obfs[@]}"
  706. continue
  707. fi
  708. shadowsockobfs=${obfs[$r_obfs-1]}
  709. echo
  710. echo "obfs = ${shadowsockobfs}"
  711. echo
  712. break
  713. done
  714. }
  715. install_prepare_libev_obfs(){
  716. if autoconf_version || centosversion 6; then
  717. while true
  718. do
  719. echo -e "Quieres instalar simple-obfs para ${software[${selected}-1]}? [y/n]"
  720. read -p "(default: n):" libev_obfs
  721. [ -z "$libev_obfs" ] && libev_obfs=n
  722. case "${libev_obfs}" in
  723. y|Y|n|N)
  724. msg -bar
  725. echo "Tu eliges = ${libev_obfs}"
  726. msg -bar
  727. break
  728. ;;
  729. *)
  730. echo -e "[${red}Error${plain}] Please only enter [y/n]"
  731. ;;
  732. esac
  733. done
  734. if [ "${libev_obfs}" == "y" ] || [ "${libev_obfs}" == "Y" ]; then
  735. while true
  736. do
  737. echo -e "Por favor, seleccione obfs para simple-obfs:"
  738. msg -bar
  739. for ((i=1;i<=${#obfs_libev[@]};i++ )); do
  740. hint="${obfs_libev[$i-1]}"
  741. echo -e "${green}${i}${plain}) ${hint}"
  742. done
  743. msg -bar
  744. read -p "Qué objs elegirías(Default: ${obfs_libev[0]}):" r_libev_obfs
  745. [ -z "$r_libev_obfs" ] && r_libev_obfs=1
  746. expr ${r_libev_obfs} + 1 &>/dev/null
  747. if [ $? -ne 0 ]; then
  748. echo -e "[${red}Error${plain}] Please enter a number"
  749. continue
  750. fi
  751. if [[ "$r_libev_obfs" -lt 1 || "$r_libev_obfs" -gt ${#obfs_libev[@]} ]]; then
  752. echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#obfs_libev[@]}"
  753. continue
  754. fi
  755. shadowsocklibev_obfs=${obfs_libev[$r_libev_obfs-1]}
  756. echo
  757. echo "obfs = ${shadowsocklibev_obfs}"
  758. echo
  759. break
  760. done
  761. fi
  762. else
  763. echo -e "[${green}Info${plain}] autoconf version is less than 2.67, simple-obfs for ${software[${selected}-1]} installation has been skipped"
  764. fi
  765. }
  766. install_prepare(){
  767. if [[ "${selected}" == "1" || "${selected}" == "3" || "${selected}" == "4" ]]; then
  768. install_prepare_password
  769. install_prepare_port
  770. install_prepare_cipher
  771. if [ "${selected}" == "4" ]; then
  772. install_prepare_libev_obfs
  773. fi
  774. elif [ "${selected}" == "2" ]; then
  775. install_prepare_password
  776. install_prepare_port
  777. install_prepare_cipher
  778. install_prepare_protocol
  779. install_prepare_obfs
  780. fi
  781. echo "Presiona cualquier tecla para comenzar...o Presione Ctrl+C para cancelar"
  782. char=`get_char`
  783. }
  784. install_libsodium(){
  785. if [ ! -f /usr/lib/libsodium.a ]; then
  786. cd ${cur_dir}
  787. download "${libsodium_file}.tar.gz" "${libsodium_url}"
  788. tar zxf ${libsodium_file}.tar.gz
  789. cd ${libsodium_file}
  790. ./configure --prefix=/usr && make && make install
  791. if [ $? -ne 0 ]; then
  792. echo -e "[${red}Error${plain}] ${libsodium_file} install failed."
  793. install_cleanup
  794. exit 1
  795. fi
  796. else
  797. echo -e "[${green}Info${plain}] ${libsodium_file} already installed."
  798. fi
  799. }
  800. install_mbedtls(){
  801. if [ ! -f /usr/lib/libmbedtls.a ]; then
  802. cd ${cur_dir}
  803. download "${mbedtls_file}-gpl.tgz" "${mbedtls_url}"
  804. tar xf ${mbedtls_file}-gpl.tgz
  805. cd ${mbedtls_file}
  806. make SHARED=1 CFLAGS=-fPIC
  807. make DESTDIR=/usr install
  808. if [ $? -ne 0 ]; then
  809. echo -e "[${red}Error${plain}] ${mbedtls_file} install failed."
  810. install_cleanup
  811. exit 1
  812. fi
  813. else
  814. echo -e "[${green}Info${plain}] ${mbedtls_file} already installed."
  815. fi
  816. }
  817. install_shadowsocks_python(){
  818. cd ${cur_dir}
  819. unzip -q ${shadowsocks_python_file}.zip
  820. if [ $? -ne 0 ];then
  821. echo -e "[${red}Error${plain}] unzip ${shadowsocks_python_file}.zip failed, please check unzip command."
  822. install_cleanup
  823. exit 1
  824. fi
  825. cd ${shadowsocks_python_file}
  826. python setup.py install --record /usr/local/shadowsocks_python.log
  827. if [ -f /usr/bin/ssserver ] || [ -f /usr/local/bin/ssserver ]; then
  828. chmod +x ${shadowsocks_python_init}
  829. local service_name=$(basename ${shadowsocks_python_init})
  830. if check_sys packageManager yum; then
  831. chkconfig --add ${service_name}
  832. chkconfig ${service_name} on
  833. elif check_sys packageManager apt; then
  834. update-rc.d -f ${service_name} defaults
  835. fi
  836. else
  837. echo
  838. echo -e "[${red}Error${plain}] ${software[0]} install failed."
  839. echo "Please visit: https://teddysun.com/486.html and contact."
  840. install_cleanup
  841. exit 1
  842. fi
  843. }
  844. install_shadowsocks_r(){
  845. cd ${cur_dir}
  846. tar zxf ${shadowsocks_r_file}.tar.gz
  847. mv ${shadowsocks_r_file}/shadowsocks /usr/local/
  848. if [ -f /usr/local/shadowsocks/server.py ]; then
  849. chmod +x ${shadowsocks_r_init}
  850. local service_name=$(basename ${shadowsocks_r_init})
  851. if check_sys packageManager yum; then
  852. chkconfig --add ${service_name}
  853. chkconfig ${service_name} on
  854. elif check_sys packageManager apt; then
  855. update-rc.d -f ${service_name} defaults
  856. fi
  857. else
  858. echo
  859. echo -e "[${red}Error${plain}] ${software[1]} install failed."
  860. echo "Please visit; https://teddysun.com/486.html and contact."
  861. install_cleanup
  862. exit 1
  863. fi
  864. }
  865. install_shadowsocks_go(){
  866. cd ${cur_dir}
  867. if is_64bit; then
  868. gzip -d ${shadowsocks_go_file_64}.gz
  869. if [ $? -ne 0 ];then
  870. echo -e "[${red}Error${plain}] Decompress ${shadowsocks_go_file_64}.gz failed."
  871. install_cleanup
  872. exit 1
  873. fi
  874. mv -f ${shadowsocks_go_file_64} /usr/bin/shadowsocks-server
  875. else
  876. gzip -d ${shadowsocks_go_file_32}.gz
  877. if [ $? -ne 0 ];then
  878. echo -e "[${red}Error${plain}] Decompress ${shadowsocks_go_file_32}.gz failed."
  879. install_cleanup
  880. exit 1
  881. fi
  882. mv -f ${shadowsocks_go_file_32} /usr/bin/shadowsocks-server
  883. fi
  884. if [ -f /usr/bin/shadowsocks-server ]; then
  885. chmod +x /usr/bin/shadowsocks-server
  886. chmod +x ${shadowsocks_go_init}
  887. local service_name=$(basename ${shadowsocks_go_init})
  888. if check_sys packageManager yum; then
  889. chkconfig --add ${service_name}
  890. chkconfig ${service_name} on
  891. elif check_sys packageManager apt; then
  892. update-rc.d -f ${service_name} defaults
  893. fi
  894. else
  895. echo
  896. echo -e "[${red}Error${plain}] ${software[2]} install failed."
  897. echo "Please visit: https://teddysun.com/486.html and contact."
  898. install_cleanup
  899. exit 1
  900. fi
  901. }
  902. install_shadowsocks_libev(){
  903. cd ${cur_dir}
  904. tar zxf ${shadowsocks_libev_file}.tar.gz
  905. cd ${shadowsocks_libev_file}
  906. ./configure --disable-documentation && make && make install
  907. if [ $? -eq 0 ]; then
  908. chmod +x ${shadowsocks_libev_init}
  909. local service_name=$(basename ${shadowsocks_libev_init})
  910. if check_sys packageManager yum; then
  911. chkconfig --add ${service_name}
  912. chkconfig ${service_name} on
  913. elif check_sys packageManager apt; then
  914. update-rc.d -f ${service_name} defaults
  915. fi
  916. else
  917. echo
  918. echo -e "[${red}Error${plain}] ${software[3]} install failed."
  919. echo "Please visit: https://teddysun.com/486.html and contact."
  920. install_cleanup
  921. exit 1
  922. fi
  923. }
  924. install_shadowsocks_libev_obfs(){
  925. if [ "${libev_obfs}" == "y" ] || [ "${libev_obfs}" == "Y" ]; then
  926. cd ${cur_dir}
  927. git clone https://github.com/shadowsocks/simple-obfs.git
  928. [ -d simple-obfs ] && cd simple-obfs || echo -e "[${red}Error:${plain}] Failed to git clone simple-obfs."
  929. git submodule update --init --recursive
  930. if centosversion 6; then
  931. if [ ! "$(command -v autoconf268)" ]; then
  932. echo -e "[${green}Info${plain}] Starting install autoconf268..."
  933. yum install -y autoconf268 > /dev/null 2>&1 || echo -e "[${red}Error:${plain}] Failed to install autoconf268."
  934. fi
  935. # replace command autoreconf to autoreconf268
  936. sed -i 's/autoreconf/autoreconf268/' autogen.sh
  937. # replace #include <ev.h> to #include <libev/ev.h>
  938. sed -i 's@^#include <ev.h>@#include <libev/ev.h>@' src/local.h
  939. sed -i 's@^#include <ev.h>@#include <libev/ev.h>@' src/server.h
  940. fi
  941. ./autogen.sh
  942. ./configure --disable-documentation
  943. make
  944. make install
  945. if [ ! "$(command -v obfs-server)" ]; then
  946. echo -e "[${red}Error${plain}] simple-obfs for ${software[${selected}-1]} install failed."
  947. echo "Please visit: https://teddysun.com/486.html and contact."
  948. install_cleanup
  949. exit 1
  950. fi
  951. [ -f /usr/local/bin/obfs-server ] && ln -s /usr/local/bin/obfs-server /usr/bin
  952. fi
  953. }
  954. install_completed_python(){
  955. clear
  956. ${shadowsocks_python_init} start
  957. msg -bar
  958. echo -e "Felicidades, ${green}${software[0]}${plain} instalación del servidor completada!"
  959. echo -e "Tu Server IP : ${red} $(get_ip) ${plain}"
  960. echo -e "Tu Server Port : ${red} ${shadowsocksport} ${plain}"
  961. echo -e "Tu Password : ${red} ${shadowsockspwd} ${plain}"
  962. echo -e "Tu Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  963. }
  964. install_completed_r(){
  965. clear
  966. ${shadowsocks_r_init} start
  967. msg -bar
  968. echo -e "Felicidades, ${green}${software[1]}${plain} instalación del servidor completada!"
  969. echo -e "Tu Server IP : ${red} $(get_ip) ${plain}"
  970. echo -e "Tu Server Port : ${red} ${shadowsocksport} ${plain}"
  971. echo -e "Tu Password : ${red} ${shadowsockspwd} ${plain}"
  972. echo -e "Tu Protocol : ${red} ${shadowsockprotocol} ${plain}"
  973. echo -e "Tu obfs : ${red} ${shadowsockobfs} ${plain}"
  974. echo -e "Tu Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  975. }
  976. install_completed_go(){
  977. clear
  978. ${shadowsocks_go_init} start
  979. msg -bar
  980. echo -e "Felicidades, ${green}${software[2]}${plain} instalación del servidor completada!"
  981. echo -e "Tu Server IP : ${red} $(get_ip) ${plain}"
  982. echo -e "Tu Server Port : ${red} ${shadowsocksport} ${plain}"
  983. echo -e "Tu Password : ${red} ${shadowsockspwd} ${plain}"
  984. echo -e "Tu Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  985. }
  986. install_completed_libev(){
  987. clear
  988. ldconfig
  989. ${shadowsocks_libev_init} start
  990. msg -bar
  991. echo -e "Felicidades, ${green}${software[3]}${plain} instalación del servidor completada!"
  992. echo -e "Tu Server IP : ${red} $(get_ip) ${plain}"
  993. echo -e "Tu Server Port : ${red} ${shadowsocksport} ${plain}"
  994. echo -e "Tu Password : ${red} ${shadowsockspwd} ${plain}"
  995. if [ "$(command -v obfs-server)" ]; then
  996. echo -e "Tu obfs : ${red} ${shadowsocklibev_obfs} ${plain}"
  997. fi
  998. echo -e "Tu Encryption Method: ${red} ${shadowsockscipher} ${plain}"
  999. }
  1000. qr_generate_python(){
  1001. if [ "$(command -v qrencode)" ]; then
  1002. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  1003. local qr_code="ss://${tmp}"
  1004. echo
  1005. echo "Tu QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  1006. echo -e "${green} ${qr_code} ${plain}"
  1007. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_python_qr.png
  1008. echo "Tu QR Code has been saved as a PNG file path:"
  1009. echo -e "${green} ${cur_dir}/shadowsocks_python_qr.png ${plain}"
  1010. fi
  1011. }
  1012. qr_generate_r(){
  1013. if [ "$(command -v qrencode)" ]; then
  1014. local tmp1=$(echo -n "${shadowsockspwd}" | base64 -w0 | sed 's/=//g;s/\//_/g;s/+/-/g')
  1015. local tmp2=$(echo -n "$(get_ip):${shadowsocksport}:${shadowsockprotocol}:${shadowsockscipher}:${shadowsockobfs}:${tmp1}/?obfsparam=" | base64 -w0)
  1016. local qr_code="ssr://${tmp2}"
  1017. echo
  1018. echo "Tu QR Code: (For ShadowsocksR Windows, Android clients only)"
  1019. echo -e "${green} ${qr_code} ${plain}"
  1020. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_r_qr.png
  1021. echo "Tu QR Code has been saved as a PNG file path:"
  1022. echo -e "${green} ${cur_dir}/shadowsocks_r_qr.png ${plain}"
  1023. fi
  1024. }
  1025. qr_generate_go(){
  1026. if [ "$(command -v qrencode)" ]; then
  1027. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  1028. local qr_code="ss://${tmp}"
  1029. echo
  1030. echo "Tu QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  1031. echo -e "${green} ${qr_code} ${plain}"
  1032. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_go_qr.png
  1033. echo "Tu QR Code has been saved as a PNG file path:"
  1034. echo -e "${green} ${cur_dir}/shadowsocks_go_qr.png ${plain}"
  1035. fi
  1036. }
  1037. qr_generate_libev(){
  1038. if [ "$(command -v qrencode)" ]; then
  1039. local tmp=$(echo -n "${shadowsockscipher}:${shadowsockspwd}@$(get_ip):${shadowsocksport}" | base64 -w0)
  1040. local qr_code="ss://${tmp}"
  1041. echo
  1042. echo "Tu QR Code: (For Shadowsocks Windows, OSX, Android and iOS clients)"
  1043. echo -e "${green} ${qr_code} ${plain}"
  1044. echo -n "${qr_code}" | qrencode -s8 -o ${cur_dir}/shadowsocks_libev_qr.png
  1045. echo "Tu QR Code has been saved as a PNG file path:"
  1046. echo -e "${green} ${cur_dir}/shadowsocks_libev_qr.png ${plain}"
  1047. fi
  1048. }
  1049. install_main(){
  1050. install_libsodium
  1051. if ! ldconfig -p | grep -wq "/usr/lib"; then
  1052. echo "/usr/lib" > /etc/ld.so.conf.d/lib.conf
  1053. fi
  1054. ldconfig
  1055. if [ "${selected}" == "1" ]; then
  1056. install_shadowsocks_python
  1057. install_completed_python
  1058. qr_generate_python
  1059. elif [ "${selected}" == "2" ]; then
  1060. install_shadowsocks_r
  1061. install_completed_r
  1062. qr_generate_r
  1063. elif [ "${selected}" == "3" ]; then
  1064. install_shadowsocks_go
  1065. install_completed_go
  1066. qr_generate_go
  1067. elif [ "${selected}" == "4" ]; then
  1068. install_mbedtls
  1069. install_shadowsocks_libev
  1070. install_shadowsocks_libev_obfs
  1071. install_completed_libev
  1072. qr_generate_libev
  1073. fi
  1074. echo
  1075. echo "Visite: https://pro.sshyproxy.xyz"
  1076. echo
  1077. }
  1078. install_cleanup(){
  1079. cd ${cur_dir}
  1080. rm -rf simple-obfs
  1081. rm -rf ${libsodium_file} ${libsodium_file}.tar.gz
  1082. rm -rf ${mbedtls_file} ${mbedtls_file}-gpl.tgz
  1083. rm -rf ${shadowsocks_python_file} ${shadowsocks_python_file}.zip
  1084. rm -rf ${shadowsocks_r_file} ${shadowsocks_r_file}.tar.gz
  1085. rm -rf ${shadowsocks_go_file_64}.gz ${shadowsocks_go_file_32}.gz
  1086. rm -rf ${shadowsocks_libev_file} ${shadowsocks_libev_file}.tar.gz
  1087. }
  1088. install_shadowsocks(){
  1089. disable_selinux
  1090. install_select
  1091. install_prepare
  1092. install_dependencies
  1093. download_files
  1094. config_shadowsocks
  1095. if check_sys packageManager yum; then
  1096. config_firewall
  1097. fi
  1098. install_main
  1099. install_cleanup
  1100. }
  1101. uninstall_shadowsocks_python(){
  1102. printf "Estás seguro de desinstalar ${red}${software[0]}${plain}? [y/n]\n"
  1103. read -p "(default: n):" answer
  1104. [ -z ${answer} ] && answer="n"
  1105. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1106. ${shadowsocks_python_init} status > /dev/null 2>&1
  1107. if [ $? -eq 0 ]; then
  1108. ${shadowsocks_python_init} stop
  1109. fi
  1110. local service_name=$(basename ${shadowsocks_python_init})
  1111. if check_sys packageManager yum; then
  1112. chkconfig --del ${service_name}
  1113. elif check_sys packageManager apt; then
  1114. update-rc.d -f ${service_name} remove
  1115. fi
  1116. rm -fr $(dirname ${shadowsocks_python_config})
  1117. rm -f ${shadowsocks_python_init}
  1118. rm -f /var/log/shadowsocks.log
  1119. if [ -f /usr/local/shadowsocks_python.log ]; then
  1120. cat /usr/local/shadowsocks_python.log | xargs rm -rf
  1121. rm -f /usr/local/shadowsocks_python.log
  1122. fi
  1123. echo -e "[${green}Info${plain}] ${software[0]} uninstall success"
  1124. else
  1125. echo
  1126. echo -e "[${green}Info${plain}] ${software[0]} uninstall cancelled, nothing to do..."
  1127. echo
  1128. fi
  1129. }
  1130. uninstall_shadowsocks_r(){
  1131. printf "Estás seguro de desinstalar ${red}${software[1]}${plain}? [y/n]\n"
  1132. read -p "(default: n):" answer
  1133. [ -z ${answer} ] && answer="n"
  1134. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1135. ${shadowsocks_r_init} status > /dev/null 2>&1
  1136. if [ $? -eq 0 ]; then
  1137. ${shadowsocks_r_init} stop
  1138. fi
  1139. local service_name=$(basename ${shadowsocks_r_init})
  1140. if check_sys packageManager yum; then
  1141. chkconfig --del ${service_name}
  1142. elif check_sys packageManager apt; then
  1143. update-rc.d -f ${service_name} remove
  1144. fi
  1145. rm -fr $(dirname ${shadowsocks_r_config})
  1146. rm -f ${shadowsocks_r_init}
  1147. rm -f /var/log/shadowsocks.log
  1148. rm -fr /usr/local/shadowsocks
  1149. echo -e "[${green}Info${plain}] ${software[1]} uninstall success"
  1150. else
  1151. echo
  1152. echo -e "[${green}Info${plain}] ${software[1]} uninstall cancelled, nothing to do..."
  1153. echo
  1154. fi
  1155. }
  1156. uninstall_shadowsocks_go(){
  1157. printf "Estás seguro de desinstalar ${red}${software[2]}${plain}? [y/n]\n"
  1158. read -p "(default: n):" answer
  1159. [ -z ${answer} ] && answer="n"
  1160. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1161. ${shadowsocks_go_init} status > /dev/null 2>&1
  1162. if [ $? -eq 0 ]; then
  1163. ${shadowsocks_go_init} stop
  1164. fi
  1165. local service_name=$(basename ${shadowsocks_go_init})
  1166. if check_sys packageManager yum; then
  1167. chkconfig --del ${service_name}
  1168. elif check_sys packageManager apt; then
  1169. update-rc.d -f ${service_name} remove
  1170. fi
  1171. rm -fr $(dirname ${shadowsocks_go_config})
  1172. rm -f ${shadowsocks_go_init}
  1173. rm -f /usr/bin/shadowsocks-server
  1174. echo -e "[${green}Info${plain}] ${software[2]} uninstall success"
  1175. else
  1176. echo
  1177. echo -e "[${green}Info${plain}] ${software[2]} uninstall cancelled, nothing to do..."
  1178. echo
  1179. fi
  1180. }
  1181. uninstall_shadowsocks_libev(){
  1182. printf "Estás seguro de desinstalar ${red}${software[3]}${plain}? [y/n]\n"
  1183. read -p "(default: n):" answer
  1184. [ -z ${answer} ] && answer="n"
  1185. if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
  1186. ${shadowsocks_libev_init} status > /dev/null 2>&1
  1187. if [ $? -eq 0 ]; then
  1188. ${shadowsocks_libev_init} stop
  1189. fi
  1190. local service_name=$(basename ${shadowsocks_libev_init})
  1191. if check_sys packageManager yum; then
  1192. chkconfig --del ${service_name}
  1193. elif check_sys packageManager apt; then
  1194. update-rc.d -f ${service_name} remove
  1195. fi
  1196. rm -fr $(dirname ${shadowsocks_libev_config})
  1197. rm -f /usr/local/bin/ss-local
  1198. rm -f /usr/local/bin/ss-tunnel
  1199. rm -f /usr/local/bin/ss-server
  1200. rm -f /usr/local/bin/ss-manager
  1201. rm -f /usr/local/bin/ss-redir
  1202. rm -f /usr/local/bin/ss-nat
  1203. rm -f /usr/local/bin/obfs-local
  1204. rm -f /usr/local/bin/obfs-server
  1205. rm -f /usr/local/lib/libshadowsocks-libev.a
  1206. rm -f /usr/local/lib/libshadowsocks-libev.la
  1207. rm -f /usr/local/include/shadowsocks.h
  1208. rm -f /usr/local/lib/pkgconfig/shadowsocks-libev.pc
  1209. rm -f /usr/local/share/man/man1/ss-local.1
  1210. rm -f /usr/local/share/man/man1/ss-tunnel.1
  1211. rm -f /usr/local/share/man/man1/ss-server.1
  1212. rm -f /usr/local/share/man/man1/ss-manager.1
  1213. rm -f /usr/local/share/man/man1/ss-redir.1
  1214. rm -f /usr/local/share/man/man1/ss-nat.1
  1215. rm -f /usr/local/share/man/man8/shadowsocks-libev.8
  1216. rm -fr /usr/local/share/doc/shadowsocks-libev
  1217. rm -f ${shadowsocks_libev_init}
  1218. echo -e "[${green}Info${plain}] ${software[3]} uninstall success"
  1219. else
  1220. echo
  1221. echo -e "[${green}Info${plain}] ${software[3]} uninstall cancelled, nothing to do..."
  1222. echo
  1223. fi
  1224. }
  1225. uninstall_shadowsocks(){
  1226. while true
  1227. do
  1228. echo "¿Qué servidor de Shadowsocks quieres desinstalar?"
  1229. msg -bar
  1230. for ((i=1;i<=${#software[@]};i++ )); do
  1231. hint="${software[$i-1]}"
  1232. echo -e "${green}${i}${plain}) ${hint}"
  1233. done
  1234. msg -bar
  1235. read -p "Por favor, introduzca un número[1-4]:" un_select
  1236. case "${un_select}" in
  1237. 1|2|3|4)
  1238. msg -bar
  1239. echo "Tu eliges = ${software[${un_select}-1]}"
  1240. msg -bar
  1241. break
  1242. ;;
  1243. *)
  1244. echo -e "[${red}Error${plain}] Please only enter a number [1-4]"
  1245. ;;
  1246. esac
  1247. done
  1248. if [ "${un_select}" == "1" ]; then
  1249. if [ -f ${shadowsocks_python_init} ]; then
  1250. uninstall_shadowsocks_python
  1251. else
  1252. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1253. echo
  1254. exit 1
  1255. fi
  1256. elif [ "${un_select}" == "2" ]; then
  1257. if [ -f ${shadowsocks_r_init} ]; then
  1258. uninstall_shadowsocks_r
  1259. else
  1260. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1261. echo
  1262. exit 1
  1263. fi
  1264. elif [ "${un_select}" == "3" ]; then
  1265. if [ -f ${shadowsocks_go_init} ]; then
  1266. uninstall_shadowsocks_go
  1267. else
  1268. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1269. echo
  1270. exit 1
  1271. fi
  1272. elif [ "${un_select}" == "4" ]; then
  1273. if [ -f ${shadowsocks_libev_init} ]; then
  1274. uninstall_shadowsocks_libev
  1275. else
  1276. echo -e "[${red}Error${plain}] ${software[${un_select}-1]} not installed, please check it and try again."
  1277. echo
  1278. exit 1
  1279. fi
  1280. fi
  1281. }
  1282. # Initialization step
  1283. action=$1
  1284. [ -z $1 ] && action=install
  1285. case "${action}" in
  1286. install|uninstall)
  1287. ${action}_shadowsocks
  1288. ;;
  1289. *)
  1290. echo "Arguments error! [${action}]"
  1291. echo "Usage: $(basename $0) [install|uninstall]"
  1292. ;;
  1293. esac
  1294. echo -e "\E[44;1;37mA SIDO CREADA CON EXITO 0 PARA SALIR\033[0m " "\033[1;33m\033[2;33m\E[41;1;37m[15]-MENU PRINCIPAL\033[0m"
  1295. while [ "$opcion" != "0" ]
  1296. do
  1297. read opcion
  1298. case $opcion in
  1299. 15)/root/menu
  1300. ;;
  1301. esac
  1302. exit
  1303. done