freedombone/src/freedombone-sipfreeext

58 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Returns the next free SIP extension number
# License
# =======
#
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CONFIG_FILE=/etc/sipwitch.conf
extensions=()
# get the used extensions
2015-11-02 13:11:49 +01:00
IFS=''
2015-11-02 15:53:18 +01:00
for line in $(cat $CONFIG_FILE | grep "extension"); do
extnum=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
extensions+=($extnum)
done
2015-11-02 15:53:18 +01:00
# find the max extension number
maxnum=201
for i in ${extensions[@]}; do
if [ $i -gt $maxnum ]; then
maxnum=$i
break
fi
done
2015-11-02 15:53:18 +01:00
if [ $maxnum -gt 299 ]; then
exit 1
fi
echo $(($maxnum + 1))
exit 0