diff --git a/Makefile b/Makefile index d4a52a26..c7111153 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ install: install -m 755 src/${APP}-logging ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-addsipuser ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-rmsipuser ${DESTDIR}${PREFIX}/bin + install -m 755 src/${APP}-sipfreeext ${DESTDIR}${PREFIX}/bin mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}-keydrive.1.gz ${DESTDIR}${PREFIX}/share/man/man1 @@ -133,6 +134,7 @@ uninstall: rm -f ${PREFIX}/bin/${APP}-logging rm -f ${PREFIX}/bin/${APP}-addsipuser rm -f ${PREFIX}/bin/${APP}-rmsipuser + rm -f ${PREFIX}/bin/${APP}-sipfreeext clean: rm -f \#* \.#* debian/*.substvars debian/*.log rm -fr deb.* debian/${APP} diff --git a/src/freedombone-adduser b/src/freedombone-adduser index 6e32160e..2e8b619e 100755 --- a/src/freedombone-adduser +++ b/src/freedombone-adduser @@ -205,6 +205,7 @@ if grep -q "Blog domain" $COMPLETION_FILE; then fi if grep -q "install_sip" $COMPLETION_FILE; then + SIP_EXTENSION=$(freedombone-sipfreeext) freedombone-addsipuser -u $MY_USERNAME -e $SIP_EXTENSION -p "$NEW_USER_PASSWORD" if [ ! "$?" = "0" ]; then echo 'SIP user could not be added' diff --git a/src/freedombone-sipfreeext b/src/freedombone-sipfreeext new file mode 100755 index 00000000..7a206e6d --- /dev/null +++ b/src/freedombone-sipfreeext @@ -0,0 +1,69 @@ +#!/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