#!/bin/sh
#
# zaptel        This shell script takes care of loading and unloading \
#               Zapata Telephony interfaces
# chkconfig: - 9 92
# description: The zapata telephony drivers allow you to use your linux \
# computer to accept incoming data and voice interfaces
#
# config: /etc/sysconfig/zaptel

initdir=/etc/rc.d/init.d

# Source function library.
. $initdir/functions || exit 0

# Source zaptel configuration.
[ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel

# Check that telephony is up.
[ "${TELEPHONY}" = "yes" ] || exit 0

[ -f /sbin/ztcfg ] || exit 0

[ -f /etc/zaptel.conf ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
    start)
	if [ ! -e /proc/zaptel/1 ]; then
		echo "No functioning zap hardware found in /proc/zaptel, loading ztdummy"
		action "Loading ztdummy:" modprobe ztdummy
	fi
	action "Running ztcfg: " /sbin/ztcfg
	RETVAL=$?

        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zaptel
        ;;
  stop)
	RETVAL=0

        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zaptel
        ;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	action "Reloading ztcfg: " /sbin/ztcfg
	RETVAL=$?
	;;
  status)
	echo "Status option unimplemented."
	RETVAL=$?
	;;
  *)
        echo "Usage: zaptel {start|stop|status|restart|reload}"
        exit 1
esac

exit $RETVAL

