Tomas Cohen Arazi
75994dc94a
This patch simplifies the koha-foreach script, making it use koha-shell to gain instance privileges and have all environment variables set. To test: - Apply the patch - Have one or more instances created (kohadev already exists in kohadevbox, add another onewith $ sudo koha-create --create-db test) - Run: $ sudo kohaclone/debian/scripts/koha-foreach echo "This is instance __instancename__" => SUCCESS: The script runs gracefuly, and outputs something like: This is instance kohadev This is instance test Note: this means the command was executed for each instance and the current behaviour of replacing the placeholder __instancename__ for the actual instance name still works as expected. - You can try the different filter switches, but the logic has not been touched. only the command call. - Sign off :-D Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
58 lines
1.9 KiB
Bash
Executable file
58 lines
1.9 KiB
Bash
Executable file
#!/bin/sh
|
|
# koha-foreach -- run a command for each Koha instance
|
|
# Copyright 2010 Catalyst IT, Ltd
|
|
#
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
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
|
|
|
|
listopts=""
|
|
while [ ! -z "$1" ]
|
|
do
|
|
case "$1" in
|
|
--email) listopts="$listopts --email";;
|
|
--noemail) listopts="$listopts --noemail";;
|
|
--enabled) listopts="$listopts --enabled";;
|
|
--disabled) listopts="$listopts --disabled";;
|
|
--sip) listopts="$listopts --sip";;
|
|
--nosip) listopts="$listopts --nosip";;
|
|
--plack) listopts="$listopts --plack";;
|
|
--noplack) listopts="$listopts --noplack";;
|
|
--letsencrypt) listopts="$listopts --letsencrypt" ;;
|
|
--noletsencrypt) listopts="$listopts --noletsencrypt" ;;
|
|
*) break;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
for name in $(koha-list $listopts)
|
|
do
|
|
# Replace the __instancename__ placeholder for the instance name (Bug 8566)
|
|
cmd=`echo "$@" | sed -e s/__instancename__/${name}/g`
|
|
|
|
if [ "${cmd}" != "" ]; then
|
|
koha-shell ${name} -c "${cmd}"
|
|
fi
|
|
done
|