[zaptel-commits] tzafrir: trunk r2332 - in /trunk/xpp/utils: genzaptelconf genzaptelconf.8

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Thu Mar 22 00:01:21 MST 2007


Author: tzafrir
Date: Thu Mar 22 02:01:21 2007
New Revision: 2332

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2332
Log:
* genzaptelconf -z will also generate the output of zapscan (The additional 
  /etc/asterisk/zapscan.conf the asterisk gui needs).
* Also put every digital span N in group 10+N (in addition to 0 / 5).
* Removed useless fxs/fxo-s lists, and other unused code.
* Add wcte12xp to the modules list. Prefer vzaphfc to zaphfc.
* Default to ptmp for zapbri signalling.
* Should be more readable.

Modified:
    trunk/xpp/utils/genzaptelconf
    trunk/xpp/utils/genzaptelconf.8

Modified: trunk/xpp/utils/genzaptelconf
URL: http://svn.digium.com/view/zaptel/trunk/xpp/utils/genzaptelconf?view=diff&rev=2332&r1=2331&r2=2332
==============================================================================
--- trunk/xpp/utils/genzaptelconf (original)
+++ trunk/xpp/utils/genzaptelconf Thu Mar 22 02:01:21 2007
@@ -34,7 +34,7 @@
 # (redhat/centos)
 
 # /etc/default/zaptel may override the following variables
-VERSION=0.5.8
+VERSION=0.5.10
 rcsid='$Id$'
 lc_country=us
 # set to: ls, ks or gs for (Loopstart, Kewlstart and GroundStart)
@@ -59,6 +59,7 @@
 ZAPCONF_FILE=${ZAPCONF_FILE:-/etc/zaptel.conf}
 ZAPCONF_FILE_SYSTEM=$ZAPCONF_FILE
 ZAPATA_FILE=${ZAPATA_FILE:-/etc/asterisk/zapata-channels.conf}
+ZAPSCAN_FILE=${ZAPSCAN_FILE:-/etc/asterisk/zapscan.conf}
 ZAPTEL_BOOT_DEBIAN=${ZAPTEL_BOOT_DEBIAN:-/etc/default/zaptel}
 ZAPTEL_BOOT_FEDORA=${ZAPTEL_BOOT_FEDORA:-/etc/sysconfig/zaptel}
 MODLIST_FILE=/etc/modules
@@ -68,6 +69,9 @@
 # how long to wait for /dev/zap/ctl to appear? (seconds)
 DEVZAP_TIMEOUT=${DEVZAP_TIMEOUT:-20}
 ZTCFG=${ZTCFG:-/sbin/ztcfg}
+# BRI/PRI spans will be in an additional per-span group whose number
+# is SPAN_GROUP_BASE + span-number
+SPAN_GROUP_BASE=10
 
 # a temporary directory to store whatever we need to remember.
 #
@@ -77,14 +81,14 @@
 # A list of all modules:
 # - the list of modules which will be probed (in this order) if -d is used
 # - The module that will be deleted from /etc/modules , if -d -M is used
-ALL_MODULES="zaphfc qozap ztgsm wctdm wctdm24xxp wcfxo wcfxs pciradio tor2 torisa wct1xxp wct4xxp wcte11xp wanpipe wcusb xpp_usb"
+ALL_MODULES="vzaphfc zaphfc qozap ztgsm wctdm wctdm24xxp wcfxo wcfxs pciradio tor2 torisa wcte12xp wct1xxp wct4xxp wcte11xp wanpipe wcusb xpp_usb"
 
 # What signalling to give to ZapBRI channels?
 # bri:       bri_net; bri_cpe           (Bristuffed Asterisk. No multi- support)
 # bri_ptmpi: bri_net_ptmp; bri_cpe_ptmp (Bristuffed Asterisk, multi- support)
 # pri:       pri_net; pri_cpe           (Recent Asterisk. Experimental)
-ZAPBRI_SIGNALLING=bri
-#ZAPBRI_SIGNALLING=bri_ptmp
+#ZAPBRI_SIGNALLING=bri
+ZAPBRI_SIGNALLING=bri_ptmp
 #ZAPBRI_SIGNALLING=pri
 
 # read default configuration from /etc/default/zaptel
