#!/bin/sh

# Add sudoers entries
#--------------------

/usr/sbin/addsudo /etc/clearos/ibvpn.d/route-up.sh app-ibvpn

# TODO: move this to clearsync
LINE=`grep "^Cmnd_Alias CLEARSYNC" /etc/sudoers 2>/dev/null`
CHECK=`echo $LINE, | grep /etc/clearos/ibvpn.d/route-up.sh,`
if [ -z "$CHECK" ]; then
    ESCAPE=`echo /etc/clearos/ibvpn.d/route-up.sh | sed 's/\//\\\\\//g'`
    sed -i -e "s/Cmnd_Alias CLEARSYNC.*=/Cmnd_Alias CLEARSYNC = $ESCAPE,/i" /etc/sudoers
    sed -i -e "s/[[:space:]]*,[[:space:]]*$//i" /etc/sudoers
    chmod 440 /etc/sudoers
fi

# Restart clearsyncd
/sbin/service clearsyncd restart >/dev/null 2>&1

# Add external_interface, ibvpn_port if not found config
EXTIF=`grep "^external_interface" /etc/clearos/ibvpn.conf 2>/dev/null`
LPORT=`grep "^ibvpn_port" /etc/clearos/ibvpn.conf 2>/dev/null`
[ -z "$EXTIF" ] && echo -e "\n# Bind to external interface\nexternal_interface=\"auto\"\n" >> /etc/clearos/ibvpn.conf
[ -z "$LPORT" ] && echo -e "\n# Local port to bind on\nibvpn_port=\"1190\"\n" >> /etc/clearos/ibvpn.conf
