From 392edc1a2fe1f84f94b03bd569a10adb60dbc6fe Mon Sep 17 00:00:00 2001 From: Evan Giles Date: Fri, 1 Sep 2023 18:42:45 +1200 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi (cherry picked from commit d9849aaa3aa777072c846526c772a896b5424cfb) Signed-off-by: Fridolin Somers --- debian/scripts/koha-foreach | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/debian/scripts/koha-foreach b/debian/scripts/koha-foreach index d2e98dd7de..66f8757d4f 100755 --- a/debian/scripts/koha-foreach +++ b/debian/scripts/koha-foreach @@ -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 -- 2.39.5