Skip to content

Commit

Permalink
Bug 18709: Make koha-foreach use koha-shell internally
Browse files Browse the repository at this point in the history
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 <[email protected]>

Signed-off-by: Nick Clemens <[email protected]>

Signed-off-by: Jonathan Druart <[email protected]>
(cherry picked from commit 75994dc)
Signed-off-by: Fridolin Somers <[email protected]>
  • Loading branch information
tomascohen authored and fridobox committed Apr 10, 2018
1 parent 6e58877 commit d6367c4
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions debian/scripts/koha-foreach
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,13 @@ do
esac
shift
done

for name in $(koha-list $listopts)
do
# Optionally use alternative paths for a dev install
adjust_paths_dev_install $name

# Replace the __instancename__ placeholder for the instance name (Bug 8566)
cmd=`echo "$@" | sed -e s/__instancename__/${name}/g`
(
exec 3>&1
sudo -u "$name-koha" \
env PERL5LIB=$PERL5LIB \
KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
${cmd} 2>&1 >&3 | sed -e "s/^/$name: /" >&2 3>&-
exec 3>&-
) | sed -e "s/^/$name: /"

if [ "${cmd}" != "" ]; then
koha-shell ${name} -c "${cmd}"
fi
done

0 comments on commit d6367c4

Please sign in to comment.