Bug 34653: Make koha-foreach return the correct status code

I think the correct behavior for this script should be that koha-foreach
will return 0 (success) if all the commands it tried to run succeeded, but
1 (failure) if any of the commands failed.

To test:
1. $ koha-create --create-db test
2. $ vi test.sh
if [ $USER = 'kohadev-koha' ]; then
    echo "FAILED";
    exit 1;
else
    echo "SUCCESS";
    exit 0;
fi

3. $ debian/scripts/koha-foreach sh test.sh
FAILED
kohadev: 1 status returned by "sh test.sh"
SUCCESS
4. $ echo $?
5. Note that the exit status is 0 (success)

6. Apply patch

7. $ debian/scripts/koha-foreach sh test.sh
FAILED
kohadev: 1 status returned by "sh test.sh"
SUCCESS
8. $ echo $?
9. Note that the exit status is 1 (failure)

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit d9849aaa3a)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Evan Giles 2023-09-01 18:42:45 +12:00 committed by Fridolin Somers
parent 6dbd5e5fdb
commit 392edc1a2f

View file

@ -51,6 +51,7 @@ do
shift
done
rv=0
for name in $(koha-list $listopts)
do
# Replace the __instancename__ placeholder for the instance name (Bug 8566)
@ -64,8 +65,8 @@ do
if koha-shell ${name} -c "${cmd}"; then
: #noop
else
rv=$?
echo "${name}: $rv status returned by \"${cmd}\""
echo "${name}: $? status returned by \"${cmd}\""
rv=1
fi
# Go back to the original dir if required
@ -73,4 +74,4 @@ do
fi
done
exit 0
exit $rv