Menu

[r1285]: / trunk / etc / configxml.subr  Maximize  Restore  History

Download this file

67 lines (56 with data), 1.5 kB

# Copyright © 2007 Volker Theile (votdev@gmx.de)
# All rights reserved.
#
# configxml.subr
#	functions used by various rc scripts
#

configxml_file=${configxml_file:-"/conf/config.xml"}

# configxml_isset xpath
# Check in /conf/config.xml if xpath is available/found.
# Return 0 if set, nonzero otherwise.
# $1 - XPATH expression
configxml_isset()
{
	local _result

	_result=`/usr/local/bin/xml sel -t -v "count($1)" ${configxml_file}`
	if [ 0 -eq ${_result} ]; then
		return 1
	else
		return 0
	fi
}

# configxml_exec_query xquery
# Execute given query.
# Return result from query is echoed.
configxml_exec_query()
{
	local _tmpfile _queryresult _result

	# Create temporary script filename.
	_tmpfile="/tmp/xmlquery$$"

	# Create temporary script to execute xml query.
	echo "/usr/local/bin/xml sel -t $@ ${configxml_file}" > ${_tmpfile}
	# Change permissions to execute script.
	chmod 0700 ${_tmpfile}
	# Execute script and store result in variable.
	_queryresult=`${_tmpfile}`
	_result=$?
	# Remove temporary script.
	rm -f ${_tmpfile}
	# Output query result for later processing.
	echo ${_queryresult}

	return ${_result}
}

# configxml_set_rcvar xpath
# Set ${rcvar} depending on whether XPATH expression evaluates true.
# $1 - XPATH expression
configxml_set_rcvar()
{
	local _value

	if configxml_isset $1; then
		eval ${rcvar}=YES
	else
		eval ${rcvar}=NO
	fi

	eval _value=\$${rcvar}
	debug "configxml_setrcvar: ${rcvar} has been changed to $_value."
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.