#!/bin/bash
SYS_VERSION=`rpm -q --queryformat '%{VERSION}' centos-release`
(cd ppp ; ./install.sh)
(cd radius ; ./install.sh)
if [ $SYS_VERSION -eq 6 ]; then
(cd ippool ; ./install.sh)
echo "portmap: 127.0.0.1 192.168.0.0/255.255.0.0 172.16.0.0/255.255.0.0 10.0.0.0/255.0.0.0" >> /etc/hosts.allow
echo "rpcbind: 127.0.0.1 192.168.0.0/255.255.0.0 172.16.0.0/255.255.0.0 10.0.0.0/255.0.0.0" >> /etc/hosts.allow

echo "portmap: ALL" >> /etc/hosts.deny 
echo "rpcbind: ALL" >> /etc/hosts.deny
fi

(cd openl2tp ; ./install.sh)
(cd ipsec ; ./install.sh)

if [ $SYS_VERSION -eq 6 ]; then
  	/etc/init.d/monit restart
elif [ $SYS_VERSION -eq 7 ]; then
  	systemctl restart monit
fi

if [[ "$*" == all ]]; then
	echo "the l2tp files finished we sleep and go on with SS5"
	sleep 5
	if [ $SYS_VERSION -eq 6 ]; then
	    chkconfig --add perl-iptdaemon
	    chkconfig perl-iptdaemon on
#	elif [ $SYS_VERSION -eq 7 ]; then
#	    systemctl enable perl-iptdaemon
	fi
	cd /root/nvpn-ss5/
	./build.sh all
fi
