#!/bin/bash # # .---. . . # | | | # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-' # ' ' --' --' -' - -' ' ' -' -' -' ' - --' # # Freedom in the Cloud # # Returns the next free SIP extension number # License # ======= # # Copyright (C) 2015 Bob Mottram # # 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 . CONFIG_FILE=/etc/sipwitch.conf extensions=() # get the used extensions for line in $(cat $CONFIG_FILE) do if [[ "$line" == ""* ]]; then ext=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') extensions+=($ext) fi if [[ "$line" == '' ]]; 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