#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/sbin/ztcfg
NAME=zaptel
DESC="Zaptel cards initial configuration"

test -x $DAEMON || exit 0
test -r /etc/zaptel.conf || exit 0

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

# defined in /etc/default/zaptel
# ZAPTEL_MODS is a list of modules to be loaded at startup

set -e

case "$1" in
	start|reload)
		echo -n "$DESC: "
		#for module in $ZAPTEL_MODS
		#do
		#	modprobe $module
		#done
		
		# if no zaptel module loaded: load ztdummy. other modules should have
		# been loaded by now
		# The first holds if zaptel is not loaded at all. The second: if 
		# If there is no zaptel timing source:
		if head -c 0 /dev/zap/pseudo 2>/dev/null
		then modprobe ztdummy || true # will fail if there is no module package
		fi
                if [ -r /etc/fxotune.conf ] && [ -x fxotune ]; then
                  fxotune -s
                fi

		# configure existing modules:
		$DAEMON $DAEMON_OPTS
		echo "$NAME."
		;;
	stop)
		: # do nothing
		;;
	force-reload|restart) 
		# there's no '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
