[zaptel-commits] tzafrir: branch tzafrir/zaphelper r1632 - /team/tzafrir/zaphelper/zaptel.init

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Tue Nov 21 14:23:09 MST 2006


Author: tzafrir
Date: Tue Nov 21 15:23:08 2006
New Revision: 1632

URL: http://svn.digium.com/view/zaptel?view=rev&rev=1632
Log:
Rephrase/rewrite zaptel.init using zaptel-helper functions:
 * Much simpler modules loading (used only in the Debian case.
 * The recusrsive unload_modules instead of the unrelible RMODULES list.
 * No explicit sleep (only sleep command is 'sleep 1' in wait_for_zapctl).
 * Should work better with the Xorcom Astribank.
 * Check with -r before sourcing a file.
 * Debian scripts run with -e. No line there should fail for no good reason.

Modified:
    team/tzafrir/zaphelper/zaptel.init

Modified: team/tzafrir/zaphelper/zaptel.init
URL: http://svn.digium.com/view/zaptel/team/tzafrir/zaphelper/zaptel.init?view=diff&rev=1632&r1=1631&r2=1632
==============================================================================
--- team/tzafrir/zaphelper/zaptel.init (original)
+++ team/tzafrir/zaphelper/zaptel.init Tue Nov 21 15:23:08 2006
@@ -1,5 +1,6 @@
 #!/bin/sh
 #
+# FIXME: make lsb-compliant.
 # zaptel        This shell script takes care of loading and unloading \
 #               Zapata Telephony interfaces
 # chkconfig: 2345 9 92
@@ -9,6 +10,13 @@
 # config: /etc/sysconfig/zaptel
 
 initdir=/etc/init.d
+
+# include it. Don't run it:
+ZAPHELPER_ONLY_INCLUDE=1
+
+ZAPHELPER_PATH=/sbin/zaptel-helper
+
+ZTCFG=/sbin/ztcfg
 
 #
 # Determine which kind of configuration we're using
@@ -26,23 +34,19 @@
 # Source zaptel configuration.
 if [ $system = debian ]; then
 	set -e
-	if [ -f /etc/default/zaptel ]; then . /etc/default/zaptel; fi
+	if [ -r /etc/default/zaptel ]; then . /etc/default/zaptel; fi
 	LOCKFILE=/var/lock/zaptel # FIXME: not used with Debian.
 elif [ $system = redhat ]; then
-	[ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel
+	[ -r /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel
 	LOCKFILE=/var/lock/subsys/zaptel
 fi
+
+if [ -r "$ZAPHELPER_PATH" ]; then . $ZAPHELPER_PATH; fi
 
 if [ -z "${MODULES}" ]; then 
 	# Populate defaults if not present
 	MODULES="tor2 wct4xxp wct1xxp wcte11xp wcfxo wctdm wctdm24xxp" 
 fi
-
-RMODULES=""
-# Reverse list for un-loading; don't change
-for x in $MODULES; do 
-	RMODULES="$x $RMODULES"
-done
 
 # Check that telephony is up.
 [ "${TELEPHONY}" = "yes" ] || exit 0
@@ -51,77 +55,44 @@
 
 [ -f /etc/zaptel.conf ] || exit 0
 
-if [ "${DEBUG}" = "yes" ]; then
-	ARGS="debug=1"
-fi
-
 RETVAL=0
 
 # See how we were called.
 case "$1" in
 start)
-	# Load drivers
-	rmmod wcusb >& /dev/null
-	rmmod wcfxsusb >& /dev/null
-	rmmod audio >& /dev/null
-	if [ $system = debian ]; then
-		echo -n "Loading zaptel framework: " 
-		modprobe zaptel >& /dev/null && echo -n "done"
-		echo "."
-	elif [ $system = redhat ]; then
-		action "Loading zaptel framework: " modprobe zaptel
+	echo -n "Loading zaptel hardware modules:"
+	if [ "$system" = redhat ]; then
+		for mod in ${MODULES}; do
+			modprobe $mod
+		done
 	fi
-	echo -n "Waiting for zap to come online..."
-	TMOUT=10 # max secs to wait
-	while [ ! -d /dev/zap ] ; do
- 		sleep 1
-		TMOUT=`expr $TMOUT - 1`
-		if [ $TMOUT -eq 0 ] ; then
-			echo "Error: missing /dev/zap!"
-			exit 1
-		fi
-	done
-	echo "OK"
-	echo -n "Loading zaptel hardware modules:"
-	for x in $MODULES; do 
-		eval localARGS="\$${x}_ARGS"
-		if modprobe ${x} ${ARGS} ${localARGS} >& /dev/null; then
-			echo -n " $x"
-		fi
-	done
-	sleep 3
-	if [ ! -e /proc/zaptel/1 ]; then
-		echo "No functioning zap hardware found in /proc/zaptel, loading ztdummy"
-		modprobe ztdummy >& /dev/null
-	fi
-	if [ $system = debian ]; then
-		echo -n "Running ztcfg: " 
-		/sbin/ztcfg >& /dev/null && echo -n "done"
-		echo "."
-	elif [ $system = redhat ]; then
-		action "Running ztcfg: " /sbin/ztcfg
-	fi
+
+	# Get the Astribank module loaded properly:
+	wait_for_xpp
+	zap_reg_xpp
+	fix_asterisbank_sync
+
+	# wait for udev to generate /dev/zap/ctl before running ztcfg
+	wait_for_zapctl
+
+	# load ztdummy if there is no existing timing source.
+	# FIXME: we check that /dev/zap/ctl was generated, not that 
+	# /dev/zap/pseudo was generated.
+	guarantee_timing_source
+
+	$ZTCFG
+	
 	RETVAL=$?
 
 	[ $RETVAL -eq 0 ] && touch $LOCKFILE
 	;;
 stop)
 	# Unload drivers
+	# FIXME: Not for Debian?
 	echo -n "Unloading zaptel hardware drivers:"
-	for x in $RMODULES; do 
-		if rmmod ${x} >& /dev/null; then
-			echo -n " $x"
-		fi
-	done
-	echo "."
-
-	if [ $system = debian ]; then
-		echo -n "Removing zaptel module: " 
-		rmmod zaptel >& /dev/null && echo -n "done"
-		echo "."
-	elif [ $system = redhat ]; then
-		action "Removing zaptel module: " rmmod zaptel
-	fi
+	unload_modules
+	echo .
+	
 	RETVAL=$?
 
 	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
@@ -133,10 +104,10 @@
 reload)
 	if [ $system = debian ]; then
 		echo -n "Reloading ztcfg: "
-		/sbin/ztcfg >& /dev/null && echo -n "done"
+		$ZTCFG && echo -n "done"
 		echo "."
 	elif [ $system = redhat ]; then
-		action "Reloading ztcfg: " /sbin/ztcfg
+		action "Reloading ztcfg: " $ZTCFG
 	fi
 	RETVAL=$?
 	;;



More information about the zaptel-commits mailing list