#!/bin/sh
#
# code by ngc1927

# THIS FILE HAVE NAME OF YOUR CONFIG ..IF NOT PRESENT USE DEFAULT
if [ -e /var/etc/openvpn/myconfig.txt ]; then
	MYCONFIG="`cat /var/etc/openvpn/myconfig.txt`"
else
	MYCONFIG="client.conf"
fi

# **************************** NOT CHANGE AFTER THIS ****************************
cd /tmp
STARTED=0
LOADED=0

# load module tun.ko
/sbin/insmod /var/lib/modules/tun.ko 1>/dev/null 2>/dev/null && LOADED=1

# make directory and node tun
/bin/mkdir /dev/net 1>/dev/null 2>/dev/null
/bin/mknod -m 0600 /dev/net/tun c 10 200 1>/dev/null 2>/dev/null

# launch program with proper config
/var/bin/openvpn --config /var/etc/openvpn/$MYCONFIG &

[ -e /var/etc/SifTeam/bin/S80openvpn.sh ] && cp -a /var/etc/SifTeam/bin/S80openvpn.sh /var/etc/rcS.d/

if [ "$LOADED" == "1" ]; then
	echo "Module loaded"
else
	echo "Module not loaded"
fi

echo "Openvpn started"

exit 0
