#!/bin/bash # svn_rpt_update # 20071102 0830 Steven Henke sphenke@xelatec.com # 20071219 2126 sph zaptel-base.c added # # $Date: 2008-05-24 21:52:10 -0400 (Sat, 24 May 2008) $ # $Revision: 524 $ # $Author: shenke $ # # Only compatible with EasyVoxBox 0.010 and 0.011 # # WARNING: Overwrites existing source files! # # SVNHOME=http://www.xelatec.com/svn/app_rpt SVNBASE=trunk SVNWORK=/usr/src/svnwork SVNUSER=aguest SVNREC=http://www.xelatec.com/asterisk/evb_stats.txt SVNPASSWD=riverside APPINSTALLED=/etc/EVB/app_rpt_installed LASTSVNPATHFILE=/etc/EVB/rpt_lastsvnpath EVBRPTLOG=/etc/EVB/EVBrptlog.txt ERPTBCONF=/etc/erptb/erptb.conf BUILDON=/etc/EVB/EVBrpt_build.txt verbose=0 testmode=0 # svnproject=asterisk lastsvnbase=trunk # yall=0 devel=0 testmode=0 evb1first=0 previnstall=0 wipeit=0 text="" usvnpath="" # # define functions # function reg_send { test=0 SUBMITSITE=http://www.xelatec.com/xmail/rpt_reg_01.php SUBMITDATA=\?Submit=Send RTYPE=update REMAIL=v1001@xelatec.com RNODE=$(grep '^\[[0-9]' /etc/asterisk/rpt.conf | head -n1 | cut -d [ -f 2- | cut -d ] -f 1) RINTERFACE=$(grep '^rxchannel' /etc/asterisk/rpt.conf | head -n1 | cut -d / -f 2- | cut -d \; -f 1 | sed -e 's/^[ \t]*//') RCALLSIGN=$(grep ^idrecording*\=\|i /etc/asterisk/rpt.conf | head -n1 | cut -d \| -f 2- | cut -d i -f 2- | cut -d \; -f 1 ) RVERSION=$(svn info /usr/src/svnwork/asterisk | grep ^Revision | cut -d \: -f 2- | sed -e 's/^[ \t]*//') RSOURCE=$(svn info /usr/src/svnwork/asterisk | grep ^URL | cut -d \: -f 2- | sed -e 's/^[ \t]*//') RDATE=$(date +%Y%m%d%k%M) XDATE=\&user_date\=$(date +%Y%m%d%k%M) RKERNEL=$(uname -rmi) XKERNEL=\&user_kernel\=$(uname -rmi | sed s/[\ \#\/]/\+/g) #XCPU=$(grep 'model name' /proc/cpuinfo | cut -d : -f 2- | sed -e 's/^[ \t]*//' | sed s/[\ \#\/]/\+/g) #XCPU=\&user_cpumodel\=$XCPU RMEM=$(grep 'MemTotal' /proc/meminfo | cut -d : -f 2- | sed 's/[ \t]*//') XMEM=$(grep 'MemTotal' /proc/meminfo | cut -d : -f 2- | sed 's/[ \t]*//' | sed s/\ /\+/g) XMEM=\&user_mem\=$XMEM RCPUSPEED=$(grep 'cpu MHz' /proc/cpuinfo | cut -d : -f 2- | sed -e 's/^[ \t*]//') XCPUSPEED=\&user_cpuspeed\=$(grep 'cpu MHz' /proc/cpuinfo | cut -d : -f 2- | sed -e 's/^[ \t*]//'| sed s/\ /\+/g) RCPUMODEL=$(grep 'model name' /proc/cpuinfo | cut -d : -f 2- | sed -e 's/^[ \t]*//') XCPUMODEL=\&user_cpumodel\=$(grep 'model name' /proc/cpuinfo | cut -d : -f 2- | sed -e 's/^[ \t]*//' | sed s/[\ \#\/]/\+/g) target=$ERPTBCONF if [ -d /etc/erptb ]; then if ! [ -e $target ]; then touch $target chown asterisk:asterisk $target else grep 'email\=' $target > /dev/null 2>&1 res=$? if [ $res = 1 ]; then REMAIL=$(grep 'email\=' $target | cut -d = -f 2- | sed -e 's/^[ \t]*//' | sed s/[\ \#\/]/\+/g) fi fi else mkdir /etc/erptb fi # sed -i -e'/^svn/d' $target echo "svn="$RSOURCE >> $target sed -i -e'/^version/d' $target echo "version="$RVERSION >> $target #if ![ $test > "1" ]; then #REMAIL=stevehenke@bellsouth\.net #RVERSION=01.01.01 #RCALLSIGN=KDKA #RSOURCE=trunk #RINTERFACE=usb #RNODE=1234 #RTYPE=NEW #fi XEMAIL=\&user_email_addr\=$REMAIL XVERSION=\&user_version\=$RVERSION XCALLSIGN=\&user_callsign\=$RCALLSIGN XSOURCE=\&user_source\=$RSOURCE XINTERFACE=\&user_interface\=$RINTERFACE XNODE=\&user_node\=$RNODE XTYPE=\&user_type\=$RTYPE if [ $verbose -gt 0 ]; then echo $XDATE echo $XVERSION echo $XCPUMODEL echo $XMEM echo $XKERNEL echo $XSOURCE echo $XINTERFACE echo $XNODE echo $XCALLSIGN echo $XEMAIL echo $XCPUSPEED fi echo "" echo "-Installation Summary-" echo "" echo " Date Installed = "$RDATE echo " Type = "$RTYPE echo "Version Installed = "$RVERSION echo " Source = "$RSOURCE echo " CPU = "$RCPUMODEL echo " CPU Speed = "$RCPUSPEED echo " Memory = "$RMEM echo " Radio Interface = "$RINTERFACE echo "Radio Node Number = "$RNODE echo " Radio Callsign = "$RCALLSIGN #echo " E-mail Address = "$REMAIL echo " Kernel = "$RKERNEL echo "" echo "May we send the Installation Summary to the project developers" echo "so that they can design new features and improvements that are" echo -n "compatible with your computer? (y/N):" read text # if [ .$text != ".N" ]; then # #if [ .$REMAIL = "." ]; then # echo -n "Please enter your e-mail address:" # read REMAIL # echo "email="$REMAIL >> /etc/EVB/evb.conf # XEMAIL=\&user_email_addr\=$REMAIL #fi # wget -O /etc/EVB/zxmewget.txt $SUBMITSITE$SUBMITDATA\ $XEMAIL$XDATE$XTYPE$XVERSION$XCPUMODEL$XCPUSPEED$XMEM$XKERNEL\ $XNODE$XCALLSIGN$XSOURCE$XINTERFACE > /dev/null 2>&1 fi echo "" # } # # remove file if not a link # function rmifnotlink { linkfile=$linkdir/$sourcefile echo "rmifnotlink for $linkfile" if [ -e $linkfile ]; then if ! [ -L $linkfile ]; then if [ $testmode = 1 ]; then echo "rmifnot would rm : $linkfile" else # echo "rm -fR $linkfile" rm -fR $linkfile fi else unlink $linkfile fi fi # if ! [ -L $linkfile ]; then echo "ln -s $targetdir/$sourcefile $linkfile" ln -s $targetdir/$sourcefile $linkfile fi } # # main process # echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "" echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "" echo "************************************************************************" echo "" echo "svn_rpt_update 0.22 - Asterisk w/app_rpt update script begins." echo "" # # get installed svn info # lastsvnurl=$(svn info /usr/src/svnwork/asterisk | grep ^URL | cut -d \: -f 2- | sed -e 's/^[ \t]*//') lastsvnvers=$(svn info /usr/src/svnwork/asterisk | grep ^Revision | cut -d \: -f 2- | sed -e 's/^[ \t]*//') lastsvnhome=$(echo $lastsvnurl | sed -e 's/\/asterisk\//\+/g' | cut -d \+ -f1 ) lastsvnbase=$(echo $lastsvnurl | sed -e 's/\/asterisk\//\+/g' | rev | cut -d \+ -f1 | rev ) # if [ $verbose -gt 0 ]; then echo $lastsvnurl echo $lastsvnvers echo $lastsvnhome echo $lastsvnbase fi # #target=$ERPTBCONF #if [ -e $target ]; then # lastsvnhome=$(grep ^usvnhome $target | head -n1 | cut -d \= -f 2 | sed -e 's/^[ \t]*//') # lastsvnbase=$(grep ^usvnbase $target | head -n1 | cut -d \= -f 2 | sed -e 's/^[ \t]*//') # verbose=$(grep ^verbose $target | head -n1 | cut -d \= -f 2 | sed -e 's/^[ \t]*//') #fi # if ! [ -e /etc/EVB/EVB1first ]; then evb1first=0 else grep "complete" /etc/EVB/EVB1first > /dev/null 2>&1 complete=$? if [ $complete = 0 ]; then evb1first=1 else evb1first=0 fi fi # if [ $evb1first = 0 ]; then echo "" echo "/etc/EVB/EVB1first missing or does not indicate complete." echo "Unable to continue." exit 0 fi # if [ $(id -u) != "0" ]; then echo "ERROR: You must be the superuser (root) to run this script." exit 1 fi # # while [ "$1" != "" ]; do case $1 in -f | --file ) shift filename=$1 ;; --svnrepos ) shift SVNREPOS=$1 ;; --svnpath ) shift svnpath=$1 ;; -d | --devel ) devel=1 ;; -t | --test ) testmode=1 ;; -y | --yall ) yall=1 ;; -u | --user ) shift SVNUSER=$1 ;; -p | --passwd ) shift SVNPASSWD=$1 ;; -h | --help ) help=1 exit ;; -v | --verbose ) verbose=1 ;; -w | --wipe ) wipeit=1 ;; * ) help=1 exit 1 esac shift done # source=$SVNREC target=/tmp/evb_stats.txt wget -O $target $source > /dev/null 2>&1 recsvnhome=$(grep ^recsvnhome $target | head -n1 | cut -d \= -f 2 | sed -e 's/^[ \t]*//') recsvnbase=$(grep ^recsvnbase $target | head -n1 | cut -d \= -f 2 | sed -e 's/^[ \t]*//') if [ $verbose -gt 0 ]; then echo "rec svn="$recsvnhome/asterisk/$recsvnbase fi # #lastsvnpath=$(basename $(svn info /usr/src/svnwork/asterisk | grep ^URL | cut -d \: -f 3)) # if [ $yall = 0 ]; then echo "This program will update the Asterisk app_rpt sources on this computer" echo "by overwriting them with the latest versions from the developers." echo "This means that any changes you have made locally to the sources will" echo "be lost unless you have made a backup copy." echo "After downloading the new sources, the Zaptel and Asterisk software" echo "will be remade and installed. Your configuration information will not" echo "be modified or lost by the update." echo "" echo "The recommended update base is:" echo " "$recsvnhome/asterisk/$recsvnbase if ! [ .$lastsvnhome = "." ]; then echo "The last update or install base was:" echo " "$lastsvnhome/asterisk/$lastsvnbase fi echo "Enter [r] to be repeat the last base." echo "Enter [c] to be prompted for a custom base." echo "Press Enter to use the recommended update base." read text svnhome=$recsvnhome svnbase=$recsvnbase if [ .$text = ".r" ]; then svnhome=$lastsvnhome svnbase=$lastsvnbase elif [ .$text = ".c" ]; then echo -n "Don't enter leading or ending slashes." echo -n "Enter first part: " read svnhome echo -n "Enter second part: " read svnbase fi echo "Using "$svnhome/asterisk/$svnbase echo -n "Do you want to proceed with the update? (n/y):" read text if [ .$text != ".y" ]; then echo "Operation canceled by user request." exit 0 fi echo "" fi if [ $testmode -gt 0 ]; then reg_send exit 0 fi # echo "" echo "Running a few tests before the update..." echo "" # # check for asterisk # if ! [ -d /usr/src/asterisk ]; then echo "ERROR: You do not have /usr/src/asterisk/." exit 1 else echo "You have /usr/src/asterisk/." fi # # test zaptel source directory # if ! [ -d /usr/src/zaptel ]; then echo "ERROR: You do not have /usr/src/zaptel." exit 1 else echo "You have /usr/src/zaptel." fi # # check for subversion # if ! [ -e /usr/bin/svn ]; then echo "ERROR: Unable to find Subversion." exit 1 else echo "You have Subversion." fi # grep 0.010 /etc/EVB/EVBrev > /dev/null 2>&1 res=$? if [ $res = 0 ]; then EVBrev=0.010 fi # grep 0.011 /etc/EVB/EVBrev > /dev/null 2>&1 res=$? if [ $res = 0 ]; then EVBrev=0.011 fi # echo "You have EVB revision $EVBrev" # if [ -e $APPINSTALLED ]; then previnstall=1 echo "Previous app_rpt installation found." else previnstall=0 echo "ERROR: No previous app_rpt installation found." exit 1 fi # # # svn diff --non-interactive > /tmp/svnrptdiff # diffhit=0 # cd $SVNWORK/asterisk # svn status > /tmp/zrptz if [ -s /tmp/zrptz ]; then echo "asterisk - Local Working Copy Modified Locally." fi # svn diff -r HEAD --username $SVNUSER --password $SVNPASSWD > /tmp/zrptz # echo -n "asterisk - " if ! [ -s /tmp/zrptz ]; then echo "Local Working Copy Matches Repository." else echo "Local Working Copy Does Not Match Repository." diffhit=1 fi # cd $SVNWORK/zaptel # svn diff -r HEAD --username $SVNUSER --password $SVNPASSWD > /tmp/zrptz # echo -n "zaptel - " if ! [ -s /tmp/zrptz ]; then echo "Local Working Copy Matches Repository." else echo "Local Working Copy Does Not Match Repository." diffhit=1 fi # if [ $diffhit = 1 ]; then echo "" echo "A new version is available from the developers." fi # if [ $yall = 0 ]; then echo "" echo "-- SECOND NOTICE --" echo "This program will update the Asterisk app_rpt sources on this computer" echo "by overwriting them with the latest versions from the developers." echo "This means that any changes you have made locally to the sources will" echo "be lost unless you have made a backup copy." echo "After downloading the new sources, the Zaptel and Asterisk software" echo "will be remade and installed. Your configuration information will not" echo "be modified or lost by the update." echo "" echo -n "Do you really want to proceed with the update? (n/y):" read text if [ .$text != ".y" ]; then echo "Operation canceled by user request." exit 0 fi fi # echo "$svnbase" > $LASTSVNPATHFILE # # # make backup copies # if ! [ -d $SVNWORK/backup/asterisk ]; then if ! [ -d $SVNWORK ]; then echo "Creating $SVNWORK" mkdir $SVNWORK fi if ! [ -d $SVNWORK/backup ]; then echo "Creating $SVNWORK/backup" mkdir $SVNWORK/backup fi if ! [ -d $SVNWORK/backup/asterisk ]; then echo "Creating $SVNWORK/backup/asterisk" mkdir $SVNWORK/backup/asterisk fi fi # cp -p /usr/src/zaptel/pciradio.c $SVNWORK/backup/asterisk/. # cp -p /usr/src/zaptel/zaptel-base.c $SVNWORK/backup/asterisk/. cp -p /usr/src/asterisk/menuselect-tree $SVNWORK/backup/asterisk/. cp -p /usr/src/asterisk/apps/app_rpt.c $SVNWORK/backup/asterisk/. cp -p /usr/src/asterisk/channels/chan_usbradio.c $SVNWORK/backup/asterisk/. cp -p /usr/src/asterisk/channels/Makefile $SVNWORK/backup/asterisk/. cp -p -r /usr/src/asterisk/channels/xpmr $SVNWORK/backup/asterisk/. # # subversion checkout # cd $SVNWORK rm -fR $SVNWORK/asterisk svn checkout $svnhome/asterisk/$svnbase $SVNWORK/asterisk --username $SVNUSER --password $SVNPASSWD # cd $SVNWORK/asterisk if ! [ -e /usr/src/asterisk/zprot_menuselect ]; then cp -p ./menuselect-tree /usr/src/asterisk/menuselect-tree cp -p ./build_tools/cflags.xml /usr/src/asterisk/build_tools/. else echo "menuselect-tree is protected." fi # targetdir=$SVNWORK/asterisk linkdir=/usr/src/asterisk # sourcefile=configs/rpt.conf.sample rmifnotlink # sourcefile=apps/app_rpt.c rmifnotlink # sourcefile=channels/chan_usbradio.c rmifnotlink # sourcefile=channels/xpmr rmifnotlink # cp -p ./channels/Makefile /usr/src/asterisk/channels/Makefile # touch /etc/EVB/zlinks # # # checkout zaptel # cd $SVNWORK rm -fR $SVNWORK/zaptel svn checkout $svnhome/zaptel/$svnbase $SVNWORK/zaptel --username $SVNUSER --password $SVNPASSWD # targetdir=$SVNWORK/zaptel linkdir=/usr/src/zaptel sourcefile=pciradio.c rmifnotlink # cd $SVNWORK/zaptel if [ $EVBrev = 0.010 ]; then cp ./zaptel-base.c.EVB010 ./zaptel-base.c cp ztcfg.c.EVB010 ztcfg.c fi # if [ $EVBrev = 0.011 ]; then cp ./zaptel-base.c.EVB011 ./zaptel-base.c cp ztcfg.c.EVB011 ztcfg.c fi # targetdir=$SVNWORK/zaptel linkdir=/usr/src/zaptel sourcefile=zaptel-base.c rmifnotlink # # get sounds # if [ -d $SVNWORK/rpt-sounds ]; then echo "You have $SVNWORK/rpt-sounds." else echo "Creating $SVNWORK/rpt-sounds." mkdir $SVNWORK/rpt-sounds fi # cd $SVNWORK rm -fR $SVNWORK/rpt-sounds svn checkout $svnhome/rpt-sounds/$svnbase $SVNWORK/rpt-sounds --username $SVNUSER --password $SVNPASSWD # tar xzf $SVNWORK/rpt-sounds/rpt-sounds.tar.gz -C /var/lib/asterisk/sounds/ #tar xzf $SVNWORK/rpt-sounds/nodenames.tar.gz -C /var/lib/asterisk/sounds/ # # get better quality ulaw sounds # cd /var/lib/asterisk/sounds soundurl=http://downloads.digium.com/pub/telephony/sounds/ soundfile1=asterisk-core-sounds-en-ulaw-current.tar.gz soundfile2=asterisk-extra-sounds-en-ulaw-current.tar.gz if ! [ -e $soundfile1 ]; then wget -N $soundurl$soundfile1 wget -N $soundurl$soundfile2 tar xzf asterisk-core-sounds-en-ulaw-current.tar.gz tar xzf asterisk-extra-sounds-en-ulaw-current.tar.gz chown -R asterisk:asterisk * fi # # so that g726aal2 works on radio links # conf=/etc/asterisk/iax_general_custom.conf target="bandwidth=high" if ! [ -e $conf ]; then touch $conf chown asterisk:asterisk $conf fi grep "$target" $conf > /dev/null 2>&1 res=$? if [ $res = 1 ]; then echo ";" >> $conf echo $target >> $conf fi # # # checkout scripts # if [ -d $SVNWORK/scripts ]; then echo "You have $SVNWORK/scripts." else echo "Creating $SVNWORK/scripts." mkdir $SVNWORK/scripts fi # cd $SVNWORK rm -fR $SVNWORK/scripts svn checkout $svnhome/scripts/$svnbase $SVNWORK/scripts --username $SVNUSER --password $SVNPASSWD cd $SVNWORK/scripts cp -p ./rc.updatenodelist /usr/local/bin/. # #targetfile="/var/lib/asterisk/bin/freepbx_engine" #cp -p ./freepbx_engine $targetfile #chown asterisk:asterisk $targetfile #chmod 754 $targetfile # cp ./permiblast /usr/local/bin/permiblast chown root:root /usr/local/bin/permiblast chmod 700 /usr/local/bin/permiblast # cp ./svn_rpt_update /usr/local/bin/svn_rpt_update chown root:root /usr/local/bin/svn_rpt_update chmod 700 /usr/local/bin/svn_rpt_update # cp ./svn_rpt_update_a /usr/local/bin/svn_rpt_update_a chown root:root /usr/local/bin/svn_rpt_update_a chmod 700 /usr/local/bin/svn_rpt_update_a # cp ./svn_2_app_rpt /usr/local/bin/svn_2_app_rpt chown root:root /usr/local/bin/svn_2_app_rpt chmod 700 /usr/local/bin/svn_2_app_rpt # cp ./rpt_info_dump /usr/local/bin/rpt_info_dump chown root:root /usr/local/bin/rpt_info_dump chmod 700 /usr/local/bin/rpt_info_dump # cp ./app_rpt_helper /usr/local/bin/app_rpt_helper chown root:root /usr/local/bin/app_rpt_helper chmod 700 /usr/local/bin/app_rpt_helper # # make sure rc.local calls app_rpt_helper # grep "/usr/local/bin/app_rpt_helper" /etc/rc.local > /dev/null 2>&1 res=$? if [ $res = 1 ]; then sed -i '/touch \/var\/lock\/subsys\/local/{p;s/.*/\/usr\/local\/bin\/app_rpt_helper/;}' /etc/rc.local fi # # possibly set flag to call new update program later # amportal kill # # # rebuild and re-install zaptel and then asterisk # echo "" echo "Rebuilding Zaptel..." echo "" cd /usr/src/zaptel # # zaptel make install trashes /etc/zaptel.conf so copy and reload as needed # cp -p /etc/zaptel.conf /etc/zaptel.conf.rpt_bck # make res=$? if [ $res = 0 ]; then echo "make OK." else echo "ERROR: Zaptel make returned $res make NOT OK. Process Failed." exit 1 fi make install # cp -p /etc/zaptel.conf.rpt_bck /etc/zaptel.conf # #ztcfg # echo "" echo "Rebuilding Asterisk..." echo "" cd /usr/src/asterisk # echo "x" | make menuselect sed -i 's/app_rpt//' ./menuselect.makeopts sed -i 's/MENUSELECT_CFLAGS=/MENUSELECT_CFLAGS=RADIO_RELAX /' ./menuselect.makeopts rm apps/app_rpt.o rm apps/app_rpt.so rm channels/chan_usbradio.o rm channels/chan_usbradio.so make res=$? if [ $res = 0 ]; then echo "make OK." else echo "ERROR: Asterisk make returned $res make NOT OK. Process Failed." exit 1 fi make install # echo "******************************************************" >> $EVBRPTLOG echo "rpt update $(date +%Y%m%d_%H%M%S) " >> $EVBRPTLOG svn info $SVNWORK/asterisk >> $EVBRPTLOG # echo "$(date +%Y%m%d_%H%M%S) " > $BUILDON # echo "" echo "" echo "" echo "svn_rpt_update - update complete." echo "" reg_send echo "A reboot will ensure that everything is reinitialized." echo -n "We suggest a reboot. Reboot now? (y/n):" read text echo "" if [ .$text = ".n" ]; then echo "The computer will NOT reboot now." echo "Warning: Zaptel may need to be reloaded." echo " Asterisk is probably not running." echo "" exit 0 fi echo "Rebooting the computer now." reboot # # end of file #