#! /bin/sh
#
# /etc/init.d/nstxcd: start and stop the nstx IP over DNS client

DAEMON=/usr/sbin/nstxcd
NAME=nstxcd
DESC=nstxcd

test -x $DAEMON || exit 0

# Source function library.
. /etc/rc.d/init.d/functions

# Include nstx defaults if available
if [ -f /etc/nstx/nstxcd.default ] ; then
	. /etc/nstx/nstxcd.default
fi

set -e

case "$1" in
  start)
	gprintf "Starting $DESC: "
	OPTIONS="$NSTX_OPTIONS $NSTX_DOMAIN $NSTX_DNS_SERVER"
	daemon $DAEMON $OPTIONS &
	touch /var/lock/subsys/nstxcd
	sleep 1;
	if [ -n "$ifup_tun" ]; then
	    ifconfig $ifup_tun up $tun_ip_address netmask $tun_ip_netmask
	fi
	echo 
	;;
  stop)
	gprintf  "Stopping $DESC: "
	if [ -n "$ifup_tun" ]; then
		ifconfig $ifup_tun down >/dev/null 2>&1
	fi
	killproc $DAEMON
	rm -f /var/lock/subsys/nstxcd
	echo 
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	$0 stop
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
