#!/bin/sh # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set -e # Read configuration variable file if it is present [ -r /etc/default/koha-common ] && . /etc/default/koha-common # include helper functions if [ -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 exit 1 fi usage() { local scriptname=$0 cat </dev/null; then commit_size=${clo_commit_size} fi rebuild_opts="--commit ${commit_size}" if [ "${clo_processes}" -gt 0 ] 2>/dev/null; then processes=${clo_processes} fi rebuild_opts="${rebuild_opts} --processes ${processes}" if [ "${delete}" = "yes" ]; then rebuild_opts="${rebuild_opts} -d" fi if [ "${reset}" = "yes" ]; then rebuild_opts="${rebuild_opts} -r" fi if [ "${biblios}" = "yes" ]; then rebuild_opts="${rebuild_opts} -b" fi if [ "${authorities}" = "yes" ]; then rebuild_opts="${rebuild_opts} -a" fi if [ "${verbose}" = "yes" ]; then rebuild_opts="${rebuild_opts} -v" fi if [ "${where}" ]; then rebuild_opts="${rebuild_opts} --where \"${where}\"" fi # KOHA_HOME and KOHA_BINDIR may have been adjusted/set by adjust_paths_git_install if koha-shell \ -c "${KOHA_HOME}/${KOHA_BINDIR}/search_tools/rebuild_elasticsearch.pl ${rebuild_opts}" \ ${name}; then return 0 else return 1 fi } # Default parameters from koha-common.default biblios=$ES_INDEX_BIBLIOS # the 'only' variants are skipped because they don't actually control authorities=$ES_INDEX_AUTHORITIES # anything and are just for setting stuff internally. commit_size=$ES_COMMIT_SIZE processes=$ES_NUMBER_OF_PROCESSES verbose=$ES_VERBOSE where=$ES_WHERE_QUERY_SQL # Default parameters if all else fails : ${biblios:="yes"} : ${authorities:="yes"} : ${commit_size:=5000} : ${processes:=1} : ${verbose:="no"} : ${where:=""} biblios_only="no" authorities_only="no" op="" # Read parameters while [ -n "$*" ]; do case "$1" in -h|--help) usage ; exit 0 ;; -d|--delete) delete="yes" ;; -r|--reset) reset="yes" ;; -b|--biblios) toggle_biblios_only ;; -a|--authorities) toggle_authorities_only ;; -c|--commit) clo_commit_size="$2" ; shift ;; -p|--processes) clo_processes="$2" ; shift ;; -w|--where) where="$2" ; shift ;; --rebuild) set_action "rebuild" ;; -v|--verbose) verbose="yes" ;; *) break ;; esac shift done # Parse command line. if [ $# -lt 1 ]; then usage die "Missing instance name." fi # Loop over instance names for name in "$@" do if is_instance $name; then adjust_paths_git_install $name if [ "${op}" = "rebuild" ]; then if ! run_rebuild_elasticsearch $name; then warn "Something went wrong rebuilding indexes for ${name}" fi else # TODO: Add other actions, status? etc usage die "Error: no action passed" fi else warn "Unknown instance ${name}" fi done exit 0