@@ -115,6 +119,7 @@
 verbose=no
 do_restart=yes
 fxsdisable=no
+do_gen_zapscan=no
 
 span_te_timing_counter=1
 
@@ -123,7 +128,7 @@
 pri)      ZAPBRI_NET=pri_net;      ZAPBRI_CPE=pri_cpe ;;
 bri_ptmp) ZAPBRI_NET=bri_net_ptmp; ZAPBRI_CPE=bri_cpe_ptmp ;;
 *) 
-  echo >&2 "Incorrect value for ZAPBRI_SIGNALLING ($ZAPBRI_SIGNALLING). Abortring"
+	echo >&2 "Incorrect value for ZAPBRI_SIGNALLING ($ZAPBRI_SIGNALLING). Abortring"
 	exit 1
 	;;
 esac
@@ -146,10 +151,10 @@
 	# no point waiting.
 	if [ -c /dev/zap/ctl ] || ! grep -q zaptel /proc/modules ; then
 	  return
-  fi
-  say "Waiting for /dev/zap/ctl to be generated"
-  devzap_found=0
-  for i in `seq $DEVZAP_TIMEOUT`; do
+	fi
+	say "Waiting for /dev/zap/ctl to be generated"
+	devzap_found=0
+	for i in `seq $DEVZAP_TIMEOUT`; do
 		sleep 1
 		if [ -c /dev/zap/ctl ]; then
 		  devzap_found=1
@@ -157,8 +162,8 @@
 		fi
 	done
 	if [ "$devzap_found" != 1 ]; then
-	  say "Still no /dev/zap/ctl after $devzap_timeout seconds."
-	  echo >&2 "No /dev/zap/ctl: cannot run ztcfg. Aborting."
+		say "Still no /dev/zap/ctl after $devzap_timeout seconds."
+		echo >&2 "No /dev/zap/ctl: cannot run ztcfg. Aborting."
 	fi
 }
 
@@ -198,9 +203,9 @@
 
 update_module_list() {
   if   [ -f "$MODLIST_FILE" ]; then
-	  update_module_list_debian "$@"
+		update_module_list_debian "$@"
 	elif [ -f "$MODLIST_FILE_FEDORA" ]; then
-	  update_module_list_fedora "$@"
+		update_module_list_fedora "$@"
 	else
 	  die "Can't find a modules list to update. Tried: $MODLIST_FILE, $MODLIST_FILE_FEDORA. Aborting"
 	fi
@@ -251,6 +256,20 @@
 	echo >&2 "  -v: verbose"
 	echo >&2 "  -s: Stop Asterisk before running, and start it at the end."
 	echo >&2 "  -R: Don't restart asterisk in the end."
+	echo >&2 "  -z: also generate zapscan.conf for the asterisk GUI."
+}
+
+# print /etc/asterisk/zapscan.conf for the Asterisk-GUI
+# $1: port type. Currently only fxs/fxo . Note that this is the type, and
+#                not the signalling (which would be the fxo fir an fxs port.
+# $2: port number. Probably a range of ports is also allowed.
+print_zapscan_port () {
+	if [ "$do_gen_zapscan" != 'yes' ]; then return 0; fi
+
+	echo "
+[$2]
+port=$1
+"	>>$zapscan_file
 }
 
 # $1: channel number
@@ -286,12 +305,12 @@
 	else
 		method="$fxs_default_start"
 	fi
+	case "$sig" in
+	fxs) sig_name=FXO; sig_name_sc=fxo ;;
+	fxo) sig_name=FXS; sig_name_sc=fxs ;;
+	esac
 	case "$mode" in
 	list)
-		case "$sig" in
-		fxs) sig_name=FXO;;
-		fxo) sig_name=FXS;;
-		esac
 		echo $chan $sig_name $astbank_type;;
 	files)
 		# sadly, both input ports and output ports go into the same span as 
@@ -400,18 +419,7 @@
 		reset_zapata_entry $zapata_file $reset_values
 		echo ""                                          >> $zapata_file
 
