/[smecontribs]/rpms/smeserver-freepbx/contribs7/smeserver-freepbx-0.1-genzaptelconf.patch
ViewVC logotype

Contents of /rpms/smeserver-freepbx/contribs7/smeserver-freepbx-0.1-genzaptelconf.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Mon Mar 2 17:31:24 2009 UTC (15 years, 8 months ago) by slords
Branch: MAIN
CVS Tags: smeserver-freepbx-0_1-12_el4_sme, smeserver-freepbx-0_1-22_el4_sme, smeserver-freepbx-0_1-28_el4_sme, smeserver-freepbx-0_1-29_el4_sme, smeserver-freepbx-0_1-26_el4_sme, smeserver-freepbx-0_1-25_el4_sme, smeserver-freepbx-0_1-15_el4_sme, smeserver-freepbx-0_1-31_el4_sme, smeserver-freepbx-0_1-21_el4_sme, smeserver-freepbx-0_1-23_el4_sme, smeserver-freepbx-0_1-27_el4_sme, smeserver-freepbx-0_1-9_el4_sme, smeserver-freepbx-0_1-24_el4_sme, smeserver-freepbx-0_1-30_el4_sme, smeserver-freepbx-0_1-17_el4_sme, smeserver-freepbx-0_1-13_el4_sme, smeserver-freepbx-0_1-20_el4_sme, smeserver-freepbx-0_1-14_el4_sme, smeserver-freepbx-0_1-32_el4_sme, smeserver-freepbx-0_1-18_el4_sme, smeserver-freepbx-0_1-16_el4_sme, HEAD
Initial import of smeserver-freepbx

