#!/bin/bash
function v2boot(){
	echo "v2 Boot install";
	#check wether vps suppot ppp and tun
	cd /etc/init.d/
	rm -f v2
	wget www.xuanlove.download/ss/v2
	chmod +x /etc/init.d/v2
	chkconfig --add v2
	chkconfig v2 on
	/etc/init.d/v2 start
	echo "v2 Boot Ok"
}
function installiptables(){
	echo "SS install";
	#check wether vps suppot ppp and tun	
	systemctl stop firewalld.service
	systemctl disable firewalld.service
	iptables -A OUTPUT -p 25 -j DROP
	iptables -A INPUT -p tcp --dport 600:2000 -j ACCEPT
	iptables -A OUTPUT -p tcp --sport 600:2000 -j ACCEPT
	iptables -A INPUT -p tcp --dport 20000:50000 -j ACCEPT
	iptables -A OUTPUT -p tcp --sport 20000:50000 -j ACCEPT
	service iptables save
	chkconfig iptables on
	service iptables start
	echo "SS iptables Ok"
	
}
function installSP(){
	echo "SS install";
	#check wether vps suppot ppp and tun
	cp /etc/sysctl.conf /root/
	echo "* soft nproc 11000" >> /etc/security/limits.conf
	echo "* hard nproc 11000" >> /etc/security/limits.conf
	echo "* soft nofile 655350" >> /etc/security/limits.conf
	echo "* hard nofile 655350" >> /etc/security/limits.conf
	echo "fs.file-max = 51200" >> /etc/sysctl.conf
	echo "" >> /etc/sysctl.conf
	echo "net.core.rmem_max = 67108864" >> /etc/sysctl.conf
	echo "net.core.wmem_max = 67108864" >> /etc/sysctl.conf
	echo "net.core.netdev_max_backlog = 250000" >> /etc/sysctl.conf
	echo "net.core.somaxconn = 4096" >> /etc/sysctl.conf
	echo "" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_syncookies = 1" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_tw_recycle = 0" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_keepalive_time = 1200" >> /etc/sysctl.conf
	echo "net.ipv4.ip_local_port_range = 10000 65000" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_max_syn_backlog = 8192" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_max_tw_buckets = 5000" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_rmem = 4096 87380 67108864" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_wmem = 4096 65536 67108864" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_mtu_probing = 1" >> /etc/sysctl.conf
	echo "net.ipv4.tcp_congestion_control = hybla" >> /etc/sysctl.conf
	/sbin/modprobe tcp_hybla
	sysctl net.ipv4.tcp_available_congestion_control
	sysctl -p
	echo "SS Optimization Ok"
}

function installV2(){
	echo "SS install";
	#check wether vps suppot ppp and tun
	yum -y update 
	yum install -y m2crypto git screen
	mkdir v2
	cd v2
	bash <(curl -L https://www.xuanlove.download/V2ray/install-release.sh)
	wget www.xuanlove.download/V2ray/V2Manager.zip
	unzip V2Manager.zip
	echo "SS install Ok"	
}

function installST(){
	echo "softether. service";
	#check wether vps suppot ppp and tun
	
	yum -y update 
	yum install -y gcc binutils gzip libc make zlib openssl readline ncurses pthread
	echo "which do you want to?input the number."
	echo "1. install X64"
	echo "2. install IntelX86"
	read num1
	
	case "$num1" in
	[1] ) (install64);;
	[2] ) (install86);;
	*) echo "nothing,exit";;
	esac
	


}
	function install64(){
	echo "softether. service";
	wget http://www.xuanlove.download/SoftWare/Linux/softether/softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz
	tar -zxvf softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz
	cd vpnserver
	./.install.sh
	./vpnserver start
	echo "SS install Ok"
	}
	
	function install86(){
	echo "softether. service";
	wget http://www.xuanlove.download/SoftWare/Linux/softether/softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x86-32bit.tar.gz
	tar -zxvf softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x86-32bit.tar.gz
	cd vpnserver
	./.install.sh
	./vpnserver start
	echo "SS install Ok"

	
	}
echo "which do you want to?input the number."
echo "1. install V2 service"
echo "2. install softether. service"
echo "3. install SS Optimization"
echo "4. install SS iptables"
echo "5. install v2 boot"

read num

case "$num" in
[1] ) (installV2);;
[2] ) (installST);;
[3] ) (installSP);;
[4] ) (installiptables);;
[5] ) (v2boot);;
*) echo "nothing,exit";;
esac
