# Copyright (c) 2012 Tresys Technology LLC, Columbia, Maryland, USA
#
# This software was developed by Tresys Technology LLC
# with U.S. Government sponsorship.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


FILE=/etc/avahi/avahi-daemon.conf

function add_section_entry() {
# Add an avahi entry to the proper section in /etc/avahi/avahi-daemon.conf
#  arguments:
#    ENTRY   - The appropriate name to add to the conf file
#    OPTION  - A yes/no value that ENTRY should be set to
#    SECTION - The section in which this ENTRY=OPTION line should appear
#
	ENTRY=$1 OPTION=$2 SECTION=$3

	[ -f $FILE ] || exit 1

	/bin/sed -i -r -e "s/(\s*)(\#*)(\s*)($ENTRY)(=.*)/\3\4=$OPTION/g" $FILE
	/bin/echo $LINE
	COUNT=$( /bin/grep -Ec "$ENTRY\=.*" $FILE )

	if [ $COUNT -eq 0 ]; then
		SECTIONLINE=$( /bin/grep -n "^\[$SECTION\]" $FILE )
		SECTIONLINE=${SECTIONLINE%":[$SECTION]"}
		
		/bin/sed -i -r -e "${SECTIONLINE}a\
		$ENTRY=$OPTION" $FILE
	fi
}
