#!/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/capi2text-check-number-settings - check phone number settings # # Copyright (c) 2009-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation : 2009-10-01 jed # Last Update: $Id$ # # Usage: capi2text-check-number-settings [-simulate phone-number] # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ # read eislib etc. . /var/install/include/eislib . /var/install/include/jedlib # activate debug output #debug_capi2text=true if ${debug_capi2text:-false} then exec 2> /tmp/$(basename ${0})-trace-$$.log set -x ask_debug=true export ask_debug fi configfile=/etc/config.d/capi2text logfile=/var/log/messages if [ "$1" = "-simulate" ] then # remove non numeric values and spaces sresult="`echo "$2" | sed -e 's/^[^0-9].*//g' -e 's/ *//g'`" # simulate 'phone number not found' if [ "${sresult}" = "999" ] then sresult=' ' fi fi if [ -z "${sresult}" ] then sresult='' fi if [ -f "${configfile}" ] then # read configuration . ${configfile} # country code if [ -z "${CAPI2TEXT_DEFAULT_CCODE}" ] then CAPI2TEXT_DEFAULT_CCODE='49' fi clrhome mecho --info "check phone number settings" mecho if /var/install/bin/ask "Have you finished your Capi2Text configuration" "n" then # configuration done, go on ... if /var/install/bin/ask "Have you done an external test call" "n" then # test call successfully done, go on ... mecho mecho --info "Reading phone number from log file ..." if [ -z "${sresult}" ] then # read phone number from logfile # kernel: capidrv-1: incoming call 00172334455,1,1,21 # listen2fritz[11790]: incoming call from 00172334455 -> 0 00492131445566 sresult=`grep -E "kernel:.*incoming call |listen2fritz[[0-9]*]: incoming call " ${logfile} | grep -v "incoming call *," | \ grep -v "call 0*${CAPI2TEXT_DEFAULT_CCODE}" | tail -1 | \ sed -e 's/^.*incoming call from //' -e 's/^.*incoming call //' -e 's/,.*$//' -e 's/->.*$//' -e 's/ *//g'` else sresult=`echo "${sresult}" | sed 's/ *//g'` fi if [ -n "${sresult}" ] then # phone number number read, go on ... mecho mecho -n "Found number: " mecho --warn "${sresult}" mecho # count leading zeros zstr=`echo "${sresult}" | sed 's/[^0].*$//'` if [ -z "${zstr}" ] then zcount=0 else zcount=`expr length ${zstr}` fi zmax=1 # if /var/install/bin/ask "Does the phone number contain a country code, e.g. 49 for Germany" "n" # then # zmax=2 # fi mecho mecho --info "Checking settings ..." mecho mecho -n "Current settings: " mecho --warn "CAPI2TEXT_NUMBER_TRIMLEADING='${CAPI2TEXT_NUMBER_TRIMLEADING}'" mecho -n " " mecho --warn "CAPI2TEXT_NUMBER_ADDCHARS='${CAPI2TEXT_NUMBER_ADDCHARS}'" mecho # compare values # if [ ${zcount} -eq ${zmax} ] # then # # everything ok # trimchar='0' # addchar='' # elif [ ${zcount} -le ${zmax} ] # then # # add one zero # trimchar='0' # addchar='0' # else # # remove n zeros # trimchar="`expr ${zcount} - 1`" # addchar='' # fi if [ ${zcount} -gt 0 ] then trimchar="${zcount}" else trimchar='' fi addchar='' if [ ${trimchar} -ne `echo "${CAPI2TEXT_NUMBER_TRIMLEADING}" | sed 's/^[zZ]//'` -o \ "${CAPI2TEXT_NUMBER_ADDCHARS}" != "${addchar}" ] then mecho -n "recommended settings: " mecho --info "CAPI2TEXT_NUMBER_TRIMLEADING='${trimchar}'" mecho -n " " mecho --info "CAPI2TEXT_NUMBER_ADDCHARS='${addchar}'" mecho mecho --info "Please update your configuration!" else mecho --info "The settings seem to be ok." fi mecho else mecho --error "Unable to read phone number from logfile, check aborted!" fi else mecho --warn "Check aborted!" fi else mecho --warn "Check aborted!" fi anykey else mecho --error "No configuration file '${configfile}' found!" anykey fi exit 0