ssr.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. sh_ver="1.0.26"
  5. filepath=$(cd "$(dirname "$0")"; pwd)
  6. file=$(echo -e "${filepath}"|awk -F "$0" '{print $1}')
  7. ssr_folder="/usr/local/shadowsocksr"
  8. config_file="${ssr_folder}/config.json"
  9. config_user_file="${ssr_folder}/user-config.json"
  10. config_user_api_file="${ssr_folder}/userapiconfig.py"
  11. config_user_mudb_file="${ssr_folder}/mudb.json"
  12. ssr_log_file="${ssr_folder}/ssserver.log"
  13. Libsodiumr_file="/usr/local/lib/libsodium.so"
  14. Libsodiumr_ver_backup="1.0.17"
  15. jq_file="${ssr_folder}/jq"
  16. source /etc/os-release
  17. OS=$ID
  18. ver=$VERSION_ID
  19. Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
  20. Info="${Green_font_prefix}[information]${Font_color_suffix}"
  21. Error="${Red_font_prefix}[error]${Font_color_suffix}"
  22. Tip="${Green_font_prefix}[note]${Font_color_suffix}"
  23. Separator_1="——————————————————————————————"
  24. check_pid(){
  25. PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
  26. }
  27. Add_iptables(){
  28. iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 1443:1543 -j ACCEPT
  29. iptables -I INPUT -m state --state NEW -m udp -p udp --dport 1443:1543 -j ACCEPT
  30. }
  31. Save_iptables(){
  32. if [[ ${OS} == "centos" ]]; then
  33. service iptables save
  34. service ip6tables save
  35. else
  36. iptables-save > /etc/iptables.up.rules
  37. fi
  38. }
  39. Set_iptables(){
  40. if [[ ${OS} == "centos" ]]; then
  41. service iptables save
  42. service ip6tables save
  43. chkconfig --level 2345 iptables on
  44. chkconfig --level 2345 ip6tables on
  45. else
  46. iptables-save > /etc/iptables.up.rules
  47. echo -e '#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules\n/sbin/ip6tables-restore < /etc/ip6tables.up.rules' > /etc/network/if-pre-up.d/iptables
  48. chmod +x /etc/network/if-pre-up.d/iptables
  49. fi
  50. }
  51. Set_user_api_server_pub_addr(){
  52. ip=$(wget -qO- ipv4.icanhazip.com);
  53. ssr_server_pub_addr="${ip}"
  54. }
  55. Modify_user_api_server_pub_addr(){
  56. sed -i "s/SERVER_PUB_ADDR = '${server_pub_addr}'/SERVER_PUB_ADDR = '${ssr_server_pub_addr}'/" ${config_user_api_file}
  57. }
  58. Check_python(){
  59. if [[ ${OS} == "centos" ]]; then
  60. if [[ $ver == '7' ]]; then
  61. yum -y install python
  62. elif [[ $ver == '8' ]]; then
  63. yum install -y python2
  64. alternatives --set python /usr/bin/python2
  65. fi
  66. else
  67. apt-get install -y python
  68. fi
  69. }
  70. Centos_yum(){
  71. yum update
  72. cat /etc/redhat-release |grep 7\..*|grep -i centos>/dev/null
  73. if [[ $? = 0 ]]; then
  74. yum install -y vim unzip crond net-tools git
  75. else
  76. yum install -y vim unzip crond git
  77. fi
  78. }
  79. Debian_apt(){
  80. apt-get update
  81. apt-get install -y vim unzip cron git net-tools
  82. }
  83. Download_SSR(){
  84. cd "/usr/local"
  85. git clone -b akkariiin/master https://github.com/shadowsocksrr/shadowsocksr.git
  86. cd "shadowsocksr"
  87. cp "${ssr_folder}/config.json" "${config_user_file}"
  88. cp "${ssr_folder}/mysql.json" "${ssr_folder}/usermysql.json"
  89. cp "${ssr_folder}/apiconfig.py" "${config_user_api_file}"
  90. sed -i "s/API_INTERFACE = 'sspanelv2'/API_INTERFACE = 'mudbjson'/" ${config_user_api_file}
  91. server_pub_addr="127.0.0.1"
  92. Modify_user_api_server_pub_addr
  93. sed -i 's/ \/\/ only works under multi-user mode//g' "${config_user_file}"
  94. }
  95. Service_SSR(){
  96. if [[ ${OS} = "centos" ]]; then
  97. wget --no-check-certificate https://raw.githubusercontent.com/hybtoy/ssrrmu/master/ssrmu_centos -O /etc/init.d/ssrmu
  98. chmod +x /etc/init.d/ssrmu
  99. chkconfig --add ssrmu
  100. chkconfig ssrmu on
  101. else
  102. wget --no-check-certificate https://raw.githubusercontent.com/hybtoy/ssrrmu/master/ssrmu_debian -O /etc/init.d/ssrmu
  103. chmod +x /etc/init.d/ssrmu
  104. update-rc.d -f ssrmu defaults
  105. fi
  106. }
  107. JQ_install(){
  108. cd "${ssr_folder}"
  109. wget --no-check-certificate "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file}
  110. chmod +x ${jq_file}
  111. }
  112. Installation_dependency(){
  113. if [[ ${OS} == "centos" ]]; then
  114. Centos_yum
  115. service crond restart
  116. else
  117. Debian_apt
  118. /etc/init.d/cron restart
  119. fi
  120. }
  121. Start_SSR(){
  122. check_pid
  123. wget -O /etc/init.d/ssrmu "https://raw.githubusercontent.com/senowahyu62/freesc/main/ssrmu"
  124. /etc/init.d/ssrmu start
  125. }
  126. Install_SSR(){
  127. Set_user_api_server_pub_addr
  128. Check_python
  129. Installation_dependency
  130. Download_SSR
  131. Service_SSR
  132. JQ_install
  133. Set_iptables
  134. Add_iptables
  135. Save_iptables
  136. Start_SSR
  137. }
  138. Install_SSR
  139. wget -O /usr/bin/ssr https://raw.githubusercontent.com/senowahyu62/freesc/main/ssrmu.sh && chmod +x /usr/bin/ssr
  140. wget -O /usr/bin/add-ssr https://raw.githubusercontent.com/senowahyu62/freesc/main/add-ssr.sh && chmod +x /usr/bin/add-ssr
  141. wget -O /usr/bin/del-ssr https://raw.githubusercontent.com/senowahyu62/freesc/main/del-ssr.sh && chmod +x /usr/bin/del-ssr
  142. wget -O /usr/bin/renew-ssr https://raw.githubusercontent.com/senowahyu62/freesc/main/renew-ssr.sh && chmod +x /usr/bin/renew-ssr
  143. touch /usr/local/shadowsocksr/akun.conf
  144. rm -f /root/ssr.sh