Bug 20267: .gitignore do not need to be mapped in Makefile
[koha.git] / debian / scripts / koha-rebuild-zebra
blob6c0fce38835a4054d722a3cb39d7728c21f88d00
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 if [ "$DEV_INSTALL" = "" ]; then
60 KOHA_BINDIR=$KOHA_HOME/bin
61 else
62 KOHA_BINDIR=$KOHA_HOME/misc
65 # TODO: This comment is here to remind us that we should make
66 # rebuild_zebra.pl return error codes on failure
67 if sudo -u "$instancename-koha" -H \
68 env PERL5LIB=$PERL5LIB \
69 KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
70 $KOHA_BINDIR/migration_tools/rebuild_zebra.pl $@ ; then
71 return 0
72 else
73 return 1
78 usage()
80 local scriptname=$0
81 cat <<EOF
82 Rebuild the Zebra indexes for Koha instances. The default behaviour
83 is to do an incremental rebuild.
85 Usage: $scriptname [options] instancename1 instancename2...
86 Options:
87 --authorities|-a Only run process for authorities.
88 --biblios|-b Only run process for biblios.
89 --full|-f Does a reindex of the whole collection.
90 --force Run incremental indexing even if USE_INDEXER_DAEMON="yes"
91 --quiet|-q Sometimes be a bit quieter for scripts/cronjobs.
92 --verbose|-v Be verbose.
93 --help|-h Print this help.
96 Note: Any other options are passed directly to rebuild_zebra.pl.
97 EOF
100 # Default parameters
101 opt_idx="-z"
102 opt_verbose=""
103 opts_other=""
104 biblios_only="no"
105 authorities_only="no"
106 biblios="yes"
107 authorities="yes"
108 force="no"
109 full_reindex="no"
111 # The '-q' option is intended to prevent the cronjob causing this to output
112 # help information if there are no instances defined.
113 quiet="no"
115 # Read parameters
116 while [ -n "$*" ]; do
117 case "$1" in
118 -h|--help)
119 usage ; exit 0
121 -b|--biblios)
122 toggle_biblios_only
124 -a|--authorities)
125 toggle_authorities_only
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 # Optionally use alternative paths for a dev install
152 adjust_paths_dev_install $1
154 # Parse command line.
155 if [ $# -lt 1 ]; then
156 if [ "$quiet" = "no" ]; then
157 usage
158 die "Missing instance name."
159 else
160 exit
164 # Loop over instance names
165 for name in "$@"
167 if is_instance $name; then
168 if [ "$biblios" = "yes" ]; then
169 if ! run_rebuild_zebra $name \
170 -b $opt_verbose $opt_idx $opts_other; then
171 warn "Something went wrong rebuilding biblio indexes for $name"
174 if [ "$authorities" = "yes" ]; then
175 if ! run_rebuild_zebra $name \
176 -a $opt_verbose $opt_idx $opts_other ; then
177 warn "Something went wrong rebuilding authority indexes for $name"
180 else
181 warn "Unknown instance $name."
183 done
185 exit 0