#!/bin/sh
home=`pwd`
cd $home

read_meta_conf ()
{

	if [ $ostype = "Linux" ]; then
		WAN_BASE=/etc
		WAN_HOME=$WAN_BASE/wanpipe
		META_CONF=$WAN_BASE/wanpipe/wanrouter.rc
	elif [ $ostype = "FreeBSD" -o $ostype = "OpenBSD" ]; then
		WAN_BASE=/usr/local/etc
		WAN_HOME=$WAN_BASE/wanpipe
		wanrouter_rc_file=""
		if [ -r /etc/rc.conf ]; then
			. /etc/rc.conf
		fi
		if [ -n "$wanrouter_rc_file" ]; then
			WAN_HOME=${wanrouter_rc_file%/*}
		fi
		META_CONF=$wanrouter_rc_file
	fi

	# Read meta-configuration file.
	if [ -f $META_CONF ]
	then . $META_CONF
	else
		return 1 
	fi
	return 0
}

ostype=`sysctl -a |grep ostype`
ostype=`echo $ostype | sed 's/.* //'`

while [ ! -z "$1" ];
do
        ARGS=$ARGS"$1 "
        shift
done


read_meta_conf
if [ $? -ne 0 ]; then
	echo "ERROR: Failed to find Wanpipe meta config file!"
	exit 1
fi

cd ${WAN_HOME}/wancfg_zaptel
./wancfg_zaptel.pl --hp_tdm_api --conf_dir=$WAN_BASE $ARGS
cd $home
