#!/bin/sh
#

STUNLRUNDIR=/var/run/stunnel
SERVERCERT=/etc/ssl/certs/stunnel.pem
SSLCERT=/mnt/conf/ssl/cacert.pem
STUNLSH=/etc/init.d/stunnel

CONFFILE=/mnt/conf/stunnel.conf

test -f $CONFFILE || exit 1

STUNNEL_ENABLE=`cat $CONFFILE | awk '/enableStunnel/ { print $2}' `;
if [ ! $STUNNEL_ENABLE -eq 1 ]; then 
    exit 1
fi

if [ ! -e $STUNLRUNDIR ]; then
    mkdir $STUNLRUNDIR
fi
if [ ! -e $SERVERCERT ]; then
    [ -e $SSLCERT ] && cp $SSLCERT $SERVERCERT
fi

if [ -e $STUNLSH ]; then
    $STUNLSH $1
fi
