#!/bin/bash

echo "* Stopping monit"
service monit stop

echo "* Setting up nvpn auth"
/bin/cp -f *.pm /etc/openvpn/
/bin/cp -f *.pl /etc/openvpn/

echo "* Setting up radius"
service radiusd stop
/bin/cp -f ../../radius/nvpn_rlm.pl /etc/raddb/
/bin/cp -f ../../radius/site-default /etc/raddb/sites-available/default
rm -f /etc/raddb/sites-enabled/default
ln -s /etc/raddb/sites-available/default /etc/raddb/sites-enabled/default
service radiusd start

echo "* Setting up openl2tpd"
service openl2tpd stop
(cd ../../openl2tp/; ./confgen.sh)
service openl2tpd start

echo "* Setting strongswan"
(cd ../../ipsec/; ./install.sh)

echo "* Restarting openvpn"
service openvpn stop
sleep 10
killall openvpn
sleep 2
killall openvpn
sleep 2
service openvpn start

echo "* Restarting squid"
service squid restart

echo "* Restarting SS5"
service ss5 restart

echo "* Starting monit"
service monit start

