From 64820e016c22cc4a18a53b0f28aae9392ebaf252 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 8 Apr 2015 16:28:18 +0200 Subject: [PATCH] Bug 13971: Adjusted locations in koha-rebuild-zebra for gitified instance This patch adds a few lines to koha-rebuild-zebra in order to adjust the locations for PERL5LIB and rebuild_zebra.pl script. It also adds two functions to koha-functions: is_gitified and get_perl5lib. It builds on the notion that koha-conf.xml contains a tag for gitified installs. It also looks for a perl5lib tag in koha-conf. NOTE: If the gitified or the perl5lib tag does not exist, behavior does not change. I will submit a separate follow-up report for adding those tags. The use of function get_perl5lib can replace hardcoded paths in the other scripts too; I will also move that to a new report. Furthermore, I would like to use the Zebra setup from the gitified instance instead of the default files in /etc/koha/zebradb. Will put that in another report too. Test plan: [1] Verify that your koha-conf does not contain: 1 [2] Run koha-rebuild-zebra -a -b -v [instance] [3] If you have a gitified instance, add the gitified tag to your koha-conf and the path in a perl5lib tag. [4] Run koha-rebuild-zebra -a -b -v [instance] Verify that you run the right version of rebuild_zebra.pl. You could do that by adding a simple debug print. Signed-off-by: Mirko Tietgen --- debian/scripts/koha-functions.sh | 25 +++++++++++++++++++++++++ debian/scripts/koha-rebuild-zebra | 18 +++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index 8090fc5..2bf17b2 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -126,3 +126,28 @@ get_instances() find /etc/koha/sites -mindepth 1 -maxdepth 1\ -type d -printf '%f\n' | sort } + +get_perl5lib() +{ + local instancename=$1 + + #first try perl5lib in koha-conf.xml + local retval=$(xmlstarlet sel -t -v 'yazgfs/config/perl5lib' /etc/koha/sites/$instancename/koha-conf.xml) + + if [ "$retval" != "" ]; then + echo "$retval" + else + echo "/usr/share/koha/lib" + fi +} + +is_gitified() +{ + local instancename=$1 + local retval=$(xmlstarlet sel -t -v 'yazgfs/config/gitified' /etc/koha/sites/$instancename/koha-conf.xml) + if [ "$retval" = "1" ]; then + return 0 + else + return 1 + fi +} diff --git a/debian/scripts/koha-rebuild-zebra b/debian/scripts/koha-rebuild-zebra index f8267c5..e701d6b 100755 --- a/debian/scripts/koha-rebuild-zebra +++ b/debian/scripts/koha-rebuild-zebra @@ -20,7 +20,10 @@ set -e # include helper functions -if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then +scriptdir=$(dirname "$0") +if [ -f $scriptdir/koha-functions.sh ]; then + . "$scriptdir/koha-functions.sh" +elif [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then . "/usr/share/koha/bin/koha-functions.sh" else echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 @@ -49,12 +52,21 @@ run_rebuild_zebra() { local instancename=$1; shift + # If we 'gitified' a Koha instance, point to adjusted locations + local libpath=$(get_perl5lib $instancename) + local rebuild + if is_gitified $instancename; then + rebuild="$libpath/misc" + else + rebuild="/usr/share/koha/bin" + fi + # TODO: This comment is here to remind us that we should make # rebuild_zebra.pl return error codes on failure if sudo -u "$instancename-koha" -H \ - env PERL5LIB=/usr/share/koha/lib \ + env PERL5LIB=$libpath \ KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \ - /usr/share/koha/bin/migration_tools/rebuild_zebra.pl $@ ; then + $rebuild/migration_tools/rebuild_zebra.pl $@ ; then return 0 else return 1 -- 1.7.10.4