-		# Keep a note of what channels we have identified
-		say "DEBUG: adding to channels list: channel: $chan, sig: $sig"
-		case "$sig" in
-		fxs)
-			echo $chan >$tmp_dir/fxo_$chan
-			say "DEBUG: FXO list now contains: `cat $tmp_dir/fxo_* |xargs`"
-			;;
-		fxo)
-			echo $chan >$tmp_dir/fxs_$chan
-			say "DEBUG: FXS list now contains: `cat $tmp_dir/fxs_* |xargs`"
-			;;
-		esac
+		print_zapscan_port "$sig_name_sc" "$chan"
 		;;
 	esac
 	
@@ -552,32 +560,6 @@
 	esac
 }
 
-# TODO: kill this function. It is now unreferenced from anywhere.
-check_tdm_sigtype() {
-	chan_num=$1
-	sig_type=$2
-	mode=$3
-	
-	case "$sig_type" in
-	fxs)chan_sig_type=fxo;;
-	fxo)chan_sig_type=fxs;;
-	esac
-
-#	print_pattern $chan_num $chan_sig_type $mode
-	
-  # if you get syntax error from this line, make sure you use 'bash' 
-  # rather than 'sh'
-	$ztcfg_cmd -c <(print_pattern $chan_num $chan_sig_type zaptel) 2>/dev/null  \
-		|| return 1
-	if head -c1 /dev/zap/$chan_num >/dev/null 2>/dev/null
-	then 
-		print_pattern $chan_num $chan_sig_type $mode
-		return 0
-	else
-		return 1
-	fi	
-}
-
 # run after the channel's entry. Used to reset all the values 
 reset_zapata_entry() {
 	conf_file="$1"; shift
@@ -595,12 +577,215 @@
 }
 
 
