#! /bin/bash # SCRIPT_VERSION=1.3.4 SCRIPT_DATE="27 June 2007" # # Usual caveats apply, so make sure you have backups: BEFORE YOU START!. # # Writtten by W1zz (for support: w1zz at brightheadtechnology com) # # For those that have copied large chunks of this code, please remember to credit the author. # # This script is explicitly designed to load bristuff for BRI ISDN # # It was written and tested against AAH 2.0 (from ISO) # # It has been tested with other releases of AAH, Trixbox and asterisk but Your Mileage May Vary! # # I don't expect other bristuff devices to work with this script. # (which does not mean they won't - but don't expect it) # Reported issues: # # - One user reported that running from an ISO build (AAH2.0) on a dual CPU machine # that /bin/sh could not be found. [WORKAROUND] replace #!/bin/sh above with #!/bin/bash # # - Not known to be an issue: But if you have tried installing using a method similar to that # described on http://dondisperato.blogspot.com/ then you should remove the edits in /etc/rc.d/rc.local # This scripts configures Asterisk to load the zaphfc module in the same way that it # loads any other zap module # # - Also reported: "During the script I saw a FAILED flash by during zaptel unload. But zaptel # seems to never unload correctly....." (by the same person as it happens). # # - Not all motherboards will run the bristuff patched code. E.g. a motherboard known not to work is the Asus A7VC # If this is the case you may be best reporting this to the guys at Junghanns. # Otherwise you'll need to find another motherboard. # # - Reported by DonDisparato: # # "1) for use with an X100P card # # run Alan script and after unselect zaptel in system service and edit rc.local file like this: # # modprobe zaptel # sleep 10 # modprobe zaphfc # modprobe wcfxo # ztcfg -vv " # #--- I think that you will find that if you edit /etc/sysconfig/zaptel and uncomment all modules required, #--- then the above modifications are not needed. E.g as this script adds the entry for zaphfc all you #--- would need to do is un-comment the entry for wcfxo. # # 2) for use HFC card in NT mode # # "run Alan script and after unselect zaptel in system service and edit rc.local file like this: # # modprobe zaptel # sleep 10 # insmod /usr/src/bristuff-0.3.0-PRE-1d/zaphfc/zaphfc.ko modes=1 # ztcfg -vv " # #--- A command line option (-N) has been added to do this within this script. # # 3) for sync lost or crc error i suggest the installation of Florz' Patch (http://zaphfc.florz.dyndns.org/) that is avaiable for bristuff 0.3.0 PRE-1 packages # #--- A command line option (-f) has been added to do this within this script. # # # - Following a request from Gertjan to address the issues that arise if udev is updated, I've added a test # for the presence of the new zaptel.rules file. If it is not there I'll run a make install-udev. # # 31 January 2006 # - Added support for multiple cards (currently 4 - as I've not heard of anyone being mad enough to run more). # - Removed support for the -o Override option. # - Removed -N NT mode option as this may be confusing with multi-card setup # # 3 February 2006 # - Added new parameters to cope with the non-alignment of version numbers # - Added support for timer card and slave mode. Syntax for multi-card NT/TE chganged to match. # - Changed file modifications so that any previous edits are removed first. # # 5 February 2006 # - Added a function that updates /etc/zaptel.conf with a configuration which # I think should get most people going. # # 8 February 2006 # - Junghanns released bristuff-0.3.0-PRE-1l for * 1.2.4 # - Beefed up stop function to stop * when safe_asterisk is looping in an errored configuration situation. # e.g. If a module has not loaded when asterisk is called to start, rather than exiting, safe_asterisk # behaves as if it has abended from a running environment. It then reverts to its default behaviour to # re-start. Which in the case of the system not being in the correct configuration to start with, produces # a looping start/fail. # # 11 April 2006 # - Junghanns released bristuff-0.3.0-PRE-1n for * 1.2.6 (assumes the not released -1m would have been for 1.2.5) # - Changed the params to wget so failed downloads resume. # - Looked into the problem of Zaptel not starting cleanly in some cases. This is due to udev (but I've no clean workaround yet). # If you have a problem with starting then follow this proceedure (which always seems to work): # # amportal stop # service zaptel stop # service zaptel start # amportal start # # 12 April 2006 # - For convenience, copy fxotune to the same dir as ztcfg and zttool (/sbin) # If you call fxotune from rc.local then it will always be in the same place rather than under .../zaptel_version/fxotune. # # 25 April 2006 # - Added functions to configure zapata data for cards. (/etc/asterisk/zapata.conf, /etc/asterisk/zapata-BRI-HFC.conf) # - Added -R so the zapata-BRI-HFC.conf can be re-written. # - Changed code so that up to 8 cards could be catered for (in prepartation for future features). # - Changed the log file suffix to .log - just to make it easier for people to identify. Logs are kept (log.1, log.2, log.3 etc.) # - Lots of small code changes to use more efficient code. # - Changed the shutdown code following a suggestion from RoadKill... :-) # # - 1.0.4-1a # - Junghanns released bristuff-0.3.0-PRE-1o for * 1.2.7 # # 29 April 2006 # - Major reorganisation of code. Moved most of it in to functions. No functional changes were made. Long overdue and prompted by RoadKill. # - Added -B command line option. Will only run the build module. # - Added -C command line option. Will only run the configure module. # # 1 May 2006 # - Found a small bug in a conditional statement. # # 9 May 2006 # - Junghanns released bristuff-0.3.0-PRE-1p for * 1.2.7.1 # # 11 May 2006 # - Florz' released zaphfc_0.3.0-PRE-1o_florz-12.diff for bristuff-0.3.0-PRE-1o # # 13 June 2006 # - Updated version data for Asterisk 1.2.8 & 1.2.9.1 # - Added test for spinlock.h issue. # - Due to not always being available. Mirrored Florz's patches on my site and use this as the download source. # # 14 June 2006 # - spinlock test caused BRIstuff download to be in wrong dir. # # 20 June 2006 # - Junghanns released bristuff-0.3.0-PRE-1q for * 1.2.9.1 # # 23 June 2006 # - Updated the card detection sub-routine to use the vendor & device ID's (as collected by RoadKill from his detectVoiceHW script) # # 25 June 2006 # - Added md5 check to updated script file. # # 28 June 2006 # - Updated the help section. # # 14 July 2006 # - Added more vendor and device ID's # # 15 July 2006 # - Added a module which will mod Trixbox to cope with non-rpm build # # 15 July 2006 # - Updated version data for Asterisk 1.2.10 # # 18 July 2006 # - Junghanns released bristuff-0.3.0-PRE-1r for * 1.2.9.1 # # 10 August 2006 # - Junghanns released bristuff-0.3.0-PRE-1s for * 1.2.10 # # 15 August 2006 # - Tested Junghanns bristuff-0.3.0-PRE-1s, changed config to use zaptel 1.2.6 to match. # # 19 October 2006 # - Junghanns released bristuff-0.3.0-PRE-1t (* 1.2.12?) and bristuff-0.3.0-PRE-1u (1.2.13) # - updated a number of functions Check_For_Trixbox, Rename_File, Set_Version # # 21 October 2006 # - correct repo name for trixbox.repo # - change TE context to "context=from-zaptel" this allows the use of "Zaptel Channel" in freePBX Incoming routes without the need to edit zapata-BRI-HFC.conf # - remove app_speech_utils.so if a TB build. # - remove a bit of debug code I'd left in. # # 24 October 2006 # - Junghanns released bristuff-0.3.0-PRE-1v (fixes segfault introduced by 0.3.0-PRE-1u in chan_sip) # - don't declare FLORZ_PATCH as read only. (reported by Paul Weterings) # # 24 October 2006 # - minor updates to kernel set-up function # - # 5 December 2006 # - Junghanns released bristuff-0.3.0-PRE-1w # # 6 December 2006 # - Added a switch so that when trying to install/update kernel-devel rpm for TrixBox it will enable the TrixBox repo. # # 17 January 2007 # - Junghanns released bristuff-0.3.0-PRE-1x for * 1.2.14 # # 23 February 2007 # - Junghanns released bristuff-0.3.0-PRE-1y for * 1.2.14 # - added extra shutdown test for new zaptel zttranscode module # # 15 March 2007 # - Junghanns released bugfix bristuff-0.3.0-PRE-1y-b for * 1.2.14 # # 29 March 2007 # - Junghanns released bugfix bristuff-0.3.0-PRE-1y-d for * 1.2.14 # # 3 April 2007 # - Junghanns bristuff-0.3.0-PRE-1y-d turned out to be for * 1.2.17 - fixed in build table. # - Junghanns released bugfix bristuff-0.3.0-PRE-1y-e for * 1.2.17 # # 26 April 2007 # - Added Junghanns test release for * 1.4 # - Fixed a bug in one of the Florz test conditions trigged when null values were used. Reported by Paul Weterings. # # 1 May 2007 # - Corrected a number of typos's caused by interuppted editing session...paying clients have to come first. # # 11 May 2007 # - Changed the detection routine so that it is able to cope with multiple cards from different vendors. - - this will not be foolproof, especially if people try mixing 1, 2, 4 & 8 port cards (realy not recommended). # - In doing so found a bug in the coding (wrong case) of the card ID strings from detectVoiceHW (http://asterisk.dencro.net/TrixBox-Scripts/detectVoiceHW) that RoadKill generated. This was the source of the card ID's used in the detection section. # - Changed some test conditions so they are easier to read # - Having changed the detection routine to cope with multiple vendor single port cards... changed it again..... # Detection now runs from the ordered output from lspci, so cards are listed in the order lspci finds them, not by HFC chipset type. This makes detection quicker, and port finding should be easier - when looking at the physical cards. # - Further changed the detection routines to use bit values so that different card types (1,2,4,8 port) can be catered for in the same build. # - Added base values for duoBRI - this should make the additional subvendor id tests to differentiate the quad and duo card easier. # # 29 May 2007 # - Tweaked the card detection routine a bit more. # - Junghanns released bristuff-0.3.0-PRE-1y-f this is the first release to support * 1.2.18 # # 12 June 2007 # - Change the start-up order so that -V is not preceded by card detection. # - Junghanns released bristuff-0.3.0-PRE-1y-g # - Updated Trixbox function. This should allow the script to work better when re-run or a TB install is in an unstable state. # - Added some tests to the build phases of the script which will terminate the script on error. This will allow people to better debug the build problem and be less likely to be sidetracked by the subsequent problems they see. # # 14 June 2007 # - Following a couple of issues with the last few releases of BRIstuff not being able to download successfully from the mirror specified by Junghanns... # Add a new function to handle the download and patching. By default this will be the Digium site. # The new -M command line switch can be used to select another mirror. Currently there are only two mirror sites defined. # # 26 June 2007 # - BugFix: Re-ordered the start-up calls to their original positions after moving the comand line processing before card detection (-V issue above). # This left some parameters unset when some tests are run. # # 27 June 2007 # - Junghanns released bristuff-0.3.0-PRE-1y-h this is the first release to support * 1.2.19 # ##### shopt -s -o nounset # ------------------------------------------- # Static parameters # ------------------------------------------- declare -rx ASTERISK_DIRECTORY=/etc/asterisk declare -x BUILD=1 declare -x CONFIGURE=1 declare -x COUNTRY_CODE=za # COUNTRY_CODE is used for loadzone and defaultzone in /etc/zaptel only if /etc/zaptel does not already exist. You can change this to one of the valid Asterisk Country Codes. declare -rx CURRENT_DIRECTORY=`pwd` declare -x FLORZ_PATCH="" declare -x FLORZ_TESTED=1 declare -x MIRROR=1 # Asterisk sources mirror. 0=Jungahnns(specified) 1=Digium(default) declare -x MODES=0 declare -rx PROGRAM=${0##*/} declare -rx SERVER=${HOSTNAME%%\.*} declare -x SLAVES=0 declare -rx SLEEP_TIME=5 declare -rx SOURCE_DIRECTORY=/usr/src declare -rx SYSCONFIG=/etc/sysconfig/zaptel declare -x TIMER_CARD=0 declare -x TRIXBOX='' declare -rx UDEV_RULES=/etc/udev/rules.d/zaptel.rules #----------------------------------- # Functions #----------------------------------- # # Build_Asterisk function Build_Asterisk { ## Asterisk BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/asterisk-$ASTERISK_VERSION" cd $BUILD_DIR || Build_Error_CD Status "Building Asterisk in: `pwd`" make clean make make install if [ -f asterisk ] then Write_Log "Asterisk build:\t\t`ls -l asterisk`" else Write_Log "Asterisk build:\t\tFAILED: ***** No asterisk file found after build." Say "Asterisk build ***** FAILED: ***** No asterisk file found after build. Termintating script." Exit_Script fi } # # Build_Error_CD function Build_Error_CD { Write_Log "FATAL ERROR:\tUnable to move into directory $BUILD_DIR" Status "FATAL Error: Exiting script." Exit_Script } # # Build_Libpri function Build_Libpri { BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/libpri-$LIBPRI_VERSION" cd $BUILD_DIR || Build_Error_CD Status "Building libpri in: `pwd`" make clean make make install if [ -f libpri.so ] then Write_Log "Libpri build:\t\t`ls -l libpri.so`" else Write_Log "Libpri build:\t\tFAILED: ***** No libpri.so file found after build." Say "Libpri build ***** FAILED: ***** No libpri.so file found after build. Termintating script." Exit_Script fi } # changes by www.jumpingbean.co.za function Build_Spandsp { BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/spandsp-$SPANDSP_DIR" cd $BUILD_DIR || Build_Error_CD Status "Building spandsp in: `pwd`" ./configure make make install if [ -f /usr/local/lib/libspandsp.so ] then Write_Log "spandsp build:\t\t`ls -l libpri.so`" else Write_Log "Spandsp build:\t\tFAILED: ***** No libspandsp.so file found after build." Say "Spandsp build ***** FAILED: ***** No libspandsp.so file found after build. Termintating script." Exit_Script fi } # # Build_Qozap function Build_Qozap { BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/qozap" cd $BUILD_DIR || Build_Error_CD Status "Building qozap in: `pwd`" make clean make if [ -f qozap.ko ] then Write_Log "QoZap build:\t\t`ls -l qozap.ko`" else Write_Log "QoZap build:\t\tFAILED: ***** No qozap.ko file found after build." Say "QoZap build ***** FAILED: ***** No qozap.ko fie found after build. Termintating script." Exit_Script fi ### Check if module already exists, if so rename, then copy new module to libs/extra directory if [ -f $MODULES_DIRECTORY/qozap.ko ] then Rename_File $MODULES_DIRECTORY/qozap.ko fi cp $SOURCE_DIRECTORY/$BRISTUFF_VERSION/qozap/qozap.ko $MODULES_DIRECTORY/ } # # Build_Zaphfc function Build_Zaphfc { BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/zaphfc" cd $BUILD_DIR || Build_Error_CD Status "Building zaphfc in: `pwd`" # ------------------------------------------- # Florz Patch - patch if required # ------------------------------------------- if [ $FLORZ_PATCH ] then Status "Applying Florz's patch." Write_Log "\nFlorz Patch:\t\tPatching" zcat $FLORZ_VERSION | patch -p1 Say "Done\n" fi make clean make if [ -f zaphfc.ko ] then Write_Log "Zaphfc build:\t\t`ls -l zaphfc.ko`" else Write_Log "Zaphfc build:\t\tFAILED: ***** No zaphfc.ko file found after build." Say "Zaphfc build ***** FAILED: ***** No zaphfc.ko file found after build. Termintating script." Exit_Script fi ### Check if module already exists, if so rename, then copy new module to libs/extra directory if [ -f $MODULES_DIRECTORY/zaphfc.ko ] then Rename_File $MODULES_DIRECTORY/zaphfc.ko fi cp $SOURCE_DIRECTORY/$BRISTUFF_VERSION/zaphfc/zaphfc.ko $MODULES_DIRECTORY/ } # # Build_Zaptel function Build_Zaptel { BUILD_DIR="$SOURCE_DIRECTORY/$BRISTUFF_VERSION/zaptel-$ZAPTEL_VERSION" cd $BUILD_DIR || Build_Error_CD Status "Building zaptel in: `pwd`" make clean make make install if [ -f zaptel.ko ] then Write_Log "Zaptel build:\t\t`ls -l zaptel.ko`" else Write_Log "Zaptel build:\t\tFAILED: ***** No zaptel.ko file found after build." Say "Zaptel build ***** FAILED: ***** No zaptel.ko file found after build. Termintating script." Exit_Script fi } # # Check_For_Update function Check_For_Update { SCRIPT_SOURCE=$PROGRAM SCRIPT_LOCATION=`dirname $0` RELEASED=$SCRIPT_VERSION VERSION_FILE="$PROGRAM.released" BTL_SOURCE="http://brightheadtechnology.com/other/aah" Status "Checking for updates from $BTL_SOURCE" cd $SCRIPT_LOCATION if [ -f $VERSION_FILE ] ; then rm -f $VERSION_FILE; fi wget -c -N -q $BTL_SOURCE/$VERSION_FILE source $VERSION_FILE if [ $SCRIPT_VERSION != $RELEASED ] then Say "\n-----------------------------------------------------" Say "There is an update to this script available.\n" Say "Current version: $SCRIPT_VERSION" Say "Updated version: $RELEASED" Say "\nWould you like to download it now?" Say "-----------------------------------------------------" echo -e -n "Download? [y/N] :" read CONTINUE if [ "$CONTINUE" = "y" -o "$CONTINUE" = "Y" ] then Say "OK...." Rename_File $PROGRAM # go get the update wget -c -N -q $BTL_SOURCE/$PROGRAM if [ -f $PROGRAM.md5 ] ; then rm -f $PROGRAM.md5; fi # go get the md5 wget -c -N -q $BTL_SOURCE/$PROGRAM.md5 md5sum -c $PROGRAM.md5 > /dev/null 2>&1 \ && ( chmod 0777 $PROGRAM Say "Script updated........exiting. Please re-run with the new script." Write_Log "Script:\t\t\tScript updated to version $RELEASED." Exit_Script ) || ( Say "Update failed. Please retry or download manually from:" Say "$BTL_SOURCE/$PROGRAM" Write_Log "Script:\t\t\tScript update failed. exiting" # restore the original version of the script mv $PROGRAM.$COUNT $PROGRAM Exit_Script ) else Say "OK. Continuing build......." fi fi } # # Check_For_Trixbox function Check_For_Trixbox { if [ -f /usr/local/sbin/help-trixbox ] then Status "Found Trixbox installed." TRIXBOX=1 Write_Log "Trixbox:\t\tApplying changes to allow build on Trixbox" cd /etc/init.d/ # save /etc/init.d/zaptel (which will be deleted during rpm removal) if [ -f zaptel ]; then cp zaptel zaptel.saved; fi # find out which rpm's are installed # Quick Fudge on test as rpm now returns a differetn result i.e. not NULL. SPANDSP=`rpm -q spandsp`; if [ "${SPANDSP:0:7}" = "package" ];then SPANDSP="";fi ASTERISK=`rpm -q asterisk`; if [ "${ASTERISK:0:7}" = "package" ];then ASTERISK="";fi LIPBRI=`rpm -q libpri`; if [ "${LIBPRI:0:7}" = "package" ];then LIBPRI="";fi ZAPTEL=`rpm -q zaptel`; if [ "${ZAPTEL:0:7}" = "package" ];then ZAPTEL="";fi ZAPMOD=`rpm -q zaptel-modules`; if [ "${ZAPMOD:0:7}" = "package" ];then ZAPMOD="";fi # remove them for PACKAGE in $ASTERISK $LIBPRI $ZAPTEL $ZAPMOD $SPANDSP do rpm -e --nodeps $PACKAGE && \ Write_Log "Trixbox:\t\tRemoved rpm $PACKAGE" done if [ -f zaptel.saved ] then mv zaptel.saved zaptel # edit path to pre-TB value sed -i.bak s/'\/usr\/sbin\/ztcfg'/'\/sbin\/ztcfg'/ zaptel fi # check /var/run/asterisk exists, if not create if [ ! -d /var/run/asterisk ]; then mkdir /var/run/asterisk; fi # Change path to fxotune to match ztcfg path if [ `grep -c fxotune /etc/rc.local` -gt 0 ] then sed -i.bak s/'\/usr\/sbin\/fxotune'/'\/sbin\/fxotune'/ /etc/rc.local fi # Remove app_trunkisavail & app_speech_utils if [ -f /usr/lib/asterisk/modules/app_trunkisavail.so ]; then rm -f /usr/lib/asterisk/modules/app_trunkisavail.so; fi if [ -f /usr/lib/asterisk/modules/app_speech_utils.so ]; then rm -f /usr/lib/asterisk/modules/app_speech_utils.so; fi # disable TB yum repo if [ -f /etc/yum.repos.d/trixbox.repo ] then sed -i s/enabled=1/enabled=0/ /etc/yum.repos.d/trixbox.repo fi # disable update script to stop things getting messed up. if [ -f /usr/local/sbin/trixbox-update.sh ] then mv /usr/local/sbin/trixbox-update.sh /usr/local/sbin/trixbox-update.sh.org fi fi } # # Check_Modprobe_Qozap function Check_Modprobe_Qozap { ## check if qozap is already in /etc/modprobe.conf If so remove. if [ 0 -ne `fgrep -c qozap /etc/modprobe.conf` ] then Write_Log "modprobe.conf:\t\tRemoving old qozap entry" sed -i.bak /qozap/d /etc/modprobe.conf fi # Add new/updated entry to modprobe.conf Write_Log "modprobe.conf:\t\tAdding qozap entry" echo "install qozap /sbin/modprobe --ignore-install qozap ports=$MODES && /sbin/ztcfg" >> /etc/modprobe.conf Write_Log "modprobe.conf:\t\t`fgrep qozap /etc/modprobe.conf`" } # # Check_Modprobe_Zaphfc function Check_Modprobe_Zaphfc { ## check if zaphfc is already in /etc/modprobe.conf If so remove. if [ 0 -ne `fgrep -c zaphfc /etc/modprobe.conf` ] then Write_Log "modprobe.conf:\t\tRemoving old zaphfc entry" sed -i.bak /zaphfc/d /etc/modprobe.conf fi # Add new/updated entry to modprobe.conf Write_Log "modprobe.conf:\t\tAdding zaphfc entry" if [ $FLORZ_PATCH ] then echo "install zaphfc /sbin/modprobe --ignore-install zaphfc modes=$MODES sync_slave=$SLAVES timer_card=$TIMER_CARD && /sbin/ztcfg" >> /etc/modprobe.conf else echo "install zaphfc /sbin/modprobe --ignore-install zaphfc modes=$MODES && /sbin/ztcfg" >> /etc/modprobe.conf fi Write_Log "modprobe.conf:\t\t`fgrep zaphfc /etc/modprobe.conf`" } # # Check_Port_Modes function Check_Port_Modes { ## Check to see if we have ports set in TE and/or NT mode for ((COUNT=1 ; COUNT<=$NUMBER_HFC_PORTS ; COUNT++ )) do if [ "${PORT_NT_TE_MODE[$COUNT]}" = "TE" ]; then TE_MODE=1; fi if [ "${PORT_NT_TE_MODE[$COUNT]}" = "NT" ]; then NT_MODE=1; fi done } # # Check_Spinlock function Check_Spinlock { ## Check for the spinlock.h rw_lock_t typo. cd /usr/src/linux/include/linux/ if [ `grep -c rw_lock_t spinlock.h` -gt 0 ] then sed -i.bak s/rw_lock_t/rwlock_t/ spinlock.h && \ Write_Log "spinlock.h:\t\tFile edited." fi } # # Check_Sysconfig_Qozap function Check_Sysconfig_Qozap { ## check if qozap is already in /etc/sysconfig/zaptel if [ 0 -eq `fgrep -c qozap $SYSCONFIG` ] then echo " " >> $SYSCONFIG echo 'MODULES="$MODULES qozap" # HFC 4S/8S ISDN module' >> $SYSCONFIG Write_Log "sysconfig/zaptel:\tAdding qozap entry" fi Write_Log "sysconfig/zaptel:\t`fgrep qozap $SYSCONFIG`" } # # Check_Sysconfig_Zaphfc function Check_Sysconfig_Zaphfc { ## check if zaphfc is already in /etc/sysconfig/zaptel if [ 0 -eq `fgrep -c zaphfc $SYSCONFIG` ] then echo " " >> $SYSCONFIG echo 'MODULES="$MODULES zaphfc" # HFC ISDN module' >> $SYSCONFIG Write_Log "sysconfig/zaptel:\tAdding zaphfc entry" fi Write_Log "sysconfig/zaptel:\t`fgrep zaphfc $SYSCONFIG`" } # # Check_Sysconfig_Ztdummy function Check_Sysconfig_Ztdummy { ## Make sure ztdummy is commented out in /etc/sysconfig/zaptel if [ 0 -ne `fgrep -c ztdummy $SYSCONFIG` ] then sed -i.bak -e '/ztdummy/s/^MODULES/#MODULES/g' $SYSCONFIG fi Write_Log "sysconfig/zaptel:\t`fgrep ztdummy $SYSCONFIG`\n" } # # Choose_Version function Choose_Version { Say "\n" if [ "$ARG_a" != "select" ]; then Say "Unable to find a version of BRIstuff to match $VERSION_FROM version of Asterisk"; fi Say "Choose the version of Asterisk you want to patch with BRIstuff" Say "Going back a version or two appears to be OK." Say "It is not recommended to go forward to a version above what you have installed.\n" PS3="Option number: " select VERSION in 1.0.9 1.0.10 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.2.10 1.2.12 1.2.13 1.2.14 1.2.17 1.2.18 1.2.19 1.4.2 QUIT do Set_Version $VERSION break done } # # Configure_Service_Start function Configure_Service_Start { # The isdn module seems to able to load without causing problems when 1 HFC card is present. # However it seems to stop a second card from working. So turn it off to be safe. /sbin/chkconfig isdn off /sbin/service isdn stop # Make sure zaptel service starts at boot time. /sbin/chkconfig zaptel on /sbin/service zaptel start /bin/sleep $SLEEP_TIME } # # Can be called to debug a line/function function Debug { shopt -s -o xtrace "$@" shopt -u -o xtrace } # # Detect_HFC_Cards function Detect_HFC_Cards { # Check lspci and see if there is one or more HFC cards listed... This may not be foolproof. # For a first release of multi-card types, it will only configure homogeneous cards. Status "Searching for HFC Chipset based cards." NUMBER_HFC_CARDS=0 NUMBER_HFC_PORTS=0 DEVICE_TYPE_FOUND=0 DEVICE_TYPE_ZAP=$((2#0001)) DEVICE_TYPE_DUO=$((2#0010)) DEVICE_TYPE_QUA=$((2#0100)) DEVICE_TYPE_OCT=$((2#1000)) DEVICE_TYPE_QOZ=$((2#1110)) DEVICE_PROC_ID[$DEVICE_TYPE_ZAP]="HFC-S" DEVICE_PROC_ID[$DEVICE_TYPE_DUO]="duoBRI" DEVICE_PROC_ID[$DEVICE_TYPE_QUA]="quadBRI" DEVICE_PROC_ID[$DEVICE_TYPE_OCT]="octoBRI" lspci -n | cut -d' ' -f4 >lspci.card.list exec 3< lspci.card.list COUNT=0 while read PCI_CARD_ID <&3 do case $PCI_CARD_ID in "1397:2bd0" | "1397:b000" | "1397:b006" | "1397:b007" | "1397:b008" | "1397:b009" | "1397:b00a" | "1397:b00c" | "1397:b100" |\ "13d1:2bd1" |\ "1043:0675" |\ "0871:ffa1" | "0871:ffa2" |\ "1051:0100" |\ "15b0:2bd0" |\ "114f:0070" | "114f:0071" | "114f:0072" | "114f:0073" |\ "182d:3069" ) PORTS=1 CHIPSET="HFC-PCI" Log_Found_Card $DEVICE_TYPE_ZAP ;; "1397:08b4" ) PORTS=4 CHIPSET="HFC-4S" ## ## Need to add a sub-vendor check here to differentiate between 2 & 4 port cards. ## Log_Found_Card $DEVICE_TYPE_QUA ;; "1397:16b8" ) PORTS=8 CHIPSET="HFC-8S" Log_Found_Card $DEVICE_TYPE_OCT ;; * ) ;; esac done rm -f lspci.card.list NUMBER_HFC_CARDS=$COUNT let "CARD_TEST_QOZ=DEVICE_TYPE_FOUND&DEVICE_TYPE_QOZ" let "CARD_TEST_ZAP=DEVICE_TYPE_FOUND&DEVICE_TYPE_ZAP" # Set the default mode for each port to TE & Master. for ((COUNT=1 ; COUNT<=$NUMBER_HFC_PORTS ; COUNT++ )) do PORT_NT_TE_MODE[$COUNT]="TE" PORT_SL_MA_MODE[$COUNT]="Master" done ## Set the max bitmap value for the number of ports detected. BITMAP_MAX_VALUE=$((2**NUMBER_HFC_PORTS-1)) } # # Display_Confirmation function Display_Confirmation { # ------------------------------------------- # Display and confirm what we are about to build # ------------------------------------------- Status "Display and confirm build." Say "About to build with the following parameters:\n" Say "Asterisk:\t$ASTERISK_VERSION" Say "Zaptel:\t\t$ZAPTEL_VERSION" Say "Libpri:\t\t$LIBPRI_VERSION" Say "BRIsttuff:\t$BRISTUFF_VERSION" Say "Cards Found:\t$NUMBER_HFC_CARDS" if [ $FLORZ_PATCH ] then Say "Florz:\t\t$FLORZ_VERSION" Say "Timer Card:\t$((TIMER_CARD+1))" COUNT=1 for (( CARD=1 ; CARD<=$NUMBER_HFC_CARDS; CARD++ )) do for (( PORT=1 ; PORT<=${CARD_FOUND_PORTS[$CARD]} ; PORT++ )) do Say "Card$CARD Port$PORT:\t${PORT_NT_TE_MODE[$COUNT]} ${PORT_SL_MA_MODE[$COUNT]} mode" ((COUNT++)) done done else COUNT=1 for (( CARD=1 ; CARD<=$NUMBER_HFC_CARDS; CARD++ )) do for (( PORT=1 ; PORT<=${CARD_FOUND_PORTS[$CARD]} ; PORT++ )) do Say "Card$CARD Port$PORT:\t${PORT_NT_TE_MODE[$COUNT]} mode" ((COUNT++)) done done fi Say "Kernel:\t\t$KERNEL_VERSION" if [ ! -f $MODULES_DIRECTORY/zaphfc.ko ]; then Say "\t\tThis looks like the first BRIstuff build for this version of the kernel."; fi if [ $REWRITE_ZAPBRI ]; then Say "Config:\t\t$ZAPBRI will be re-written."; fi if [ "$VERSION_COMMENT" ]; then Say "\n*** $VERSION_COMMENT ***"; fi if [ ! -f $ASTERISK_DIRECTORY/$ZAPBRI ]; then Display_New_Config_Info; fi if [ ! $BUILD ]; then Say "\nRunning script to CONFIGURE only."; fi if [ ! $CONFIGURE ]; then Say "\nRunning script to BUILD only."; fi if [ "$CARD_TEST_ZAP" -gt 0 -a "$CARD_TEST_QOZ" -gt 0 ]; then Say "\n\n***** Both Single and Multi port cards found. Results will be unpredictable. *****\n"; fi Say "\nIf this is not the configuration you require try \"$PROGRAM -h\" for a list of options." Say "\nAre you sure you wish to continue this build?" Say "-----------------------------------------------------" echo -e -n "Continue? [y/N] :" read CONTINUE if [ "$CONTINUE" = "y" -o "$CONTINUE" = "Y" ] then Say "OK...." else Exit_Script 0 fi } # # Display_New_Config_Info function Display_New_Config_Info { Say "\n**************************************************************" Say "* *" Say "* As of version 1.0.4 install-ZAPHFC will automatically *" Say "* create a zapata config for your HFC card(s). *" Say "* *" Say "* It puts this config into /etc/asterisk/zapata-BRI-HFC.conf *" Say "* *" Say "* It also adds an include for this file into zapata.conf *" Say "* *" Say "* Please move your existing zapata HFC config statements *" Say "* into zapata-BRI-HFC.conf *" Say "* *" Say "* zapata-BRI-HFC.conf will not be over-written unless you *" Say "* specify the -R command line option. The old version will *" Say "* be re-named. *" Say "* *" Say "**************************************************************\n" } # # Display_No_HFC_Card_Warning function Display_No_HFC_Card_Warning { # ------------------------------------------- # If no HFC chipset card found, check user really wants to run this... # ------------------------------------------- Say "\n-----------------------------------------------------" Write_Log "lspci:\t\t\tDoes NOT show an entry for an HFC device" Say "No HFC based device was found when your system was tested.\n" Say "If you have an HFC card installed please post details to the help forum at http://www.trixbox.org/modules/newbb/ or http://sourceforge.net/forum/forum.php?forum_id=420324\n" Say "Please include the following details:" Say "- the output from an lspci" Say "- the make and model of your card\n" Say "Otherwise, are you sure you wish to continue this build?" Say "-----------------------------------------------------" echo -e -n "Continue? [y/N] :" read CONTINUE if [ "$CONTINUE" = "y" -o "$CONTINUE" = "Y" ] then Say "OK...." else Exit_Script 0 fi } # # Display_Signoff_Info function Display_Signoff_Info { Say "\n************************************************************" Say "* You should now check: *" Say "* *" Say "* /etc/zaptel.conf & /etc/asterisk/zapata-BRI-HFC.conf *" Say "* *" Say "* if you also have any of the following cards: *" Say "* *" Say "* T400P Quad Span T1 Card *" Say "* E400P Quad Span E1 Card *" Say "* TE405P Quad Span T1/E1 Card (5v version) *" Say "* TE410P Quad Span T1/E1 Card (3.3v version) *" Say "* T100P Single Span T1 Card *" Say "* E100P Single Span E1 Card *" Say "* TE110P Single Span T1/E1 Card *" Say "* X100P Single port FXO interface *" Say "* X101P Single port FXO interface *" Say "* TDM400P Modular FXS/FXO interface (1-4 ports) *" Say "* S100U Single port FXS USB Interface *" Say "* Old Tormenta1 ISA Card *" Say "* *" Say "* .... then check $SYSCONFIG *" Say "* *" Say "************************************************************\n" } # # Display_Usage function Display_Usage { cat < |-l ] [-B |-C ] [-R ] [-m 1|0[1|0[1|0[1|0]]] ] [-f t|u [-t 1|2|3|4] [-s 1|0[1|0[1|0[1|0]]]] ] $PROGRAM -h $PROGRAM -V Options: -a : The version of Asterisk you want to patch with BRIstuff (e.g. 1.2.1) The default is to use the version number from the currently installed Asterisk. -B Build only. Will disable the configuration module*. -C Configure only. Will disable the build module*. * if you specify both B & C options the last occurrence on the command line takes presidence -f Apply Florz's patch (http://zaphfc.florz.dyndns.org/). (Default no) t (tested) the last tested patch will be applied (this may use an earlier * to do so). u (un-tested) patch the latest version of BRIstuff (CAUTION). -h This help screen -l List the versions of Asterisk that you can build BRIstuff for. -M set the mirror to use for downloading the Asterisk sources from. -M 0 Use the mirror specified by Junghanns -M 1 Use the Digium mirror (default) -m Set the NT/TE mode for each card. Use 1 for NT mode and 0 for TE mode. Specify one or more cards with card 1 as the rightmost digit. Examples: -m 1 Card 1 in NT mode. -m 10 Card 2 NT mode card 1 TE mode. -m 11 Cards 2 & 1 in NT mode. -m 1100 Cards 4 & 3 in NT mode cards 2 & 1 in TE mode. -R Re-write $ZAPBRI. -s Set the Slave/Master mode for each card. Use 1 for Slave mode and 0 for Master mode. Only when built with Florz's patch. Specify one or more cards with card 1 as the rightmost digit. Examples: -s 1 Card 1 in Slave mode. (Assumes you have more than one card). -s 10 Card 2 in Slave mode card 1 in Master mode. -s 110 Cards 3 & 2 in Slave mode card 1 in Master mode. -s 1110 Cards 4, 3 & 2 in Slave mode card 1 in Master mode. -t Specify which card will be the timer_card. (Default 1). Only when built with Florz's patch. -V Print script version number and exit. EOF-HELP Exit_Script 0 } # # Download_And_Patch function Download_And_Patch { Status "Downloading and patching Asterisk applications." # Junghanns SRCURL[0]="http://www.asterisk-support.de/mirror" SUBDIR[0]="" # Digium SRCURL[1]="ftp://ftp.digium.com/pub" SUBDIR[1]="releases/" for APPLICATION in asterisk-$ASTERISK_VERSION zaptel-$ZAPTEL_VERSION libpri-$LIBPRI_VERSION do APPBASE=${APPLICATION%%\-*} #======== Jumping Bean Changes ===============# if [ ! -e $SOURCE_DIRECTORY/$APPLICATION.tar.gz ] then wget "${SRCURL[$MIRROR]}/$APPBASE/${SUBDIR[$MIRROR]}$APPLICATION.tar.gz" cp $APPLICATION.tar.gz $SOURCE_DIRECTORY/ else cp $SOURCE_DIRECTORY/$APPLICATION.tar.gz ./ fi tar -zxf $APPLICATION.tar.gz &&\ if [ -h $APPLICATION ]; then rm -f $APPLICATION; fi &&\ ln -s $APPLICATION $APPBASE ||\ { Write_Log "Download:\t\tFailed to sucessfully download $APPLICATION" Say "Failed to sucessfully download $APPLICATION. Exiting script." Say "Try re-running and using a different mirror (-M command line option)." Exit_Script } Write_Log "Download:\t\t$APPLICATION downloaded." pushd $APPLICATION >/dev/null &&\ patch -p1 < ../patches/$APPBASE.patch &&\ popd >/dev/null ||\ { Write_Log "Patch:\t\t\tFailed to sucessfully patch $APPLICATION" Say "Failed to sucessfully patch $APPLICATION. Exiting script." Exit_Script } Write_Log "Patch:\t\t\t$APPLICATION patched." done #=======================Jumping Bean changes ========================# echo "====================Getting files for rxfax ====================" TRIXBOX_EXTRA=/var/trixbox_load/extra_apps cp $TRIXBOX_EXTRA/app_rxfax.c asterisk/apps/ cp $TRIXBOX_EXTRA/app_txfax.c asterisk/apps/ wget "http://www.jumpingbean.co.za/files/apps_Makefile.patch" mv apps_Makefile.patch asterisk/apps/ currDir=`pwd` cd asterisk/apps/ echo "=================Patching Asterisk for rxfax ======================" patch 0 ; COUNT-- )) do if [ -f "$1.$COUNT" ]; then mv $1.$COUNT $1.$((COUNT+1)); fi done mv $1 $1.1 } # # Say VERBOSE=1 function Say { if [ $VERBOSE ]; then echo -e "$@" >&2; fi } # # Search_For_ZAP_Processes function Search_For_ZAP_Processes { CARD_PROCID=$1 # keep old variable name for the moment. Status "Checking contents of /proc/zaptel for $CARD_PROCID" PROCESS_FOUND="" PORT_NUMBER=0 for FILE in /proc/zaptel/* do if [ `grep -c "$CARD_PROCID" $FILE` -gt 0 ] then CARD_PROCFILE[$PORT_NUMBER]=$FILE ((PORT_NUMBER++)) PROCESS_FOUND=1 fi done if [ $PROCESS_FOUND ] then Write_Etc_Zaptel Write_Check_Zapata Write_Asterisk_Zapbri else Say "A process for $CARD_PROCID was not found in /proc/zaptel/ directory" Say '\nTry rebooting, then run "cat /proc/zaptel/*" from a console prompt' Write_Log "proc:\t\t\t$CARD_PROCID not found in /proc/zaptel/\n" Status " This builds logfile is in $LOGFILE" Exit_Script fi } # # Set_Asterisk_Version function Set_Asterisk_Version { # ------------------------------------------- # Set the version of Aterisk to patch/build # ------------------------------------------- Status "Determining which version of asterisk to build." if [ $ARG_a ] then VERSION=$ARG_a VERSION_FROM="the version quoted on the command line ($ARG_a)" Write_Log "Asterisk:\t\tCommand line - $VERSION" else # Get the version info from the system. VERSION_STR=`/usr/sbin/asterisk -V` STR_START=`expr index "$VERSION_STR" ' [1-9]*\.[0-9]*\.[0-9]*'` STR_END=`expr match "$VERSION_STR" 'Asterisk [1-9]*\.[0-9]*\.[0-9]*'` LENGTH=$((STR_END - STR_START)) VERSION=${VERSION_STR:$STR_START:$LENGTH} if [ "$VERSION" = "" ]; then VERSION="that asterisk was not"; fi Write_Log "Asterisk:\t\tFound $VERSION installed." VERSION_FROM="your currently installed" fi Set_Version $VERSION Write_Log "Asterisk:\t\tBuilding Asterisk $ASTERISK_VERSION" Write_Log "BRIstuff:\t\tPatching with $BRISTUFF_VERSION" } # # Set_Program_Options function Set_Program_Options { ARG_a="" while getopts '?a:BCf:hlM:m:Rs:t:V' ARGUMENTS do case "$ARGUMENTS" in a ) ARG_a=$OPTARG ;; B ) BUILD=1 CONFIGURE="" ;; C ) BUILD="" CONFIGURE=1 if [ ! -f $ZAPTEL_ETC ] then Say "Unable to use the -C option when no $ZAPTEL_ETC exists. Exiting." Exit_Script fi ;; f ) FLORZ_PATCH=1 case "$OPTARG" in t ) FLORZ_TESTED=1 ;; u ) FLORZ_TESTED="" ;; * ) Display_Usage ;; esac ;; h|\? ) Display_Usage ;; l ) ARG_a="select" ;; M ) case "$OPTARG" in 0 ) MIRROR=0 ;; 1 ) MIRROR=1 ;; * ) Display_Usage ;; esac ;; m ) BITMAP=$((2#$OPTARG)) if [ $BITMAP -gt $BITMAP_MAX_VALUE ] then Say "\n***** You only have $NUMBER_HFC_PORTS port(s) detected.*****\n" Display_Usage fi MODES=$BITMAP PORT=1 for ((COUNT=1 ; COUNT<=$NUMBER_HFC_PORTS ; COUNT++ )) do let "RESULT=PORT & BITMAP" if [ $RESULT -gt 0 ] then PORT_NT_TE_MODE[$COUNT]="NT" fi let "PORT=PORT << 1" done ;; R ) REWRITE_ZAPBRI=1 ;; s ) BITMAP=$((2#$OPTARG)) if [ $BITMAP -gt $BITMAP_MAX_VALUE ] then Say "\n***** You only have $NUMBER_HFC_PORTS port(s) detected.*****\n" Display_Usage fi SLAVES=$BITMAP PORT=1 for ((COUNT=1 ; COUNT<=$NUMBER_HFC_PORTS ; COUNT++ )) do let "RESULT=PORT & BITMAP" if [ $RESULT -gt 0 ] then PORT_SL_MA_MODE[$COUNT]="Slave" fi let "PORT=PORT << 1" done ;; t ) TIMER_CARD=$OPTARG if [ $TIMER_CARD -gt $NUMBER_HFC_CARDS ] then Say "\n***** You only have $NUMBER_HFC_CARDS card(s) detected.*****\n" Display_Usage fi # Cards are counted from 0 so correct... ((TIMER_CARD--)) ;; V ) Status "Version: $PROGRAM $SCRIPT_VERSION ($SCRIPT_DATE)" Exit_Script ;; * ) Display_Usage ;; esac done shift $(( $OPTIND-1 )) if [ $# != 0 ] then Say "\n******************************************************************************" Say "$PROGRAM: Unexpected parameters on command line ($@)" Say "******************************************************************************" Display_Usage fi } # # Set_Version function Set_Version { # # These are the versions of Asterisk that I know there are BRIstuff patches for. # If you want this list extended, then please mail me the details. # declare -a BUILD_FIELDS BUILD_FIELDS=("ASTERISK_VERSION" "ZAPTEL_VERSION" "LIBPRI_VERSION" "BRISTUFF_VERSION" "FLORZ_VERSION" "VERSION_COMMENT") NUM_BUILD_FIELDS=${#BUILD_FIELDS[*]} declare -a BUILD_VERSION # Asterisk v 1.0.x BUILD_VERSION[5109]="1.0.9"~"1.0.9"~"1.0.9"~"bristuff-0.2.0-RC8o"~"zaphfc_0.2.0-RC8o_florz-9.diff.gz"~"" BUILD_VERSION[109]="1.0.9"~"1.0.9"~"1.0.9"~"bristuff-0.2.0-RC8p"~"zaphfc_0.2.0-RC8o_florz-9.diff.gz"~"" BUILD_VERSION[1010]="1.0.10"~"1.0.10"~"1.0.10"~"bristuff-0.2.0-RC8q"~"zaphfc_0.2.0-RC8q_florz-9.1.diff.gz"~"" # Asterisk v 1.2.x BUILD_VERSION[120]="1.2.0"~"1.2.0"~"1.2.0"~"bristuff-0.3.0-PRE-1c"~"zaphfc_0.3.0-PRE-1_florz-10.diff.gz"~"" BUILD_VERSION[121]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1g"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[5121]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[122]="1.2.2"~"1.2.2"~"1.2.2"~"bristuff-0.3.0-PRE-1i"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"THIS VERSION OF ASTERISK HAS KNOWN SERIOUS PROBLEMS." BUILD_VERSION[5122]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[123]="1.2.3"~"1.2.2"~"1.2.2"~"bristuff-0.3.0-PRE-1i"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"Junghanns has yet to release a version of BRIstuff for this version of Asterisk" BUILD_VERSION[5123]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[124]="1.2.4"~"1.2.3"~"1.2.2"~"bristuff-0.3.0-PRE-1l"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"" BUILD_VERSION[5124]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[125]="1.2.5"~"1.2.4"~"1.2.2"~"bristuff-0.3.0-PRE-1l"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"Junghanns has yet to release a version of BRIstuff for this version of Asterisk" BUILD_VERSION[5125]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[126]="1.2.6"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1n"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"It is an assumption that Junghanns has released this version for 1.2.6" BUILD_VERSION[5126]="1.2.1"~"1.2.1"~"1.2.1"~"bristuff-0.3.0-PRE-1f"~"zaphfc_0.3.0-PRE-1f_florz-11.diff.gz"~"To avoid the long post dial delay issue see: https://sourceforge.net/forum/message.php?msg_id=3535215" BUILD_VERSION[127]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1p"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[5127]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[128]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1p"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"Please note a security update to Asterisk (1.2.9.1) has already been released.\nJunghanns has yet to release a version of BRIstuff for this version of Asterisk." BUILD_VERSION[5128]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[129]="1.2.9.1"~"1.2.6"~"1.2.3"~"bristuff-0.3.0-PRE-1r"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[5129]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1210]="1.2.10"~"1.2.6"~"1.2.3"~"bristuff-0.3.0-PRE-1s"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6210]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1212]="1.2.12.1"~"1.2.9.1"~"1.2.4"~"bristuff-0.3.0-PRE-1t"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6212]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[1213]="1.2.13"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1v"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1213]="1.2.13"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1w"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6213]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[1214]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1x"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[1214]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1214]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y-b"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[6214]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6214]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y-b"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[1217]="1.2.17"~"1.2.16"~"1.2.4"~"bristuff-0.3.0-PRE-1y-d"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1217]="1.2.17"~"1.2.16"~"1.2.4"~"bristuff-0.3.0-PRE-1y-e"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6217]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y-b"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[1218]="1.2.18"~"1.2.17"~"1.2.4"~"bristuff-0.3.0-PRE-1y-f"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" #BUILD_VERSION[6218]="1.2.7.1"~"1.2.5"~"1.2.2"~"bristuff-0.3.0-PRE-1o"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1218]="1.2.18"~"1.2.17.1"~"1.2.4"~"bristuff-0.3.0-PRE-1y-g"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6218]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y-b"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[1219]="1.2.19"~"1.2.18"~"1.2.4"~"bristuff-0.3.0-PRE-1y-h"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" BUILD_VERSION[6219]="1.2.14"~"1.2.10"~"1.2.4"~"bristuff-0.3.0-PRE-1y-b"~"zaphfc_0.3.0-PRE-1o_florz-12.diff.gz"~"" # Asterisk v 1.4.x BUILD_VERSION[142]="1.4.2"~"1.4.1"~"1.4.0"~"bristuff-0.4.0-test1"~"zaphfc_0.4.0-test1_florz-13.diff.gz"~"This is a first test release. Consider it alpha release." BUILD_VERSION[5142]="1.4.2"~"1.4.1"~"1.4.0"~"bristuff-0.4.0-test1"~"zaphfc_0.4.0-test1_florz-13.diff.gz"~"This is a first test release. Consider it alpha release." # ASTERISK ZAPTEL LIBPRI BRISTUFF_VERSION FLORZ_VERSION VERSION_COMMENT case $VERSION in 1.0.9 | 1.0.10 | \ 1.2.0 | 1.2.1 | \ 1.2.2 | 1.2.3 | \ 1.2.4 | 1.2.5 | \ 1.2.6 | 1.2.7 | \ 1.2.8 | 1.2.9 | \ 1.2.10 | 1.2.12 | \ 1.2.13 | 1.2.14 | \ 1.2.17 | 1.2.18 | \ 1.2.19 | \ 1.4.2 ) BUILD_NUMBER=${VERSION//./""} if [ "$FLORZ_PATCH" -a "$FLORZ_TESTED" ];then ((BUILD_NUMBER+=5000)); fi RECORD=${BUILD_VERSION[$BUILD_NUMBER]} for (( COUNT=0; COUNT<$NUM_BUILD_FIELDS; COUNT++ )) # extract the fields do BUILD_DATA[$COUNT]=${RECORD%%~*} RECORD="${RECORD#*~}" done ## map back to the original parameter names to make the code more readable. ASTERISK_VERSION=${BUILD_DATA[0]} ZAPTEL_VERSION=${BUILD_DATA[1]} LIBPRI_VERSION=${BUILD_DATA[2]} BRISTUFF_VERSION=${BUILD_DATA[3]} FLORZ_VERSION=${BUILD_DATA[4]} VERSION_COMMENT=${BUILD_DATA[5]} ;; QUIT ) Say Exiting script Exit_Script 0 ;; *) Choose_Version ;; esac } # # Shutdown_Asterisk function Shutdown_Asterisk { Status "Checking Asterisk and shutting down." if [ -f /var/run/asterisk/asterisk.pid ] then PID=`cat /var/run/asterisk/asterisk.pid` if [ -d /proc/$PID ] then /usr/sbin/amportal stop /bin/sleep $SLEEP_TIME if [ -f /var/run/asterisk/asterisk.pid ] then killall -9 safe_asterisk /bin/sleep $SLEEP_TIME /usr/sbin/amportal stop /bin/sleep $SLEEP_TIME fi else Write_Log "Shutdown:\t\tPID but no PROC. PID file deleted. Continuing build." Say "A PID file exists, but the process is not running." Say "\nDeleting PID file and continuing....\n" rm -f /var/run/asterisk/asterisk.pid /bin/sleep $SLEEP_TIME fi else Say "Asterisk appears to already be stopped." fi if [ -f /var/run/asterisk/asterisk.pid ] then Write_Log "Shutdown:\t\tUnable to shutdown Asterisk ...exiting" Say "Unable to shutdown Asterisk at this time. Exiting." Exit_Script 0 else Write_Log "Shutdown:\t\tAsterisk shutdown." fi } # # Shutdown_Zap function Shutdown_Zap { Status "Checking Zaptel and unloading zaptel modules" # Read which modules are loaded from /etc/sysconfig/zaptel if [ -z "$MODULES" ] then source $SYSCONFIG MODULES="$MODULES zaptel" fi ZAP_ERROR=0 for MODULE in $MODULES do if [ `lsmod|grep -c "$MODULE"` -ne 0 ] then Write_Log "Shutdown:\t\tFound $MODULE ...Unloading" Say "Shutdown:\t\tFound $MODULE ...stopping" /sbin/rmmod $MODULE ZAP_ERROR=$? /bin/sleep $SLEEP_TIME fi done # # If zaptel fails to unload, it probably means there is other hardware installed. # Or (this is the first run and) no modules are defined in $SYSCONFIG so the default list of modules have been loaded. # Which are: ztdummy wctdm wcfxo wcte11xp wct1xxp wct4xxp tor2 # if [ $ZAP_ERROR -gt 0 ] then for MODULE in ztdummy wctdm wcfxo wcte11xp wct1xxp wct4xxp tor2 zttranscode zaptel do if [ `lsmod|grep -c "$MODULE"` -ne 0 ] then Write_Log "Shutdown:\t\tFound $MODULE ...Unloading" Say "Shutdown:\t\tFound $MODULE ...stopping" /sbin/rmmod $MODULE ZAP_ERROR=$? /bin/sleep $SLEEP_TIME fi done fi if [ $ZAP_ERROR -gt 0 ] then Say "\nUnable to shutdown zaptel." Say "***** If you have configured your system to load modules via another method please disable and then re-run this script.*****" Say "exiting....\n\n" Write_Log "Shutdown:\t\tUnable to shutdown zaptel...... exiting." Exit_Script fi } # # Start_Asterisk function Start_Asterisk { Status "Starting Asterisk" if [ $ZAPTEL_EDIT ] then /sbin/service zaptel stop /bin/sleep $SLEEP_TIME fi /sbin/service zaptel start /bin/sleep $SLEEP_TIME /usr/sbin/amportal start } # # Status function Status { Say "\n-----------------------------------------------------" Say "$1" Say "-----------------------------------------------------\n" } # # Write_Asterisk_Zapbri ZAPBRI=zapata-BRI-HFC.conf function Write_Asterisk_Zapbri { cd $ASTERISK_DIRECTORY if [ $REWRITE_ZAPBRI ]; then Rename_File $ZAPBRI; fi # # Need to write NT/TE modes.... # if [ ! -f $ZAPBRI ] then if [ $TE_MODE ] then cat >>$ZAPBRI <<-EOF_A ; Basic ISDN Card TE mode config resetinterval=never immediate=no switchtype=euroisdn signalling=bri_cpe_ptmp pridialplan=dynamic prilocaldialplan=local nationalprefix=0 internationalprefix=00 usecallingpres=yes echocancel=yes echocancelwhenbridged=yes echotraining=100 context=from-zaptel group=0 EOF_A COUNT=0 while [ $COUNT -lt $PORT_NUMBER ] do if [ `echo ${PROC_TITLE[$COUNT]}|grep -c '\[TE\]'` -gt 0 ] then echo "channel => ${CHAN_NUMBER[$COUNT]}-$((CHAN_NUMBER[$COUNT] + 1))" >>$ZAPBRI fi ((COUNT++)) done fi if [ $NT_MODE ] then cat >>$ZAPBRI <<-EOF_A ; Basic ISDN Card NT mode config immediate=no signalling=bri_net_ptmp context=from-internal group=1 EOF_A COUNT=0 while [ $COUNT -lt $PORT_NUMBER ] do if [ `echo ${PROC_TITLE[$COUNT]}|grep -c '\[NT\]'` -gt 0 ] then echo "channel => ${CHAN_NUMBER[$COUNT]}-$((CHAN_NUMBER[$COUNT] + 1))" >>$ZAPBRI fi ((COUNT++)) done fi Write_Log "zapata:\t\t\tWritten basic config to $ZAPBRI" fi } # # Write_Check_Zapata ZAPATA=$ASTERISK_DIRECTORY/zapata.conf function Write_Check_Zapata { # This should only be applicable to those not running AAH (I think) if [ ! -f $ZAPATA ] then cat >>$ZAPATA <<-EOF_A ; ; Zapata telephony interface ; ; Configuration file [trunkgroups] [channels] EOF_A Write_Log "zapata:\t\t\t$ZAPATA Did not exist. Header written." fi if [ `grep -c BRI-HFC $ZAPATA` -eq 0 ] then cat >>$ZAPATA <<-EOF_A ;Include BRI-HFC configs #include $ZAPBRI EOF_A Write_Log "zapata:\t\t\tAdded statement to include $ZAPBRI config in $ZAPATA" else Write_Log "zapata:\t\t\t$ZAPBRI include statement appears in $ZAPATA config." fi } # # Write_Etc_Zaptel ZAPTEL_ETC=/etc/zaptel.conf function Write_Etc_Zaptel { if [ ! -f $ZAPTEL_ETC ] then Write_Log "zaptel.conf:\t\t$ZAPTEL_ETC not found. Created." ZAPTEL_CONF=1 cat >>$ZAPTEL_ETC <<-EOF_A # Autogenerated by /usr/local/sbin/install-ZAPHFC # Zaptel Configuration File # # This file is parsed by the Zaptel Configurator, ztcfg # # ** You should ONLY see this header if you have NO other zaptel cards. ** # # If you do have other zaptel cards, run genzaptelconf, then re-run install-ZAPHFC # EOF_A fi if [ `grep -c "HFC CARD NOTE" $ZAPTEL_ETC` -eq 0 ] then cat >>$ZAPTEL_ETC <<-EOF_B # HFC CARD NOTE: # When run for the first time the card numbers start from 1 # When run subsequently the card numbers start from 0 # Go figure! EOF_B fi COUNT=0 while [ $COUNT -lt $PORT_NUMBER ] do SPAN_NUMBER[$COUNT]=999 # These are set to very high values by default so that CHAN_NUMBER[$COUNT]=997 # it is obvious if they are not set properly later. PROC_TITLE[$COUNT]=`head -n 1 ${CARD_PROCFILE[$COUNT]}` SPAN_NUMBER[$COUNT]=`sed -n -e 's/^Span //g' -e 's/:.*$//gp' ${CARD_PROCFILE[$COUNT]}` CHAN_NUMBER[$COUNT]=`sed -e 1,2d ${CARD_PROCFILE[$COUNT]} | awk '{print $1}'|head -n 1` Write_Log "proc:\t\t\tZTHFC found in ${CARD_PROCFILE[$COUNT]}" Write_Log "\t\t\t${PROC_TITLE[$COUNT]}" Say "\nZTHFC found in ${CARD_PROCFILE[$COUNT]}\n" Say "\t${PROC_TITLE[$COUNT]}" # Increment card count before writing as command line started from card 1 DISPLAYCOUNT=$((COUNT+1)) if [ `grep -c "Span ${SPAN_NUMBER[$COUNT]}" $ZAPTEL_ETC` -gt 0 -a `grep -c "span=${SPAN_NUMBER[$COUNT]}" $ZAPTEL_ETC` -gt 0 ] then Write_Log "zaptel.conf:\t\tCard $DISPLAYCOUNT appears to be in $ZAPTEL_ETC already." Say "\n\tCard $DISPLAYCOUNT appears to already be configured in $ZAPTEL_ETC" else ZAPTEL_EDIT=yes cat >>$ZAPTEL_ETC <<-EOF_C # ${PROC_TITLE[$COUNT]} span=${SPAN_NUMBER[$COUNT]},1,3,ccs,ami bchan=${CHAN_NUMBER[$COUNT]}-$((CHAN_NUMBER[$COUNT] + 1)) dchan=$((CHAN_NUMBER[$COUNT] + 2)) EOF_C Write_Log "zaptel.conf:\t\tAdded config for Card $DISPLAYCOUNT to $ZAPTEL_ETC" Say "\n\tAdded config for Card $DISPLAYCOUNT to $ZAPTEL_ETC" fi ((COUNT++)) done if [ $ZAPTEL_CONF ] then cat >>$ZAPTEL_ETC <<-EOF_D # Global data loadzone = $COUNTRY_CODE defaultzone = $COUNTRY_CODE EOF_D Write_Log "zaptel.conf:\t\tAdded loadzone/defautzone to $ZAPTEL_ETC" Say "\n\tAdded loadzone/defautzone to $ZAPTEL_ETC" Say "\t**** Check the country code is correct ****\n" fi } # # Write_Log LOGFILE=$ASTERISK_DIRECTORY/install-zaphfc.log WRITELOG=1 function Write_Log { if [ $WRITELOG ]; then echo -e "$@" >>$LOGFILE; fi } #--------------------------------------------------------------------------------------------------------- # Application - Start #--------------------------------------------------------------------------------------------------------- # Start a new log file if [ -f $LOGFILE ]; then Rename_File $LOGFILE; fi Write_Log "\nSTARTED: Running $0 version $SCRIPT_VERSION ($SCRIPT_DATE) from $CURRENT_DIRECTORY on `date`" Write_Log "\nCommand line:\t\t$*\n" # Are there any HFC cards installed? Detect_HFC_Cards Check_Port_Modes # Process command line - this needs to follow Detect_HFC_Cards as some command line tests need to know how many cards/ports are found. Set_Program_Options $@ # Is there a newer version of this script? Check_For_Update cd $SOURCE_DIRECTORY # If no HFC chipset card found, check user really wants to run this... if [ $NUMBER_HFC_CARDS -eq 0 ]; then Display_No_HFC_Card_Warning; fi # Set the version of Aterisk to patch/build Set_Asterisk_Version # Display build summary and get confirmation Display_Confirmation # System preparation Shutdown_Asterisk Shutdown_Zap # Check if running on Trixbox build Check_For_Trixbox if [ $BUILD ] then # Kernel setup Kernel_Setup # Download Sources & prepare Download_Bristuff #==================== added by jumping bean ====================# Download_Spandsp if [ $FLORZ_PATCH ]; then Download_Florz_Patch; fi # Build Build_Zaptel # If /etc/udev/rules.d/zaptel.rules not present run make install-udev if [ ! -f $UDEV_RULES ]; then make install-udev; Write_Log "UDEV Rules:\t\tzaptel.rules not found, installing."; fi # Copy fxotune to the same dir as ztcfg and zttool. If you call fxotune from rc.local then it will always be in the same place. cp fxotune /sbin/ Build_Libpri if [ "$CARD_TEST_QOZ" -gt 0 ]; then Build_Qozap; fi if [ "$CARD_TEST_ZAP" -gt 0 ]; then Build_Zaphfc; fi #=================== Added by Jumping Bean ======================# Build_Spandsp Build_Asterisk depmod -a fi if [ $CONFIGURE ] then # Re-configure for new ISDN card(s) Status "Setting up zaptel configuration" if [ $NUMBER_HFC_CARDS -ne 0 ] then if [ "$CARD_TEST_QOZ" -gt 0 ] then Check_Modprobe_Qozap Check_Sysconfig_Qozap fi if [ "$CARD_TEST_ZAP" -gt 0 ] then Check_Modprobe_Zaphfc Check_Sysconfig_Zaphfc fi Check_Sysconfig_Ztdummy Configure_Service_Start # For each of the card types we detected, seach for a running process CARD_TYPE=1 while [ $CARD_TYPE -le $DEVICE_TYPE_FOUND ] do let "RESULT=DEVICE_TYPE_FOUND & CARD_TYPE" if [ $RESULT -gt 0 ] then Search_For_ZAP_Processes ${DEVICE_PROC_ID[$RESULT]} fi let "CARD_TYPE=CARD_TYPE << 1" done fi fi Start_Asterisk if [ $CONFIGURE ]; then Display_Signoff_Info; fi cd $CURRENT_DIRECTORY Exit_Script 0