2015-11-02 12:22:20 +01:00
|
|
|
#!/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 12:22:20 +01:00
|
|
|
|
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
|
2015-11-02 12:22:20 +01:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-11-02 15:53:18 +01:00
|
|
|
if [ $maxnum -gt 299 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $(($maxnum + 1))
|
2015-11-02 12:22:20 +01:00
|
|
|
exit 0
|