#!/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 IFS='' for line in $(cat $CONFIG_FILE | grep "extension"); do extnum=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}') extensions+=($extnum) done # 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