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 12:27:32 +01:00
|
|
|
for line in $(cat $CONFIG_FILE)
|
2015-11-02 12:22:20 +01:00
|
|
|
do
|
|
|
|
if [[ "$line" == "<extension>"* ]]; then
|
|
|
|
ext=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
|
|
|
|
extensions+=($ext)
|
|
|
|
fi
|
|
|
|
if [[ "$line" == '</provision>' ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
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;
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|