Bug 16749: Adjust xmlstarlet calls in koha-functions

In various scripts we use xmlstarlet to extract values from koha-conf.
If we call xmlstarlet on non-existing entries in koha-conf, this may
however result in silently failing scripts (when set -e is in effect).

A function run_safe_xmlstarlet is added for situations where the entry
might not exist. It will not halt execution.

This patch only adjusts koha-functions.sh and modifies the xmlstarlet calls
for dev_install and zebra_loglevels.

Note: The function does not need to check file existence. If the file does
not exist, xmlstarlet warns about it; the function returns empty string,
but does not set an error exit status.

Test plan: See second patch ("koha-plack adjustments").

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Tested in a package installation of master+16749

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Marcel de Rooy 2017-02-10 09:37:13 +01:00 committed by Kyle M Hall
parent 2b9662e0ca
commit 4ecc98c37f
1 changed files with 17 additions and 7 deletions

View File

@ -222,16 +222,14 @@ adjust_paths_dev_install()
# corresponding tag in koha-conf.xml
local instancename=$1
local dev_install
if [ -e /etc/koha/sites/$instancename/koha-conf.xml ]; then
dev_install=$(xmlstarlet sel -t -v 'yazgfs/config/dev_install' /etc/koha/sites/$instancename/koha-conf.xml)
fi
local dev_install=$(run_safe_xmlstarlet $instancename dev_install)
if [ "$dev_install" != "" ]; then
DEV_INSTALL=1
KOHA_HOME=$dev_install
PERL5LIB=$dev_install
else
DEV_INSTALL=""
fi
}
@ -244,13 +242,12 @@ get_instances()
get_loglevels()
{
local instancename=$1
local retval=$(xmlstarlet sel -t -v 'yazgfs/config/zebra_loglevels' /etc/koha/sites/$instancename/koha-conf.xml)
local retval=$(run_safe_xmlstarlet $instancename zebra_loglevels)
if [ "$retval" != "" ]; then
echo "$retval"
else
echo "none,fatal,warn"
fi
}
get_tmpdir()
@ -272,3 +269,16 @@ get_tmpdir()
fi
echo $(dirname $retval)
}
run_safe_xmlstarlet()
{
# When a bash script sets -e (errexit), calling xmlstarlet on an
# unexisting key would halt the script. This is resolved by calling
# this function in a subshell. It will always returns true, while not
# affecting the exec env of the caller. (Otherwise, errexit is cleared.)
local instancename=$1
local myexpr=$2
set +e; # stay on the safe side
echo $(xmlstarlet sel -t -v "yazgfs/config/$myexpr" /etc/koha/sites/$instancename/koha-conf.xml)
return 0
}