Command to remove SIP user

This commit is contained in:
Bob Mottram 2015-11-02 10:12:49 +00:00
parent c4bfb48415
commit 5f7447665a
3 changed files with 81 additions and 1 deletions

View File

@ -42,6 +42,7 @@ install:
install -m 755 src/${APP}-controlpanel ${DESTDIR}${PREFIX}/bin/control
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
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
@ -69,6 +70,8 @@ install:
install -m 644 man/${APP}-mesh.1.gz ${DESTDIR}${PREFIX}/share/man/man1
install -m 644 man/${APP}-controlpanel.1.gz ${DESTDIR}${PREFIX}/share/man/man1
install -m 644 man/${APP}-logging.1.gz ${DESTDIR}${PREFIX}/share/man/man1
install -m 644 man/${APP}-addsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1
install -m 644 man/${APP}-rmsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1
uninstall:
rm -f ${PREFIX}/share/man/man1/${APP}.1.gz
rm -f ${PREFIX}/share/man/man1/${APP}-keydrive.1.gz
@ -97,6 +100,7 @@ uninstall:
rm -f ${PREFIX}/share/man/man1/${APP}-controlpanel.1.gz
rm -f ${PREFIX}/share/man/man1/${APP}-logging.1.gz
rm -f ${PREFIX}/share/man/man1/${APP}-addsipuser.1.gz
rm -f ${PREFIX}/share/man/man1/${APP}-rmsipuser.1.gz
rm -rf ${PREFIX}/share/${APP}
rm -f ${PREFIX}/bin/${APP}
rm -f ${PREFIX}/bin/zeronetavahi
@ -128,6 +132,7 @@ uninstall:
rm -f ${PREFIX}/bin/${APP}-controlpanel
rm -f ${PREFIX}/bin/${APP}-logging
rm -f ${PREFIX}/bin/${APP}-addsipuser
rm -f ${PREFIX}/bin/${APP}-rmsipuser
clean:
rm -f \#* \.#* debian/*.substvars debian/*.log
rm -fr deb.* debian/${APP}

View File

@ -146,10 +146,12 @@ fi
sip_user_exists
if [[ USER_EXISTS == "yes" ]]; then
if [[ $USER_EXISTS == "yes" ]]; then
update_sip_user
echo "SIP user $MY_USERNAME amended"
else
add_sip_user
echo "SIP user $MY_USERNAME added"
fi
service sipwitch restart

View File

@ -29,4 +29,77 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
MY_USERNAME=$1
CONFIG_FILE=/etc/sipwitch.conf
USER_EXISTS="no"
function show_help {
echo ''
echo 'freedombone-rmsipuser [username]'
echo ''
exit 0
}
function sip_user_exists {
for line in $ (cat $CONFIG_FILE)
do
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then
USER_EXISTS="yes"
return
fi
done
}
function remove_sip_user {
USER_FOUND=
NEW_CONFIG_FILE="${CONFIG_FILE}.new"
if [ -f $NEW_CONFIG_FILE ]; then
rm -f $NEW_CONFIG_FILE
fi
touch $NEW_CONFIG_FILE
for line in $ (cat $CONFIG_FILE)
do
if [ ! $USER_FOUND ]; then
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then
USER_FOUND="yes"
fi
fi
if [ ! $USER_FOUND ]; then
echo "$line" >> $NEW_CONFIG_FILE
else
if [[ "$line" == '</user>' ]]; then
USER_FOUND=
fi
fi
done
mv $NEW_CONFIG_FILE $CONFIG_FILE
}
if [ ! $MY_USERNAME ]; then
show_help
fi
if [ ! -f $CONFIG_FILE ]; then
echo "SIP configuration file not found"
exit 1
fi
# the user must already exist on the system
if [ ! -d /home/$MY_USERNAME ]; then
echo "User $MY_USERNAME not found"
exit 2
fi
sip_user_exists
if [[ $USER_EXISTS != "yes" ]]; then
echo 'User not found within SIP configuration file'
exit 3
fi
remove_sip_user
service sipwitch restart
echo "SIP user $MY_USERNAME removed"
exit 0