diff --git a/debian/docs/koha-rebuild-zebra.xml b/debian/docs/koha-rebuild-zebra.xml
index b8ce51cac3..410be8abad 100644
--- a/debian/docs/koha-rebuild-zebra.xml
+++ b/debian/docs/koha-rebuild-zebra.xml
@@ -17,13 +17,13 @@
koha-rebuild-zebra
- Rebuild the Zebra database for a Koha instance.
+ Rebuild the Zebra database for Koha instances.UNIX/Linux
- koha-rebuild-zebra||instancename
+ koha-rebuild-zebra|||||instancename
@@ -41,17 +41,35 @@
Does a reindex of the whole collection.
+
+
+
+ Only run the indexing process for authority records.
+
+
+
+
+
+ Only run the indexing process for biblio records.
+
+
+
+
+
+ Be verbose. Useful for debugging indexing problems.
+
+
- Anything else is passed directly to rebuild_zebra. This is useful in particular for -v.
+ Anything else is passed directly to rebuild_zebra.Description
- Rebuild the Zebra database for a Koha instance.
+ Rebuild the Zebra database for Koha instances.See also
diff --git a/debian/scripts/koha-rebuild-zebra b/debian/scripts/koha-rebuild-zebra
index b4478fd5d2..f32ca8bbdb 100755
--- a/debian/scripts/koha-rebuild-zebra
+++ b/debian/scripts/koha-rebuild-zebra
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# koha-rebuild-zebra -- Rebuild the Zebra database for a Koha instance.
+# koha-rebuild-zebra - Rebuild the Zebra database for Koha instances.
# Copyright 2010 Catalyst IT, Ltd
#
# This program is free software: you can redistribute it and/or modify
@@ -19,18 +19,117 @@
set -e
+die()
+{
+ echo "$@" 1>&2
+ exit 1
+}
+
+warn()
+{
+ echo "$@" 1>&2
+}
+
+is_instance()
+{
+ local instancename=$1
+
+ if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
+ -type d -printf '%f\n'\
+ | grep -q -x $instancename ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+toggle_biblios_only()
+{
+ biblios_only="yes"
+ biblios="yes"
+ if [ "$authorities_only" != "yes" ]; then
+ authorities="no"
+ fi
+}
+
+toggle_authorities_only()
+{
+ authorities_only="yes"
+ authorities="yes"
+ if [ "$biblios_only" != "yes" ]; then
+ biblios="no"
+ fi
+}
+
+run_rebuild_zebra()
+{
+ local instancename=$1; shift
+
+ # 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 \
+ KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
+ /usr/share/koha/bin/migration_tools/rebuild_zebra.pl $@ ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+usage()
+{
+ local scriptname=$0
+ cat <