Improved loops

This commit is contained in:
Bob Mottram 2015-11-02 12:11:49 +00:00
parent d50e8ad1d3
commit 5ca98a2050
3 changed files with 19 additions and 19 deletions

View File

@ -43,13 +43,13 @@ function show_help {
}
function sip_user_exists {
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; do
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then
USER_EXISTS="yes"
return
fi
done
done < $CONFIG_FILE
}
function update_sip_user {
@ -59,8 +59,8 @@ function update_sip_user {
rm -f $NEW_CONFIG_FILE
fi
touch $NEW_CONFIG_FILE
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; do
if [ ! $USER_FOUND ]; then
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then
USER_FOUND="yes"
@ -78,7 +78,7 @@ function update_sip_user {
fi
fi
echo $line >> $NEW_CONFIG_FILE
done
done < $CONFIG_FILE
mv $NEW_CONFIG_FILE $CONFIG_FILE
}
@ -88,8 +88,8 @@ function add_sip_user {
rm -f $NEW_CONFIG_FILE
fi
touch $NEW_CONFIG_FILE
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; do
if [[ "$line" == '</provision>' ]]; then
echo "<user id=\"$MY_USERNAME\">" >> $NEW_CONFIG_FILE
echo "<extension>$EXTENSION</extension>" >> $NEW_CONFIG_FILE
@ -98,7 +98,7 @@ function add_sip_user {
echo '</user>' >> $NEW_CONFIG_FILE
fi
echo $line >> $NEW_CONFIG_FILE
done
done < $CONFIG_FILE
mv $NEW_CONFIG_FILE $CONFIG_FILE
usermod -aG sipwitch $MY_USERNAME
}

View File

@ -41,13 +41,13 @@ function show_help {
}
function sip_user_exists {
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; do
if [[ "$line" == "<user id=\"$MY_USERNAME\">" ]]; then
USER_EXISTS="yes"
return
fi
done
done < $CONFIG_FILE
}
function remove_sip_user {
@ -57,21 +57,21 @@ function remove_sip_user {
rm -f $NEW_CONFIG_FILE
fi
touch $NEW_CONFIG_FILE
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; 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
echo "$line" >> $NEW_CONFIG_FILE
else
if [[ "$line" == '</user>' ]]; then
USER_FOUND=
fi
fi
done
done < $CONFIG_FILE
mv $NEW_CONFIG_FILE $CONFIG_FILE
}

View File

@ -34,8 +34,8 @@ CONFIG_FILE=/etc/sipwitch.conf
extensions=()
# get the used extensions
for line in $(cat $CONFIG_FILE)
do
IFS=''
while read line; do
if [[ "$line" == "<extension>"* ]]; then
ext=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
extensions+=($ext)
@ -43,7 +43,7 @@ do
if [[ "$line" == '</provision>' ]]; then
break
fi
done
done < $CONFIG_FILE
#echo "used extensions:"
#echo $extensions