+# we need to preserve the permissions of existing configurations files.
+# However we also don't want to be left with incomplete configurations in 
+# case we are stopped in the middle. Thus we create a temporary file and
+# mv it to the original file only when done.
+#
+# This function gives the temporary file the permissions of the original,
+# or some sane defaults.
+#
+# The temporary file is generated here, and ths its name is passed through
+# a variable whose name is passed as a parameter (new_var).
+#
+# $1: orig_cfg_file
+# $2: new_var
+gen_tmp_conf() {
+	orig_cfg_file=$1
+	new_var=$2
+
+	eval $new_var=`mktemp -t genzaptelconf-zapata-XXXXXX` # assign by reference
+	if [ -r "$orig_cfg_file" ]; then
+		chown --reference="$orig_cfg_file" ${!new_var} 2>/dev/null
+		chmod --reference="$orig_cfg_file" ${!new_var} 2>/dev/null  
+	else
+		chmod 644 ${!new_var}
+	fi
+}
+
+# Extract information from one digital channel (one line in a /proc/zaptel 
+# file). Information is saved to $tmp_dir/span_foo variables.
+detect_digital_channel() {
+	line="$1"
+	chan_num="$2"
+	span_num="$3"
+
+	# PRI/BRI channel
+	# Rather than identifying cards by the header line, we identify 
+	# them by the channel names. This is shorter. 
+	# This also allows us to count the channel numbers and check if 
+	# we have a E1 span, a T1 span or a BRI span.
+	if [ "`cat $tmp_dir/span_begin`" = "-1" ]
+	then
+		echo $chan_num      >$tmp_dir/span_begin
+		echo $span_num      >$tmp_dir/span_num
+		# The Astribank channels provide the information of TE/NT in the channel name. So 
+		# why not use it?
+		case "$line" in
+		*XPP_BRI_TE/*) echo 'te' >$tmp_dir/span_termtype;;
+		*XPP_BRI_NT/*) echo 'nt' >$tmp_dir/span_termtype;;
+		esac
+		case "$line" in
+		*ZTHFC*/*|*ztqoz*/*|*XPP_BRI_*/*)
+			# BRI channel
+			echo 'ccs'          >$tmp_dir/span_framing
+			echo 'euroisdn'     >$tmp_dir/span_switchtype
+			if [ "`cat $tmp_dir/span_termtype`" = 'nt' 2>/dev/null ]
+			then
+				echo $ZAPBRI_NET >$tmp_dir/span_signalling 
+			else
+				echo $ZAPBRI_CPE >$tmp_dir/span_signalling
+			fi
+			;;
+		*ztgsm*/*)
+			# Junghanns's GSM cards. 
+			echo 'ccs'          >$tmp_dir/span_framing
+			#Does this mean anything?
+			echo 'gsm'          >$tmp_dir/span_signalling
+			;;
+		*TE[24]/*|*WCT1/*|*Tor2/*|*TorISA/*|*WP[TE]1/*)
+			# PRI span (E1/T1)
+			echo 'esf'       >$tmp_dir/span_framing
+			echo 'b8zs'      >$tmp_dir/span_coding
+			echo 'national'  >$tmp_dir/span_switchtype
+			echo 'pri_cpe'   >$tmp_dir/span_signalling
+			# an example of country-specific setup. This is probably not accurate
+			# Contributions are welcome
+			case "$lc_country" in 
+			nl)
+				# (Just an example for per-country info)
+				echo 'ccs'       >$tmp_dir/span_framing
+				echo 'ami'       >$tmp_dir/span_coding
+				#echo 'crc4'      >$tmp_dir/span_yellow
+				#echo 'euroisdn'  >$tmp_dir/span_switchtype
+				#echo 'pri_cpe'   >$tmp_dir/span_signalling
+				;;
+			il|de|au)
+				echo 'ccs'       >$tmp_dir/span_framing
+				echo 'hdb3'      >$tmp_dir/span_coding
+				echo 'crc4'      >$tmp_dir/span_yellow
+				echo 'euroisdn'  >$tmp_dir/span_switchtype
+				;;
+			cl)
+				echo 'ccs'       >$tmp_dir/span_framing
+				echo 'hdb3'      >$tmp_dir/span_coding
+				#echo 'crc4'      >$tmp_dir/span_yellow
+				echo 'national'  >$tmp_dir/span_switchtype
+				;;
+			esac
+		;;
+		esac
+	fi
+	# span_lastd is always the one before last 
+	# channel. span_bchan is the last:
+	echo $chan_num      >$tmp_dir/span_end
+}
+
+# read information from the $tmp_dir/span_foo files and generate 
+# configuration for the span and its channels.
+write_digital_config() {
+	# if the current file we checked was not of a digital span, we have
+	# nothing to do:
+	if [ "`cat $tmp_dir/span_begin`" = -1 ]; then return; fi
+
+	# read files to variables:
+	for suffix in num begin end timing lbo framing \
+		coding switchtype signalling yellow termtype
+	do
+		eval span_$suffix=`cat $tmp_dir/span_$suffix 2>/dev/null`
+	done
+
+	if [ "$span_yellow" != '' ]; then span_yellow=",$span_yellow"; fi
+	# exactly the same logic is used in asterisk's chan_zap.c.
+	# also not that $(( )) is bash-specific
+	case "$((1+ $span_end - $span_begin))" in
+	2|3|24) #ztgsm, BRI or T1
+		dchan=$span_end
+		bchans="$span_begin-$(($span_end-1))"
+		;;
+	31) #E1
+		dchan="$(($span_begin+15))"
+		bchans="$span_begin-$(($span_begin+14)),$(($span_begin+16))-$span_end"
+		if [ "$span_switchtype" = 'national' ]; then
+			# don't leave an E1 span with defective defaults:
+			span_framing=ccs
+			span_coding=hdb3
+			span_switchtype=euroisdn
+		fi
+		;;
+	esac
+	# Let's assume that a TE span should get the clock from the remote unit,
+	# and NT spans should provide timing. Just as a sane default.
+	# If we have several TE spans, the first will have priority 1, 
+	# second: 2, etc.
+	case "$span_signalling" in *_cpe*)
+		span_timing=$span_te_timing_counter
+		span_te_timing_counter=$(($span_te_timing_counter + 1))
+		;;
+	esac
+	case "$mode" in
+	files)
+		echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow >> $zaptel_file
+		# leave a comment in zaptel.conf that allows to tell if
+		# this span is TE or NT:
+		if [ "$span_termtype" != '' ]
+		then echo "# termtype: $span_termtype" >>$zaptel_file
+		fi
+		echo bchan=$bchans >>$zaptel_file
+		echo dchan=$dchan  >>$zaptel_file
+		span_group=$(($SPAN_GROUP_BASE + $span_num))
+		
+		if [ "$span_termtype" != '' ]
+		then
+			# an ISDN card's span that we know if it is in NT mode or TE mode.
+			# NT is the same as FXS for us and TE is the same as FXO
+			if [ "$span_termtype" = 'nt' ]
+			then
+				echo "callerid=\"Channels $span_begin - $span_end\" <$span_begin>" >> $zapata_file
+				reset_values="$reset_values callerid"
+				#echo "mailbox=$exten"
+				if [ "$group_manual" != "yes" ]
+				then 
+					echo "group=$group_phones,$span_group"     >> $zapata_file
+					reset_values="$reset_values group"
+				fi
+				if [ "$context_manual" != "yes" ]
+				then 
+					echo "context=$context_phones" >> $zapata_file
+				fi
+			else 
+				#echo "mailbox="
+				if [ "$group_manual" != "yes" ]
+				then 
+					echo "group=$group_lines,$span_group"      >> $zapata_file
+					reset_values="$reset_values group"
+				fi
+				if [ "$context_manual" != "yes" ]
+				then 
+					echo "context=$context_lines"  >> $zapata_file
+					reset_values="$reset_values context"
+				fi
+			fi
+		fi
+		echo "switchtype = $span_switchtype" >> $zapata_file
+		echo "signalling = $span_signalling" >> $zapata_file
+		echo "channel => $bchans"            >> $zapata_file
+		reset_zapata_entry $zapata_file $reset_values
+		reset_values=
+		;;
+	list)
+		echo "### BRI/PRI: $span_termtype" 
+		echo "$bchans Data"
+		echo "$dchan Control"
+		#echo BRI/PRI: chans: $bchans, control: $dchan
+		;;
+	esac
+}
+
+# This is where the actual detection configuration detection work happens.
 genconf() {
 	local mode=$1
 	local reset_values=""
-	# reset FXO list (global)
-	#say "DEBUG: resetting channels lists"
-	rm -f $tmp_dir/fx{s,o}_*
 
 # 	spanlist=`echo /proc/zaptel/* |  grep -v '\*'`
 # 	spanlist=$(for i in `for i in  /proc/zaptel/*; do if [ -f $i ]; then echo $i |  cut -f 4 -d / ; fi; done | sort -n`; do echo -n "/proc/zaptel/$i "; done)
@@ -613,22 +798,20 @@
 
 
 	case "$mode" in 
-		files)
-			local zaptel_file=`mktemp -t genzaptelconf-zaptel-XXXXXX`
-			local zapata_file=`mktemp -t genzaptelconf-zapata-XXXXXX`
-			if [ -r "${ZAPCONF_FILE}" ]; then
-				chown --reference="${ZAPCONF_FILE}" $zaptel_file || true
-				chmod --reference="${ZAPCONF_FILE}" $zaptel_file 
-			else
-				chmod 644 $zaptel_file 
-			fi
-			if [ -r "${ZAPATA_FILE}" ]; then
-				chown --reference="${ZAPATA_FILE}" $zapata_file || true
-				chmod --reference="${ZAPATA_FILE}" $zapata_file 
-			else
-				chmod 644 $zapata_file 
-			fi
-			cat <<EOF >$zaptel_file
+	files)
+		if [ "$do_gen_zapscan" = 'yes' ]; then
+			gen_tmp_conf "$ZAPSCAN_FILE" zapscan_file
+			cat <<EOF >$zapscan_file
+; zapscan.conf: information about detected zaptel channels
+; (currently: analog only)
+;
+; Automatically generated by $0 -- Please do not edit.
+
+EOF
+		fi
+		gen_tmp_conf "$ZAPTEL_FILE" zaptel_file
+		gen_tmp_conf "$ZAPATA_FILE" zapata_file
+		cat <<EOF >$zaptel_file
 # Autogenerated by $0 -- do not hand edit
 # Zaptel Configuration File
 #
@@ -638,7 +821,7 @@
 # It must be in the module loading order
 
 EOF
-			cat <<EOF >$zapata_file
+		cat <<EOF >$zapata_file
 ; Autogenerated by $0 -- do not hand edit
 ; Zaptel Channels Configurations (zapata.conf)
 ;
@@ -672,10 +855,10 @@
 		case "$mode" in
 		list) echo "### $title";;
 		files)
-		  echo ""         >>$zaptel_file
-		  echo "# $title" >>$zaptel_file
-		  echo ""         >>$zapata_file
-		  echo "; $title" >>$zapata_file
+			echo ""         >>$zaptel_file
+			echo "# $title" >>$zaptel_file
+			echo ""         >>$zapata_file
+			echo "; $title" >>$zapata_file
 			;;
 		esac
 		echo '-1'  >$tmp_dir/span_begin
@@ -749,74 +932,7 @@
 				print_pattern -a input $chan_num fxo $mode
 				;;
 			*ZTHFC*/*|*ztqoz*/*|*ztgsm/*|*TE[24]/*|*WCT1/*|*Tor2/*|*TorISA/*|*XPP_BRI_*/*|*WP[TE]1/*)
-				# PRI/BRI channel
-				# Rather than identifying cards by the header line, we identify them by the channel names
-				# This is shorter. This also allows us to count the channel numbers and check if a PRI
-				# card is E1 or T1.
-				if [ "`cat $tmp_dir/span_begin`" = "-1" ]
-				then
-					echo $chan_num      >$tmp_dir/span_begin
-					echo $span_num      >$tmp_dir/span_num
-					# The Astribank channels provide the information of TE/NT in the channel name. So 
-					# why not use it?
-					case "$line" in
-					*XPP_BRI_TE/*) echo 'te' >$tmp_dir/span_termtype;;
-					*XPP_BRI_NT/*) echo 'nt' >$tmp_dir/span_termtype;;
-					esac
-					case "$line" in
-					*ZTHFC*/*|*ztqoz*/*|*XPP_BRI_*/*)
-						# BRI channel
-						echo 'ccs'          >$tmp_dir/span_framing
-						echo 'euroisdn'     >$tmp_dir/span_switchtype
-						if [ "`cat $tmp_dir/span_termtype`" = 'nt' 2>/dev/null ]
-						then
-							echo $ZAPBRI_NET >$tmp_dir/span_signalling 
-						else
-							echo $ZAPBRI_CPE >$tmp_dir/span_signalling
-						fi
-						;;
-					*ztgsm*/*)
-						# Junghanns's GSM cards. 
-						echo 'ccs'          >$tmp_dir/span_framing
-            # what switch type? Any meaning to it?
-						echo 'gsm'          >$tmp_dir/span_signalling
-						;;
-					*TE[24]/*|*WCT1/*|*Tor2/*|*TorISA/*|*WP[TE]1/*)
-						# PRI span (E1/T1)
-						echo 'esf'       >$tmp_dir/span_framing
-						echo 'b8zs'      >$tmp_dir/span_coding
-						echo 'national'  >$tmp_dir/span_switchtype
-						echo 'pri_cpe'   >$tmp_dir/span_signalling
-						# an example of country-specific setup. This is probably not accurate
-						# Contributions are welcome
-						case "$lc_country" in 
-						nl)
-							# (Just an example for per-country info)
-							echo 'ccs'       >$tmp_dir/span_framing
-							echo 'ami'       >$tmp_dir/span_coding
-							#echo 'crc4'      >$tmp_dir/span_yellow
-							#echo 'euroisdn'  >$tmp_dir/span_switchtype
-							#echo 'pri_cpe'   >$tmp_dir/span_signalling
-							;;
-						il|de|au)
-							echo 'ccs'       >$tmp_dir/span_framing
-							echo 'hdb3'      >$tmp_dir/span_coding
-							echo 'crc4'      >$tmp_dir/span_yellow
-							echo 'euroisdn'  >$tmp_dir/span_switchtype
-							;;
-						cl)
-							echo 'ccs'       >$tmp_dir/span_framing
-							echo 'hdb3'      >$tmp_dir/span_coding
-							#echo 'crc4'      >$tmp_dir/span_yellow
-							echo 'national'  >$tmp_dir/span_switchtype
-							;;
-						esac
-					;;
-					esac
-				fi
-				# span_lastd is always the one before last 
-				# channel. span_bchan is the last:
-				echo $chan_num      >$tmp_dir/span_end
+				detect_digital_channel "$line" "$chan_num" "$span_num"
 				;;
 			'') ;;		# Empty line (after span header)
 			*) 
@@ -831,97 +947,7 @@
 		done
 		# end of part in sub-process.
 		
-		if [ "`cat $tmp_dir/span_begin`" != -1 ]
-		then # write PRI span ocnfig:
-			# read files to variables:
-			for suffix in num begin end timing lbo framing \
-				coding switchtype signalling yellow termtype
-			do
-				eval span_$suffix=`cat $tmp_dir/span_$suffix 2>/dev/null`
-			done
-			if [ "$span_yellow" != '' ]; then span_yellow=",$span_yellow"; fi
-			# exactly the same logic is used in asterisk's chan_zap.c.
-			# also not that $(( )) is bash-specific
-			case "$((1+ $span_end - $span_begin))" in
-			2|3|24) #ztgsm, BRI or T1
-			  dchan=$span_end
-				bchans="$span_begin-$(($span_end-1))"
-				;;
-			31) #E1
-				dchan="$(($span_begin+15))"
-				bchans="$span_begin-$(($span_begin+14)),$(($span_begin+16))-$span_end"
-				if [ "$span_switchtype" = 'national' ]; then
-					span_framing=ccs
-					span_coding=hdb3
-					span_switchtype=euroisdn
-				fi
-				;;
-			esac
-			# Let's assume that a TE span should get the clock from the remote unit,
-			# and NT spans should provide timing. Just as a sane default.
-			# If we have several TE spans, the first will have priority 1, 
-			# second: 2, etc.
-			case "$span_signalling" in *_cpe*)
-				span_timing=$span_te_timing_counter
-				span_te_timing_counter=$(($span_te_timing_counter + 1))
-				;;
-			esac
-			case "$mode" in
-			files)
-				echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow >> $zaptel_file
-				if [ "$span_termtype" != '' ]
-				then echo "# termtype: $span_termtype" >>$zaptel_file
-				fi
-				echo bchan=$bchans >>$zaptel_file
-				echo dchan=$dchan  >>$zaptel_file
-				
-				if [ "$span_termtype" != '' ]
-				then
-					# an ISDN card's span that we know if it is in NT mode or TE mode.
-					# NT is the same as FXS for us and TE is the same as FXO
-					if [ "$span_termtype" = 'nt' ]
-					then
-						echo "callerid=\"Channels $span_begin - $span_end\" <$span_begin>" >> $zapata_file
-						reset_values="$reset_values callerid"
-						#echo "mailbox=$exten"
-						if [ "$group_manual" != "yes" ]
-						then 
-							echo "group=$group_phones"     >> $zapata_file
-							reset_values="$reset_values group"
-						fi
-						if [ "$context_manual" != "yes" ]
-						then 
-							echo "context=$context_phones" >> $zapata_file
-						fi
-					else # we have may have set it. So reset it:
-						echo "callerid=asreceived"       >> $zapata_file
-						reset_values="$reset_values callerid"
-						#echo "mailbox="
-						if [ "$group_manual" != "yes" ]
-						then 
-							echo "group=$group_lines"      >> $zapata_file
-							reset_values="$reset_values group"
-						fi
-						if [ "$context_manual" != "yes" ]
-						then 
-							echo "context=$context_lines"  >> $zapata_file
-							reset_values="$reset_values context"
-						fi
-					fi
-				fi
-				echo "switchtype = $span_switchtype" >> $zapata_file
-				echo "signalling = $span_signalling" >> $zapata_file
-				echo "channel => $bchans"            >> $zapata_file
-				reset_zapata_entry $zapata_file $reset_values
-				;;
-			list)
-				echo "### BRI/PRI: $span_termtype" 
-				echo "$bchans Data"
-				echo "$dchan Control"
-				#echo BRI/PRI: chans: $bchans, control: $dchan
-				;;
-			esac
-		fi
+		write_digital_config
 	done
 
 	if [ "$mode" = 'files' ]
@@ -936,14 +962,18 @@
 	fi
 	
 	if [ "$mode" = 'files' ]; then
-		mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak
+		mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak 2>/dev/null
 		mv $zaptel_file ${ZAPCONF_FILE}
-		mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak
+		mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak 2>/dev/nullk
 		mv $zapata_file ${ZAPATA_FILE}
-	fi
-}
-
-while getopts 'c:de:Fhlm:MRsuv' arg
+		if [ "$do_gen_zapscan" = 'yes' ]; then
+			mv $ZAPSCAN_FILE $ZAPSCAN_FILE.bak 2>/dev/null 
+			mv $zapscan_file $ZAPSCAN_FILE
+		fi
+	fi
+}
+
+while getopts 'c:de:Fhlm:MRsuvz' arg
 do
 	case "$arg" in
 		e) # guarantee that it is a number:
@@ -959,6 +989,7 @@
 		M) do_module_list=yes; do_detect=yes ;;
 		s) force_stop_ast=yes ;;
 		R) do_restart=no ;;
+		z) do_gen_zapscan=yes ;;
 		h) usage; exit 0;;
 		*) echo >&2 "unknown parameter -$arg, Aborting"; usage; exit 1;;
 	esac
@@ -991,14 +1022,14 @@
 # make sure asterisk is not in our way
 if [ "$force_stop_ast" = 'yes' ]
 then
-  /etc/init.d/asterisk stop 1>&2
+	/etc/init.d/asterisk stop 1>&2
 else
   # if asterisk is running and we wanted to detect modules
 	# or simply to unload modules, asterisk needs to go away.
 	if ( [ "$do_unload" = yes ] || [ "$do_detect" = yes ] ) && \
-	  pidof asterisk >/dev/null 
+		pidof asterisk >/dev/null 
 	then
-	  echo >&2 "Asterisk is already running. Configuration left untouched"
+		echo >&2 "Asterisk is already running. Configuration left untouched"
 		echo >&2 "You can use the option -s to shut down Asterisk for the"
 		echo >&2 "duration of the detection."
 		exit 1
@@ -1028,17 +1059,17 @@
 
 if [ "$tmp_dir" != '' ]
 then
-  rm -rf "$tmp_dir"
+	rm -rf "$tmp_dir"
 fi
 
 if [ "$force_stop_ast" != 'yes' ] || [ "$do_restart" != 'yes' ]
 then
-  exit 0
+	exit 0
 fi
 
 if [ -x /etc/init.d/asterisk ]
 then
-  /etc/init.d/asterisk start 1>&2
+	/etc/init.d/asterisk start 1>&2
 fi
 
 # if in verbose mode: verify that asterisk is running
@@ -1054,4 +1085,4 @@
 	fi
 fi
 
-# vim:ts=2:
+# vim:ts=8:

Modified: trunk/xpp/utils/genzaptelconf.8
URL: http://svn.digium.com/view/zaptel/trunk/xpp/utils/genzaptelconf.8?view=diff&rev=2332&r1=2331&r2=2332
==============================================================================
--- trunk/xpp/utils/genzaptelconf.8 (original)
+++ trunk/xpp/utils/genzaptelconf.8 Thu Mar 22 02:01:21 2007
@@ -5,7 +5,7 @@
 .SH SYNOPSIS
 .PP 
 .B genzaptelconf 
-[-sRdv] [-c <country_code>] [-e <base_exten>] [ -F ]
+[-sRdvzF] [-c <country_code>] [-e <base_exten>]
 
 .B genzaptelconf 
 [-sRdv] -l -- only list to standard output
@@ -27,7 +27,7 @@
 .I PRI
 and 
 .I BRI
-(HFC, with ZapBRI) cards are basically identified as well. However the span
+(with ZapBRI) cards are basically identified as well. However the span
 configiration is a default that I only hope is sane. Looking for feedback
 
 .SH OPTIONS
@@ -126,6 +126,14 @@
 is used. Lists detected channls. In the end tries to connect to asterisk
 to get a list of configured zaptel channels.
 .RE
+
+.B -z
+.RS
+emulate the operation of zapscan.bin: generate 
+.I /etc/asterisk/zapscan.conf
+with the results of the scan.
+.RE
+
 .SH CONFIGURATION
 Look at the beginning of the script for a number of variables that can 
 be overriden through the configuraion file. Some variables can also be 



More information about the zaptel-commits mailing list