diff --git a/src/freedombone-sipfreeext b/src/freedombone-sipfreeext index 5fbb07b2..f1f181e5 100755 --- a/src/freedombone-sipfreeext +++ b/src/freedombone-sipfreeext @@ -35,35 +35,23 @@ extensions=() # get the used extensions IFS='' -while read line; do - if [[ "$line" == *""* ]]; then - ext=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') - extensions+=($ext) - fi - if [[ "$line" == *'' ]]; then - break - fi -done < $CONFIG_FILE +for line in $(cat $CONFIG_FILE | grep "extension"); do + extnum=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') + extensions+=($extnum) +done -#echo "used extensions:" -#echo $extensions -#echo " " - -# which is the first available unused extension ? -for ext in $(seq 201 299); -do - is_used= - for i in "${extensions[@]}" - do - if [[ "$i" == "$ext" ]]; then - is_used=1 - break - fi - done - if [ ! $is_used ]; then - echo $ext; +# find the max extension number +maxnum=201 +for i in ${extensions[@]}; do + if [ $i -gt $maxnum ]; then + maxnum=$i break fi done +if [ $maxnum -gt 299 ]; then + exit 1 +fi + +echo $(($maxnum + 1)) exit 0