From 7e59a41e4fcbe73ef475be5f8791d386d1a84d7e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 2 Nov 2015 15:30:24 +0000 Subject: [PATCH] Improved way of getting the next SIP extension --- src/freedombone-sipfreeext | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/freedombone-sipfreeext b/src/freedombone-sipfreeext index f1f181e5..3196fbf9 100755 --- a/src/freedombone-sipfreeext +++ b/src/freedombone-sipfreeext @@ -31,27 +31,12 @@ CONFIG_FILE=/etc/sipwitch.conf -extensions=() - -# get the used extensions -IFS='' -for line in $(cat $CONFIG_FILE | grep "extension"); do - extnum=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') - extensions+=($extnum) -done - -# find the max extension number maxnum=201 -for i in ${extensions[@]}; do - if [ $i -gt $maxnum ]; then - maxnum=$i - break - fi +while (( maxnum < 299 )); do + if ! grep -q "extension>$maxnum<" $CONFIG_FILE; then + break; + fi + maxnum=$((maxnum + 1)) done - -if [ $maxnum -gt 299 ]; then - exit 1 -fi - -echo $(($maxnum + 1)) +echo $maxnum exit 0