vicf

install

Jan 3rd, 2019
1,352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.30 KB | None | 0 0
  1. #! /bin/sh
  2. # $PROG: semi-automatic shell script for installing shadowsocks-libev server on asus router.
  3. # $REQUIRE: Asuswrt-merlin installed and entware-ng is installed on /mnt/sda1
  4. # assume router's DDNS service is active
  5. # Tested on asus RT-AC68U powered by asuswrt-merlin version 384_2
  6. # No guarantee & responsibility to the author. Use at your own risk.
  7.  
  8. # pick server port from 17900 - 17999 randomly
  9. server_port="179$(head -n 30 /dev/urandom | tr -dc "0123456789" | head -c2)"
  10.  
  11. # generate password
  12. ss_passwd=$(openssl rand -base64 32 | tr -d '+/0oO' | cut -c5-14)
  13.  
  14. RET=0
  15. myip=$(curl -4 ifconfig.co)
  16. url="https://pastebin.com/raw/PehUx1qY"
  17. url2="https://pastebin.com/raw/jfKPER4R"
  18. config="shadowsocks.json"
  19.  
  20. opkg install haveged
  21. opkg install shadowsocks-libev-ss-server
  22.  
  23. if [ x$(which dos2unix) = x ] ; then
  24.         opkg install dos2unix
  25. fi
  26.  
  27. cd /jffs/scripts || {
  28.         echo "Cannot change path to /jffs/scripts" ;
  29.         echo "Exit install progress." ;
  30.         exit 1 ;
  31. }
  32.  
  33. if [ -f "firewall-start" ] ; then
  34.         echo "iptables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
  35.         echo "iptables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
  36.         echo "ip6tables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
  37.         echo "ip6tables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
  38. else
  39.         echo "#! /bin/sh" > firewall-start
  40.         echo "iptables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
  41.         echo "iptables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
  42.         echo "ip6tables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
  43.         echo "ip6tables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
  44. fi
  45.  
  46. chmod 755 firewall-start
  47.  
  48. echo "/jffs/scripts/haveged-init start" >> services-start
  49. echo "/jffs/scripts/ss-init start" >> services-start
  50. echo "/jffs/scripts/haveged-init stop" >> services-stop
  51. echo "/jffs/scripts/ss-init stop" >> services-stop
  52.  
  53. wget --no-check-certificate -qO haveged-init "$url2" && dos2unix haveged-init && chmod 755 haveged-init
  54. wget --no-check-certificate -qO ss-init "$url" && dos2unix ss-init && chmod 755 ss-init
  55.  
  56. cd /mnt/sda1/entware/etc || { echo "Fail change path /mnt/sda1/entware/etc/" ; exit 1 ; }
  57.  
  58. echo "{" > "$config"
  59. echo "    \"server\":\"0.0.0.0\"," >> "$config"
  60. echo "    \"server_port\":${server_port}," >> "$config"
  61. echo "    \"local_port\":1080," >> "$config"
  62. echo "    \"password\":\"${ss_passwd}\"," >> "$config"
  63. echo "    \"timeout\":60," >> "$config"
  64. echo "    \"method\":\"chacha20-ietf-poly1305\"" >> "$config"
  65. echo "}" >> "$config"
  66.  
  67. /jffs/scripts/firewall-start ; sleep 1
  68.  
  69. /jffs/scripts/haveged-init start ; sleep 1
  70.  
  71. /jffs/scripts/ss-init start ; sleep 1
  72.  
  73. ss_id=$(ps w | awk '$5 ~ /ss-server/{print $1}')
  74.  
  75. if [ -n "$ss_id" ]
  76.         then
  77.                 echo "Setup is completed."
  78.                 echo "Shadowsocks-libev is up."
  79.                 echo "Your IP:          $myip"
  80.                 echo "Server Port:      $server_port"
  81.                 echo "Password:         $ss_passwd"
  82.                 echo "Method:           chacha20-ietf-poly1305"
  83.         else
  84.                 echo "Install shadowsocks-libev server failed."
  85.                 RET=2
  86. fi
  87.  
  88. exit $RET
Add Comment
Please, Sign In to add comment