Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- # $PROG: semi-automatic shell script for installing shadowsocks-libev server on asus router.
- # $REQUIRE: Asuswrt-merlin installed and entware-ng is installed on /mnt/sda1
- # assume router's DDNS service is active
- # Tested on asus RT-AC68U powered by asuswrt-merlin version 384_2
- # No guarantee & responsibility to the author. Use at your own risk.
- # pick server port from 17900 - 17999 randomly
- server_port="179$(head -n 30 /dev/urandom | tr -dc "0123456789" | head -c2)"
- # generate password
- ss_passwd=$(openssl rand -base64 32 | tr -d '+/0oO' | cut -c5-14)
- RET=0
- myip=$(curl -4 ifconfig.co)
- url="https://pastebin.com/raw/PehUx1qY"
- url2="https://pastebin.com/raw/jfKPER4R"
- config="shadowsocks.json"
- opkg install haveged
- opkg install shadowsocks-libev-ss-server
- if [ x$(which dos2unix) = x ] ; then
- opkg install dos2unix
- fi
- cd /jffs/scripts || {
- echo "Cannot change path to /jffs/scripts" ;
- echo "Exit install progress." ;
- exit 1 ;
- }
- if [ -f "firewall-start" ] ; then
- echo "iptables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
- echo "iptables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
- echo "ip6tables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
- echo "ip6tables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
- else
- echo "#! /bin/sh" > firewall-start
- echo "iptables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
- echo "iptables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
- echo "ip6tables -I INPUT -p tcp --dport $server_port -j ACCEPT" >> firewall-start
- echo "ip6tables -I INPUT -p udp --dport $server_port -j ACCEPT" >> firewall-start
- fi
- chmod 755 firewall-start
- echo "/jffs/scripts/haveged-init start" >> services-start
- echo "/jffs/scripts/ss-init start" >> services-start
- echo "/jffs/scripts/haveged-init stop" >> services-stop
- echo "/jffs/scripts/ss-init stop" >> services-stop
- wget --no-check-certificate -qO haveged-init "$url2" && dos2unix haveged-init && chmod 755 haveged-init
- wget --no-check-certificate -qO ss-init "$url" && dos2unix ss-init && chmod 755 ss-init
- cd /mnt/sda1/entware/etc || { echo "Fail change path /mnt/sda1/entware/etc/" ; exit 1 ; }
- echo "{" > "$config"
- echo " \"server\":\"0.0.0.0\"," >> "$config"
- echo " \"server_port\":${server_port}," >> "$config"
- echo " \"local_port\":1080," >> "$config"
- echo " \"password\":\"${ss_passwd}\"," >> "$config"
- echo " \"timeout\":60," >> "$config"
- echo " \"method\":\"chacha20-ietf-poly1305\"" >> "$config"
- echo "}" >> "$config"
- /jffs/scripts/firewall-start ; sleep 1
- /jffs/scripts/haveged-init start ; sleep 1
- /jffs/scripts/ss-init start ; sleep 1
- ss_id=$(ps w | awk '$5 ~ /ss-server/{print $1}')
- if [ -n "$ss_id" ]
- then
- echo "Setup is completed."
- echo "Shadowsocks-libev is up."
- echo "Your IP: $myip"
- echo "Server Port: $server_port"
- echo "Password: $ss_passwd"
- echo "Method: chacha20-ietf-poly1305"
- else
- echo "Install shadowsocks-libev server failed."
- RET=2
- fi
- exit $RET
Add Comment
Please, Sign In to add comment