1
0

shadowsocks.sh 36 KB

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