All pastes #772121 Raw Edit

puzzled

public shellscript v1 · immutable
·published 2007-11-13 15:53 UTC
rendered paste body
#!/bin/sh## zaptel        This shell script takes care of loading and unloading \#               Zapata Telephony interfaces# chkconfig: 2345 9 92# description: The zapata telephony drivers allow you to use your linux \# computer to accept incoming data and voice interfaces## config: /etc/sysconfig/zaptelinitdir=/etc/init.d# Don't edit the following values. Edit /etc/sysconfig/zaptel or# /etc/defualt/zaptel (depending on your system) instead.ZTCFG=/usr/sbin/ztcfgZTCFG_CMD="$ZTCFG" # e.g: for a custom zaptel.conf locationFXOTUNE=/usr/sbin/fxotune# The default syncer Astribank. Usually set automatically to a sane# value by xpp_sync(1) if you have an Astribank. You can set this to an# explicit Astribank (e.g: 01).XPP_SYNC=auto# The maximal timeout (seconds) to wait for udevd to finish generating # device nodes after the modules have loaded and before running ztcfg. ZAP_DEV_TIMEOUT=20## Determine which kind of configuration we're using#system=redhat  # assume redhatif [ -f /etc/debian_version ]; then    system=debianfi# Source function library.if [ $system = redhat ]; then    . $initdir/functions || exit 0fi# Source zaptel configuration.if [ $system = debian ]; then	[ -f /etc/default/zaptel ] && . /etc/default/zaptel	LOCKFILE=/var/lock/zaptelelif [ $system = redhat ]; then	if [ ! -f /etc/sysconfig/zaptel ]; then		echo "Action failed because /etc/sysconfig/zaptel is missing."		echo "Copy /etc/sysconfig/zaptel.sample to /etc/sysconfig/zaptel"		echo "Then edit /etc/sysconfig/zaptel and retry"		exit	fi	[ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel	LOCKFILE=/var/lock/subsys/zaptelfi# recursively unload a module and its dependencies, if possible.# where's modprobe -r when you need it?# inputs: module to unload.# returns: the result fromunload_module() {	module="$1"	line=`lsmod 2>/dev/null | grep "^$1 "`	if [ "$line" = '' ]; then 		echo "No zaptel modules found"		return;	fi # module was not loaded	set -- $line	# $1: the original module, $2: size, $3: refcount, $4: deps list	mods=`echo $4 | tr , ' '`	# xpp_usb keeps the xpds below busy if an xpp hardware is	# connected. Hence must be removed before them:	case "$module" in xpd_*) mods="xpp_usb $mods";; esac	for mod in $mods; do		# run in a subshell, so it won't step over our vars:		(unload_module $mod) 		# TODO: the following is probably the error handling we want:		# if [ $? != 0 ]; then return 1; fi	done		action "Unloading zaptel module $module:" rmmod $module}# Initialize the Xorcom Astribank (xpp/) using perl utiliites:# intended to replace all the the three functions below if user has # installed the zaptel-perl utilities.xpp_startup() {	# do nothing if there are no astribank devices:	if ! grep -q connected /proc/xpp/xbuses 2>/dev/null; then return 0; fi	echo "Waiting for Astribank devices to initialize:"	cat /proc/xpp/XBUS-[0-9]*/waitfor_xpds 2>/dev/null || true		# overriding locales for the above two, as perl can be noisy	# when locales are missing.	# No register all the devices if they didn't auto-register:	LC_ALL=C zt_registration on	# this one could actually be run after ztcfg:	LC_ALL=C xpp_sync "$XPP_SYNC"}hpec_start() {	# HPEC license found	if ! echo /var/lib/digium/licenses/HPEC-*.lic | grep -v '\*' | grep -q .; then		return	fi	# zaphpec_enable not installed in /usr/sbin	if [ ! -f /usr/sbin/zaphpec_enable ]; then		echo -n "Running zaphpec_enable: Failed"		echo -n "."		echo "  The zaphpec_enable binary is not installed in /usr/sbin."		return	fi	# zaphpec_enable not set executable	if [ ! -x /usr/sbin/zaphpec_enable ]; then		echo -n "Running zaphpec_enable: Failed"		echo -n "."		echo "  /usr/sbin/zaphpec_enable is not set as executable."		return	fi	# zaphpec_enable properly installed	if [ $system = debian ]; then		echo -n "Running zaphpec_enable: "		/usr/sbin/zaphpec_enable 2> /dev/null	elif [ $system = redhat ]; then		action "Running zaphpec_enable: " /usr/sbin/zaphpec_enable	fi	if [ $? = 0 ]; then		echo -n "done"		echo "."	else		echo -n "Failed"		echo -n "."		echo "  This can be caused if you had already run zaphpec_enable, or if your HPEC license is no longer valid."	fi}shutdown_dynamic() {	if ! grep -q ' ZTD/' /proc/* 2>/dev/null; then return; fi	# we should only get here if we have dynamic spans. Right?	$ZTCFG_CMD -s}test_zap() {	TMOUT=$ZAP_DEV_TIMEOUT # 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!"			RETVAL=1			exit 1		fi	done}# Check that telephony is up.[ "${TELEPHONY}" = "yes" ] || exit 0if [ ! -f $ZTCFG ]; then	echo "Action failed because $ZTCFG is missing"	echo "Install ztcfg and retry"	exitfiif [ ! -f /etc/zaptel.conf ]; then	echo "Action failed because /etc/zaptel.conf is missing."	echo "Copy /etc/zaptel.conf.sample to /etc/zaptel.conf"	echo "Then edit /etc/zaptel.conf and retry"	exitfiif [ "${DEBUG}" = "yes" ]; then	ARGS="debug=1"fiRETVAL=0# See how we were called.case "$1" in  start)	# Load drivers	rmmod wcusb 2> /dev/null	rmmod wcfxsusb 2> /dev/null	rmmod audio 2> /dev/null	if [ $system = debian ]; then		echo "Loading zaptel framework: " 		modprobe zaptel ${ARGS} 2> /dev/null && echo -n "done"		echo "."	elif [ $system = redhat ]; then	    action "Loading zaptel framework: " modprobe zaptel ${ARGS}	fi	action "Waiting for zap to come online: " test_zap	echo ""	for x in $MODULES; do 		eval localARGS="\$${x}_ARGS"		action "Loading zaptel module ${x}: " modprobe ${x} ${ARGS} ${localARGS} 2> /dev/null	done	sleep 3 # TODO: remove it		# If you have zaptel-perl, the three below can be replaced with:	xpp_startup		if [ ! -e /proc/zaptel/1 ]; then		echo ""		echo "No functioning zap hardware found in /proc/zaptel so unload modules"		for x in $MODULES; do			action "Unloading zaptel module ${x}: " modprobe -r ${x}		done		echo ""		action "Loading zaptel module ztdummy: " modprobe ztdummy		# wait a few seconds before running ztcfg below		sleep 3	fi	if [ $system = debian ]; then	    echo -n "Running ztcfg: " 	    $ZTCFG_CMD 2> /dev/null && echo -n "done"	    echo "."	elif [ $system = redhat ]; then	    action "Running ztcfg: " $ZTCFG_CMD	fi	RETVAL=$?	[ $RETVAL -eq 0 ] && touch $LOCKFILE	if [ -x "$FXOTUNE" ] && [ -r /etc/fxotune.conf ]; then		# Allowed to fail if e.g. Asterisk already uses channels:		$FXOTUNE -s || : 	fi	hpec_start	;;  stop)	# Unload drivers	#shutdown_dynamic # FIXME: needs test from someone with dynamic spans	echo "Unloading zaptel hardware drivers:"  	unload_module zaptel	RETVAL=$?	#echo "."	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE	;;  unload)	# We don't have zaptel helper, so let's not replicate too much code:	# allow others to use the unload command.	unload_module zaptel	;;  restart)	$0 stop	$0 start	;;  reload)	if [ $system = debian ]; then	    echo -n "Reloading ztcfg: "	    $ZTCFG_CMD 2> /dev/null && echo -n "done"	    echo "."	elif [ $system = redhat ]; then	    action "Reloading ztcfg: " $ZTCFG_CMD	fi	RETVAL=$?	;;  *)	echo "Usage: zaptel {start|stop|restart|reload}"	exit 1esacexit $RETVAL