#!/bin/sh
#
# You don't need to change this file!
#
# Please read /usr/share/doc/isdnutils/README.debian
# and         /usr/share/doc/isdnutils/CONFIG.gz .
#
# This script stops/starts ALL ISDN stuff (including isdnlog, if installed).

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/isdnctrl
NAME=isdnutils
DESC='ISDN services'
FLAGS="defaults"

test -f $DAEMON || exit 0    # sanity check
. /lib/lsb/init-functions

set -e

# source the function definitions for stopping / starting the various parts

. /etc/isdn/init.d.functions

# isdn_verbose=true     # default is set by VERBOSE in /etc/default/rcS

case "$1" in
  start)
    if [ ! -z "$2" ]; then
        service="$2"
	case "$service" in
	    ipppd|isdnlog) ;;
	    *) log_failure_msg "Unknown ISDN service to stop: $2"; exit 1
	esac
	[ -s /usr/sbin/$service ] || exit 0
    	log_begin_msg "Starting $service..."
	start_$service
	log_end_msg $?
	exit 0
    fi
    log_begin_msg "Starting $DESC..."
    start_devices
    if [ -s /usr/sbin/ipppd   ]; then start_ipppd;   fi
    if [ -x /usr/sbin/ipmasq  ]; then /usr/sbin/ipmasq; fi
    start_iprofd
    if [ -s /usr/sbin/isdnlog ]; then start_isdnlog; fi
    log_end_msg 0
    ;;
  stop)
    if [ ! -z "$2" ]; then
        service="$2"
	case "$service" in
	    ipppd|isdnlog) ;;
	    *) log_failure_msg "Unknown ISDN service to stop: $2"; exit 1
	esac
	[ -s /usr/sbin/$service ] || exit 0
    	log_begin_msg "Stopping $service..."
	stop_$service
	log_end_msg $?
	exit 0
    fi
    log_begin_msg "Stopping $DESC..."
    stop_iprofd
    if [ -s /usr/sbin/ipppd   ]; then stop_ipppd;   fi
    stop_devices
    if [ -x /usr/sbin/ipmasq  ]; then /usr/sbin/ipmasq; fi
    if [ -s /usr/sbin/isdnlog ]; then stop_isdnlog; fi
    log_end_msg 0
    ;;
  reload)
    if [ ! -z "$2" ]; then
        service="$2"
	case "$service" in
	    ipppd|isdnlog) ;;
	    *) log_failure_msg "Unknown ISDN service to stop: $2"; exit 1
	esac
        isdn_verbose=false
	[ -s /usr/sbin/$service ] || exit 0
    	log_begin_msg "Restarting $service..."
        reload_$service || ( stop_$service; start_$service )
	log_end_msg $?
	exit 0
    fi
    log_warning_msg "Sorry, reload can only be done explicitly for ipppd and isdnlog."
    log_warning_msg 'Run "/etc/init.d/isdnutils reload ipppd" for example.'
    exit 1
    ;;
  restart|force-reload)
    # reload doesn't really work for some daemons...
    log_begin_msg "Restarting $DESC:"
    isdn_verbose=false
    stop_iprofd
    if [ -s /usr/sbin/ipppd   ]; then stop_ipppd;   fi
    if [ -s /usr/sbin/isdnlog ]; then stop_isdnlog; start_isdnlog; fi
    stop_devices; start_devices
    if [ -s /usr/sbin/ipppd   ]; then start_ipppd;   fi
    if [ -x /usr/sbin/ipmasq  ]; then /usr/sbin/ipmasq; fi
    start_iprofd
    log_end_msg 0
    ;;
  *)
    log_success_msg "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|reload}"
    exit 1
    ;;
esac

list_unconfigured

exit 0
# vim:set ts=8 sw=4:
