#########################################################################
# File Name: /data1/www/download/openvpn/update-kernel.sh
# Author: 
# mail: 
# Created Time: 2018年03月29日 星期四 12时00分30秒
#########################################################################
#!/bin/bash +x

disable_selinux() {
        if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
                sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
                setenforce 0
        fi
}

base_plugins_install(){
	echo 'base plugins installing...'
    yum -y upgrade
    yum -y install yum-plugin-fastestmirror -y gcc gcc-c++ wget lrzsz zip unzip vim telnet mtr traceroute
}

kernel_optimize(){
	echo 'kernel optimizing...'
	mv /etc/sysctl.conf /etc/sysctl.conf_backup
	wget -P /etc/ http://download.icloudstudio.com/openvpn/sysctl.conf
	sysctl -p
}

openvpn_install(){
	echo 'openvpn installing...'
	yum -y install openvpn lz4
	wget -P /etc/openvpn/ http://download.icloudstudio.com/openvpn/oversyee/client/client-example.conf
}

firewall_setting(){
	echo 'firewall setting...'
	systemctl stop firewalld
	systemctl disable firewalld
	
	yum -y install iptables iptables-services
	mv /etc/sysconfig/iptables /etc/sysconfig/iptables_backup
	wget -P /etc/sysconfig/ http://download.icloudstudio.com/openvpn/oversyee/client/iptables
	systemctl restart iptables
	systemctl enable iptables

	#systemctl stop iptables
	#systemctl disable iptables
}

download_keys(){
	echo 'downloading keys...'
	wget -P /etc/openvpn/client/ http://download.icloudstudio.com/openvpn/oversyee/client/keys/ca.crt
	wget -P /etc/openvpn/client/ http://download.icloudstudio.com/openvpn/oversyee/client/keys/ta.key
}

disable_selinux
base_plugins_install
kernel_optimize
openvpn_install
firewall_setting
download_keys