1 diff -Nur -x '*.orig' -x '*.rej' smeserver-freepbx-0.1/root/var/lib/asterisk/bin/genzaptelconf mezzanine_patched_smeserver-freepbx-0.1/root/var/lib/asterisk/bin/genzaptelconf
2 --- smeserver-freepbx-0.1/root/var/lib/asterisk/bin/genzaptelconf 1970-01-01 01:00:00.000000000 +0100
3 +++ mezzanine_patched_smeserver-freepbx-0.1/root/var/lib/asterisk/bin/genzaptelconf 2008-11-05 19:38:16.000000000 +0100
4 @@ -0,0 +1,570 @@
5 +#! /bin/bash
6 +
7 +# genzaptelconf: generate as smartly as you can:
8 +# /etc/zaptel.conf
9 +# /etc/asterisk/zapata-channels.conf (to be #include-d into zapata.conf)
10 +# update:
11 +# /etc/default/zaptel (list of modules to load)
12 +#
13 +# $Id:$
14 +#
15 +
16 +# The script uses a number of bash-specific features
17 +# TODO: either ditch them or convert to perl
18 +
19 +# /etc/default/zaptel may override the following variables
20 +lc_country=us
21 +#method=ls
22 +#method=ks
23 +base_exten=6000
24 +
25 +
26 +ZAPCONF_FILE=/etc/zaptel.conf
27 +ZAPATA_FILE=/etc/asterisk/zapata-auto.conf
28 +ZAPTEL_BOOT=/etc/sysconfig/zaptel
29 +exten_base_dir=/etc/asterisk/extensions-phones.d
30 +exten_defs_file=/etc/asterisk/extensions-defs.conf
31 +ztcfg_cmd=ztcfg
32 +
33 +# a temporary directory. Created when the switch -r is parsed on getopts
34 +# and deleted in the end on update_extensions_defs
35 +tmp_dir=
36 +
37 +# read default configuration from /etc/default/zaptel
38 +if [ -r $ZAPTEL_BOOT ]; then . $ZAPTEL_BOOT; fi
39 +
40 +# work around a bug (that was already fixed) in the installer:
41 +if [ "$lc_country" = '' ]; then lc_country=us; fi
42 +
43 +ALL_MODULES="wctdm wcfxo wcfxs pciradio tor2 torisa wct1xxp wct4xxp wcte11xp wcusb ztd_eth ztdummy"
44 +force_stop_ast=yes
45 +do_detect=no
46 +do_unload=no
47 +verbose=no
48 +rapid_extens=''
49 +# global: current extension number in extensions list. Should only be
50 +# changed in print_pattern:
51 +rapid_cur_exten=1
52 +# set the TRUNK in extensidialplan dialplan defs file rapid_conf_mode=no
53 +
54 +die() {
55 + echo "$@" >&2
56 + exit 1
57 +}
58 +
59 +say() {
60 + if [ "$verbose" = no ]; then
61 + return
62 + fi
63 + echo "$@" >&2
64 +}
65 +
66 +run_ztcfg() {
67 + if [ "$verbose" = no ]; then
68 + $ztcfg_cmd "$@"
69 + else
70 + say "Reconfiguring identified channels"
71 + $ztcfg_cmd -vv "$@"
72 + fi
73 +}
74 +
75 +do_update() {
76 + sed -i.bak "s/^$1=.*\$/$1=\"$2\"/" ${ZAPTEL_BOOT}
77 + if ! grep -q "^$1=" ${ZAPTEL_BOOT}; then
78 + echo "$1=\"$2\"" >> ${ZAPTEL_BOOT}
79 + fi
80 +}
81 +
82 +update_extensions_defs() {
83 + if [ "$rapid_conf_mode" = 'yes' ]
84 + then
85 + say "DEBUG: Updating dialplan defs file $exten_defs_file"
86 + if [ "`echo $tmp_dir/fxo_* | grep -v '*'`" != '' ]
87 + then
88 + trunk_nums=`cat $tmp_dir/fxo_* | sort -n | xargs`
89 + say "Configuring TRUNK to be [first of] zaptel channels: $trunk_nums"
90 + trunk_dev=`echo $trunk_nums| sed -e 's/ /\\\\\\&/g' -e 's/[0-9a-zA-Z]\+/Zap\\\\\\/&/g'`
91 + echo >&2 sed -i "s/^TRUNK.*=>.*/TRUNK => $trunk_dev/" $exten_defs_file
92 + sed -i "s/^TRUNK.*=>.*/TRUNK => $trunk_dev/" $exten_defs_file
93 + if ! grep -q "^TRUNK =>" $exten_defs_file; then
94 + trunk_dev=`echo $trunk_nums| sed -e 's/ /&/g' -e 's/[0-9a-zA-Z]*/Zap\\/&/g'`
95 + echo "TRUNK => $trunk_dev" >> $exten_defs_file
96 + fi
97 + else
98 + say "Warning: No FXO channel for trunk. Moving on."
99 + fi
100 + if [ "`echo $tmp_dir/fxs_* | grep -v '*'`" != '' ]
101 + then
102 + fxs_nums=`cat $tmp_dir/fxs_* | sort -n | xargs`
103 + zap_nums=`grep '^[^;].*Zap/\${CHAN_ZAP_' $exten_base_dir/*.conf | \
104 + sed -e 's/.*Zap\/\${CHAN_ZAP_\([0-9]*\)}.*/\1/' | sort -u | xargs`
105 + say "Configuring channels: $fxs_nums as channel placeholders: $zap_nums"
106 + j=1
107 + for i in $zap_nums
108 + do
109 + chan=`echo $fxs_nums | awk "{print \\$$i}"`
110 + if [ "$chan" = '' ]
111 + then
112 + # if the result is empty, we probably got past the last one.
113 + # bail out.
114 + say "Warning: No FXS channel for CHAN_ZAP_$i. Moving on"
115 + break
116 + fi
117 + say "DEBUG: setting channel $chan to placeholder $i"
118 + if grep -q "^CHAN_ZAP_$i " $exten_defs_file
119 + then
120 + sed -i -e "s/^CHAN_ZAP_$i .*/CHAN_ZAP_$i => Zap\/$chan/" $exten_defs_file
121 + else
122 + echo "CHAN_ZAP_$i => Zap/$chan" >> $exten_defs_file
123 + fi
124 + done
125 + fi
126 + # cleaning up the temp dir
127 + if [ -d "$tmp_dir" ]; then rm -rf "$tmp_dir"; fi
128 + fi
129 +}
130 +
131 +usage() {
132 + program=`basename $0`
133 +
134 + echo >&2 "$program: generate zaptel.conf"
135 + echo >&2 "usage:"
136 + echo >&2 " $program [-v] [-m k|l|g] [-c <country_code>] [-r |-e <base_exten>] "
137 + echo >&2 " $program [-v] -l"
138 + echo >&2 " $program -u"
139 + echo >&2 " $program -h (this screen)"
140 + echo >&2 ""
141 + echo >&2 "Options:"
142 + echo >&2 " -c CODE: set the country code (default: $lc_country)"
143 + echo >&2 " -e NUM: set the base extension number (default: $base_exten)"
144 + echo >&2 " -m: set signalling method (gs/ks/ls, default: $method)"
145 + echo >&2 " -l: output a list of detected channels instead of zaptel.conf"
146 + echo >&2 " -u: Unload zaptel modules"
147 + echo >&2 " -v: verbose"
148 + echo >&2 " -r: rapid configuration mode: configure Zaptel FXS channels from "
149 + echo >&2 " existing Rapid extension files. FXOs will all be TRUNK "
150 +}
151 +
152 +# $1: channel number
153 +print_pattern() {
154 + local chan=$1
155 + local sig=$2 #fxs/fxo
156 + local mode=$3
157 + case "$mode" in
158 + zaptel) echo "${sig}$method=$chan" ;;
159 + list) echo $chan $sig;;
160 + zapata)
161 + echo "signalling=${sig}_$method"
162 + if [ "$sig" = 'fxo' ]
163 + then
164 + echo "; Note: this is an extension. Create a ZAP extension in AMP for Channel $chan"
165 + echo "context=from-internal"
166 + echo "group=1"
167 + # to preconfigure channel 1's extension to 550, set
168 + # chan_1_exten=550
169 + # in, e.g, /etc/default/zaptel
170 + var_name=`echo chan_${chan}_exten`
171 + cfg_exten=`echo ${!var_name} | tr -d -c 0-9`
172 + var_name=`echo chan_${chan}_vmbox`
173 + cfg_vmbox=`echo ${!var_name} | tr -d -c 0-9`
174 + var_name=`echo chan_${chan}_cntxt`
175 + cfg_cntxt=`echo ${!var_name} | tr -d -c 0-9`
176 +
177 + # if option -E was given, get configuration from current extension
178 + if [ "$rapid_conf_mode" = 'yes' ]
179 + then
180 + rap_exten=`echo $rapid_extens |awk "{print \\$$rapid_cur_exten}"`
181 + if [ "$rap_exten" != '' ]
182 + then
183 + rap_cfgfile="$exten_base_dir/$rap_exten.conf"
184 + if [ -r "$rap_exten" ]
185 + then
186 + cfg_exten=$rap_exten
187 + # the vmbox is the third parameter to stdexten
188 + rap_vmbox=`grep '^[^;].*Macro(stdexten' $rap_exten | cut -d, -f3 \
189 + | cut -d')' -f1 | tr -d -c '0-9@a-zA-Z'`
190 + if [ "$rap_vmbox" ]!= '' ; then cfg_vmbox=$rap_vmbox; fi
191 + fi
192 + fi
193 + rapid_cur_exten=$(($rapid_cur_exten + 1))
194 + fi
195 +
196 + if [ "$cfg_exten" = '' ]
197 + then # No extension number set for this channel
198 + exten=$(($chan+$base_exten))
199 + else # use the pre-configured extension number
200 + exten=$cfg_exten
201 + fi
202 + # is there any real need to set 'mailbox=' ?
203 + if [ "x$cfg_vmbox" = x ]
204 + then # No extension number set for this channel
205 + vmbox=$exten
206 + else # use the pre-configured extension number
207 + vmbox=$cfg_vmbox
208 + fi
209 + # echo "callerid=\"Channel $chan\" <$exten>"
210 + # echo "mailbox=$exten"
211 + else # we have may have set it. So reset it:
212 + echo "; Note: this is a trunk. Create a ZAP trunk in AMP for Channel $chan"
213 + echo "context=from-zaptel"
214 + echo "group=0"
215 + # echo "callerid=\"\" <0>"
216 + # echo "mailbox="
217 + fi
218 +
219 + echo "channel => $chan"
220 + echo ""
221 +
222 + # Keep a note of what channels we have identified
223 + say "DEBUG: adding to channels list: channel: $chan, sig: $sig"
224 + case "$sig" in
225 + fxs)
226 + echo $chan >$tmp_dir/fxo_$chan
227 + say "DEBUG: FXO list now contains: `cat $tmp_dir/fxo_* |xargs`"
228 + ;;
229 + fxo)
230 + echo $chan >$tmp_dir/fxs_$chan
231 + say "DEBUG: FXS list now contains: `cat $tmp_dir/fxs_* |xargs`"
232 + ;;
233 + esac
234 + ;;
235 + esac
236 +
237 +}
238 +
239 +# the number of channels from /proc/zaptel
240 +# must always print a number as its output.
241 +count_proc_zap_lines() {
242 + # if zaptel is not loaded there are 0 channels:
243 + if [ ! -d /proc/zaptel ]; then echo '0'; return; fi
244 +
245 + (
246 + for file in `echo /proc/zaptel/* |grep -v '\*'`
247 + do sed -e 1,2d $file # remove the two header lines
248 + done
249 + ) | wc -l # the total number of lines
250 +}
251 +
252 +load_modules() {
253 + say "Test Loading modules:"
254 + for i in zaptel $ALL_MODULES
255 + do
256 + if [ "$i" = ztdummy ]; then
257 + continue # No hardware to detect
258 + fi
259 + lines_before=`count_proc_zap_lines`
260 + args="${i}_args"
261 + eval "args=\$$args"
262 + # a module is worth listing if it:
263 + # a. loaded successfully, and
264 + # b. added channels lines under /proc/zaptel/*
265 + if /sbin/modprobe $i $args 2> /dev/null && \
266 + [ $lines_before -lt `count_proc_zap_lines` ]
267 + then
268 + probed_modules="$probed_modules $i"
269 + say " ok $i $args"
270 + else
271 + say " - $i $args"
272 + fi
273 + done
274 +}
275 +
276 +
277 +unload_modules() {
278 + if
279 + pids="$(pgrep asterisk)"
280 + [ "$pids" != '' ]
281 + then
282 + die "Before unloading -- STOP asterisk (pids=$pids)."
283 + fi
284 + say "Unloading zaptel modules:"
285 + modlist=''
286 + for i in $ALL_MODULES zaptel
287 + do
288 + if lsmod | grep "^$i *" > /dev/null; then
289 + modlist="$modlist $i"
290 + say -n "$i "
291 + fi
292 + done
293 + /sbin/modprobe -r $modlist
294 + say ''
295 +}
296 +
297 +detect() {
298 + unload_modules
299 + load_modules
300 + modlist="$probed_modules"
301 + #for i in $ALL_MODULES
302 + #do
303 + # if lsmod | grep "^$i *" > /dev/null; then
304 + # modlist="$modlist $i"
305 + # fi
306 + #done
307 + modlist="$(echo $modlist)" # clean spaces
308 + if [ "$modlist" = '' ]; then
309 + modlist=ztdummy # Fallback
310 + fi
311 + say "Updating '${ZAPTEL_BOOT}'"
312 + do_update ZAPTEL_MODS "$modlist"
313 +}
314 +
315 +check_tdm_sigtype() {
316 + chan_num=$1
317 + sig_type=$2
318 + mode=$3
319 +
320 + case "$sig_type" in
321 + fxs)chan_sig_type=fxo;;
322 + fxo)chan_sig_type=fxs;;
323 + esac
324 +
325 +# print_pattern $chan_num $chan_sig_type $mode
326 +
327 + $ztcfg_cmd -c <(print_pattern $chan_num $chan_sig_type zaptel) 2>/dev/null \
328 + || return 1
329 + if head -c1 /dev/zap/$chan_num >/dev/null 2>/dev/null
330 + then
331 + print_pattern $chan_num $chan_sig_type $mode
332 + return 0
333 + else
334 + return 1
335 + fi
336 +}
337 +
338 +# output a list of extensions that need a channel
339 +get_rapid_extens() {
340 + if [ "$rapid_conf_mode" = 'yes' ]
341 + then
342 + rapid_extens=`grep -l '^[^;].*Zap/\${CHAN_ZAP_' $exten_base_dir/*.conf 2>/dev/null | \
343 + rev | cut -d/ -f1 | cut -d. -f2- | rev | xargs`
344 + say "Need to configure extensions: $rapid_extens"
345 + fi
346 +}
347 +
348 +genconf() {
349 + local mode=$1
350 +
351 + # reset FXO list (global)
352 + say "DEBUG: resetting channels lists"
353 + rm -f $tmp_dir/fx{s,o}_*
354 +
355 + if [ "$mode" = 'zapata' ]
356 + then
357 + rem_char=';'
358 + else
359 + rem_char='#'
360 + fi
361 +
362 + spanlist=`echo /proc/zaptel/* | grep -v '\*'`
363 +
364 + #if [ "$spanlist" == "" ]; then
365 + # die "No zapata interfaces in /proc/zaptel"
366 + #fi
367 +
368 +
369 + case "$mode" in
370 + zaptel)
371 + cat <<EOF
372 +# Autogenerated by $0 -- do not hand edit
373 +# Zaptel Configuration File
374 +#
375 +# This file is parsed by the Zaptel Configurator, ztcfg
376 +#
377 +
378 +# It must be in the module loading order
379 +
380 +EOF
381 + ;;
382 + zapata)
383 + cat <<EOF
384 +; Autogenerated by $0 -- do not hand edit
385 +; Zaptel Channels Configurations (zapata.conf)
386 +;
387 +; This is not intended to be a complete zapata.conf. Rather, it is intended
388 +; to be #include-d by /etc/zapata.conf that will include the global settings
389 +;
390 +callerid=asreceived
391 +EOF
392 + ;;
393 + esac
394 +
395 + # For each line in the spanlist: see if it represents a channel.
396 + # if it does, test that the channel is usable.
397 + # we do that by configuring it (using ztcfg with a 1-line config file)
398 + # and then trying to read 1 byte from the device file.
399 + #
400 + # The '<(command)' syntax creates a temporary file whose content is is the
401 + # output of 'command'.
402 + #
403 + # This approach failed with the T1 card we have: the read operation simply
404 + # hung.
405 + #
406 + # Another problem with such an approach is how to include an existing
407 + # configuration file. For instance: how to include some default settings.
408 + #
409 + # Maybe an 'include' directive should be added to zaptel.conf ?
410 + #cat $spanlist |
411 + for procfile in $spanlist
412 + do
413 + # the first line is the title line. It states the model name
414 + # the second line is empty
415 + title=`head -n 1 $procfile`
416 + echo ""
417 + echo "$rem_char $title"
418 +
419 + # The rest of the lines are per-channel lines
420 + sed -e 1,2d $procfile | \
421 + while read line
422 + do
423 + # in case this is a real channel.
424 + chan_num=`echo $line |awk '{print $1}'`
425 + case "$line" in
426 + *WCT1/*) # we're yet to detect when a channel is active
427 + echo "$rem_char channel $chan_num, WCT1, unhandled for now"
428 + ;;
429 + *WCTDM/*)
430 + # this can be either FXS or FXO
431 + check_tdm_sigtype $chan_num fxs $mode || \
432 + check_tdm_sigtype $chan_num fxo $mode || \
433 + echo "$rem_char channel $chan_num, WCTDM, inactive."
434 + ;;
435 + *WRTDM/*)
436 + # this can be either FXS or FXO
437 + check_tdm_sigtype $chan_num fxs $mode || \
438 + check_tdm_sigtype $chan_num fxo $mode || \
439 + echo "$rem_char channel $chan_num, WRTDM, inactive."
440 + ;;
441 + *WCFXO/*)
442 + check_tdm_sigtype $chan_num fxo $mode || \
443 + echo "$rem_char channel $chan_num, WCFXO, inactive."
444 + ;;
445 + '') ;; # Empty line (after span header)
446 + *) echo "$rem_char ??: $line";;
447 + esac
448 + done
449 + done
450 +
451 + if [ "$mode" = 'zaptel' ]
452 + then
453 + cat <<EOF
454 +
455 +# Global data
456 +
457 +EOF
458 + echo "loadzone = $loadzone"
459 + echo "defaultzone = $defaultzone"
460 + fi
461 +
462 + if [ "$mode" = 'zapata' ]
463 + then
464 + update_extensions_defs
465 + fi
466 +}
467 +
468 +while getopts 'c:de:E:hlm:rsuv' arg
469 +do
470 + case "$arg" in
471 + e) # guarantee that it is a number:
472 + new_base_exten=`echo $OPTARG | tr -d -c 0-9`
473 + if [ "x$new_base_exten" != x ]; then base_exten=$new_base_exten; fi
474 + ;;
475 + c) lc_country=`echo $OPTARG | tr -d -c a-z` ;;
476 + u) do_unload=yes ;;
477 + v) verbose=yes ;;
478 + l) mode='list' ;;
479 + m)
480 + case "$OPTARG" in
481 + k|l|g)method=${OPTARG}s ;;
482 + *) echo >&2 "unknown signalling method ${OPTARG}s, defaulting to \"$method\"";;
483 + esac
484 + ;;
485 + r)
486 + rapid_conf_mode=yes
487 + tmp_dir=`mktemp -d` || die "$0: failed to create temporary directory. Aborting"
488 + ;;
489 + *) echo >&2 "unknown parameter -$arg, Aborting"; usage; exit 1;;
490 + esac
491 +done
492 +shift $(( $OPTIND-1 ))
493 +if [ $# != 0 ]; then
494 + echo >&2 "$0: too many parameters"
495 + usage
496 + exit 1
497 +fi
498 +
499 +case "$lc_country" in
500 + # the list was generated from the source of zaptel:
501 + #grep '{.*[0-9]\+,.*"[a-z][a-z]"' zonedata.c | cut -d'"' -f 2 | xargs |tr ' ' '|'
502 + us|au|fr|nl|uk|fi|es|jp|no|at|nz|it|gr|tw|cl|se|be|il)
503 + :;;
504 +*)
505 + lc_country=us
506 + echo >&2 "unknown country-code $lc_country, defaulting to \"us\"";;
507 +esac
508 +# any reason for loadzone and defaultzone to be different? If so, this is
509 +# the place to make that difference
510 +loadzone=$lc_country
511 +defaultzone=$loadzone
512 +
513 +# Choose reasonable default for signaling method (by country)
514 +if [ "" = "$method" ]; then
515 + case "$lc_country" in
516 + il) method=ls ;;
517 + *) method=ks ;;
518 + esac
519 +fi
520 +
521 +# make sure asterisk is not in our way
522 +if [ "$force_stop_ast" = 'yes' ]
523 +then
524 +# /etc/init.d/asterisk stop 1>&2
525 + /usr/sbin/amportal stop 1>&2
526 +else
527 + if ps auxww |grep asterisk | grep -v -- -r | grep -q -v grep
528 + then
529 + echo >&2 "Asterisk is already running. Configuration left untouched"
530 + echo >&2 "You can use the option -s to shut down Asterisk for the"
531 + echo >&2 "duration of the detection."
532 + exit 1
533 + fi
534 +fi
535 +
536 +if [ "$do_unload" = yes ]
537 +then
538 + unload_modules
539 + exit
540 +fi
541 +
542 +if [ "$do_detect" = yes ]
543 +then
544 + detect
545 +fi
546 +
547 +if [ "$mode" = list ]; then
548 + genconf list
549 +else
550 + get_rapid_extens
551 + echo "Generating '${ZAPCONF_FILE}'"
552 + mv "${ZAPCONF_FILE}" "${ZAPCONF_FILE}.bak"
553 + genconf zaptel > "${ZAPCONF_FILE}"
554 + echo "Generating '${ZAPATA_FILE}'"
555 + mv "${ZAPATA_FILE}" "${ZAPATA_FILE}.bak"
556 + genconf zapata > "${ZAPATA_FILE}"
557 + run_ztcfg
558 +fi
559 +
560 +if [ "$force_stop_ast" = 'yes' ]
561 +then
562 +# /etc/init.d/asterisk start 1>&2
563 + /etc/init.d/zaptel stop
564 + /etc/init.d/zaptel start
565 + /usr/sbin/amportal start 1>&2
566 +fi
567 +
568 +# if in verbose mode: verify that asterisk is running
569 +if [ "$verify" != 'no' ]
570 + then
571 + say "Checking channels configured in Asterisk:"
572 + sleep 1 # give it some time. This is enough on our simple test server
573 + /usr/local/sbin/ast-cmd cmd "zap show channels"
574 +fi

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed