Line matching

This commit is contained in:
Bob Mottram 2015-11-02 12:16:21 +00:00
parent 5ca98a2050
commit a9efd5bcb3
2 changed files with 9 additions and 9 deletions

View File

@ -45,7 +45,7 @@ function show_help {
function sip_user_exists { function sip_user_exists {
IFS='' IFS=''
while read line; do while read line; do
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
USER_EXISTS="yes" USER_EXISTS="yes"
return return
fi fi
@ -62,17 +62,17 @@ function update_sip_user {
IFS='' IFS=''
while read line; do while read line; do
if [ ! $USER_FOUND ]; then if [ ! $USER_FOUND ]; then
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
USER_FOUND="yes" USER_FOUND="yes"
fi fi
else else
if [[ "$line" == "<extension>"* ]]; then if [[ "$line" == *"<extension>"* ]]; then
line="<extension>$EXTENSION</extension>" line="<extension>$EXTENSION</extension>"
fi fi
if [[ "$line" == "<secret>"* ]]; then if [[ "$line" == *"<secret>"* ]]; then
line="<secret>$PASSWORD</secret>" line="<secret>$PASSWORD</secret>"
fi fi
if [[ "$line" == "<display>"* ]]; then if [[ "$line" == *"<display>"* ]]; then
line="<display>$MY_USERNAME $EXTENSION</display>" line="<display>$MY_USERNAME $EXTENSION</display>"
USER_FOUND= USER_FOUND=
fi fi
@ -90,7 +90,7 @@ function add_sip_user {
touch $NEW_CONFIG_FILE touch $NEW_CONFIG_FILE
IFS='' IFS=''
while read line; do while read line; do
if [[ "$line" == '</provision>' ]]; then if [[ "$line" == *'</provision>' ]]; then
echo "<user id=\"$MY_USERNAME\">" >> $NEW_CONFIG_FILE echo "<user id=\"$MY_USERNAME\">" >> $NEW_CONFIG_FILE
echo "<extension>$EXTENSION</extension>" >> $NEW_CONFIG_FILE echo "<extension>$EXTENSION</extension>" >> $NEW_CONFIG_FILE
echo "<secret>$PASSWORD</secret>" >> $NEW_CONFIG_FILE echo "<secret>$PASSWORD</secret>" >> $NEW_CONFIG_FILE

View File

@ -43,7 +43,7 @@ function show_help {
function sip_user_exists { function sip_user_exists {
IFS='' IFS=''
while read line; do while read line; do
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
USER_EXISTS="yes" USER_EXISTS="yes"
return return
fi fi
@ -60,14 +60,14 @@ function remove_sip_user {
IFS='' IFS=''
while read line; do while read line; do
if [ ! $USER_FOUND ]; then if [ ! $USER_FOUND ]; then
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then if [[ "$line" == *"<user id=\"$MY_USERNAME\">" ]]; then
USER_FOUND="yes" USER_FOUND="yes"
fi fi
fi fi
if [ ! $USER_FOUND ]; then if [ ! $USER_FOUND ]; then
echo "$line" >> $NEW_CONFIG_FILE echo "$line" >> $NEW_CONFIG_FILE
else else
if [[ "$line" == '</user>' ]]; then if [[ "$line" == *'</user>' ]]; then
USER_FOUND= USER_FOUND=
fi fi
fi fi