Bug 17691 - add serial subscription
[koha.git] / debian / scripts / koha-rebuild-zebra
blob0eb68d018040d7bd2258e3e2c1a9c3e33091b783
1 #!/bin/sh
3 # koha-rebuild-zebra - Rebuild the Zebra database for Koha instances.
4 # Copyright 2010 Catalyst IT, Ltd
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 set -e
22 # Read configuration variable file if it is present
23 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
25 # include helper functions
26 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
27 . "/usr/share/koha/bin/koha-functions.sh"
28 else
29 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
30 exit 1
33 toggle_biblios_only()
35 biblios_only="yes"
36 biblios="yes"
37 if [ "$authorities_only" != "yes" ]; then
38 authorities="no"
42 toggle_authorities_only()
44 authorities_only="yes"
45 authorities="yes"
46 if [ "$biblios_only" != "yes" ]; then
47 biblios="no"
51 run_rebuild_zebra()
53 local instancename=$1; shift
55 if [ "$USE_INDEXER_DAEMON" = "no" ] ||
56 [ "${full_reindex}" = "yes" ] ||
57 [ "${force}" = "yes" ] ; then
59 # TODO: This comment is here to remind us that we should make
60 # rebuild_zebra.pl return error codes on failure
61 if sudo -u "$instancename-koha" -H \
62 env PERL5LIB=/usr/share/koha/lib \
63 KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
64 /usr/share/koha/bin/migration_tools/rebuild_zebra.pl $@ ; then
65 return 0
66 else
67 return 1
72 usage()
74 local scriptname=$0
75 cat <<EOF
76 Rebuild the Zebra indexes for Koha instances. The default behaviour
77 is to do an incremental rebuild.
79 Usage: $scriptname [options] instancename1 instancename2...
80 Options:
81 --usmarc|-u Runs the process as USMARC rather than
82 the default of MARCXML.
83 --authorities|-a Only run process for authorities.
84 --biblios|-b Only run process for biblios.
85 --full|-f Does a reindex of the whole collection.
86 --force Run incremental indexing even if USE_INDEXER_DAEMON="yes"
87 --quiet|-q Sometimes be a bit quieter for scripts/cronjobs.
88 --verbose|-v Be verbose.
89 --help|-h Print this help.
92 Note: Any other options are passed directly to rebuild_zebra.pl.
93 EOF
96 # Default parameters
97 opt_idx="-z"
98 opt_xml="-x"
99 opt_verbose=""
100 opts_other=""
101 biblios_only="no"
102 authorities_only="no"
103 biblios="yes"
104 authorities="yes"
105 force="no"
106 full_reindex="no"
108 # The '-q' option is intended to prevent the cronjob causing this to output
109 # help information if there are no instances defined.
110 quiet="no"
112 # Read parameters
113 while [ -n "$*" ]; do
114 case "$1" in
115 -h|--help)
116 usage ; exit 0
118 -b|--biblios)
119 toggle_biblios_only
121 -a|--authorities)
122 toggle_authorities_only
124 -u|--usmarc)
125 opt_xml=""
127 -f|--full)
128 full_reindex="yes"
129 opt_idx="-r"
131 --force)
132 force="yes"
134 -v|--verbose)
135 opt_verbose="-v"
137 -q|--quiet)
138 quiet="yes"
141 opts_other="$opts_other $1";
144 break
146 esac
148 shift
149 done
151 # Parse command line.
152 if [ $# -lt 1 ]; then
153 if [ "$quiet" = "no" ]; then
154 usage
155 die "Missing instance name."
156 else
157 exit
161 # Loop over instance names
162 for name in "$@"
164 if is_instance $name; then
165 if [ "$biblios" = "yes" ]; then
166 if ! run_rebuild_zebra $name \
167 -b $opt_verbose $opt_idx $opt_xml $opts_other; then
168 warn "Something went wrong rebuilding biblio indexes for $name"
171 if [ "$authorities" = "yes" ]; then
172 if ! run_rebuild_zebra $name \
173 -a $opt_verbose $opt_idx $opts_other ; then
174 warn "Something went wrong rebuilding authority indexes for $name"
177 else
178 warn "Unknown instance $name."
180 done
182 exit 0