Bug 25634: Warn if koha-shell returns non-zero in koha-foreach
authorDavid Cook <dcook@prosentient.com.au>
Mon, 1 Jun 2020 23:53:06 +0000 (09:53 +1000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 12 Jun 2020 08:32:30 +0000 (10:32 +0200)
By putting koha-shell in an if statement, "set -e" will no longer
cause the entire koha-foreach program to exit, if koha-shell
returns a non-zero status.

If a non-zero status is returned, we warn on it, and the caller
of koha-foreach can interpret that command visually.

To Test:
1) Write a shell script that says "Hello" and then exits with a 1
status
2) Run koha-foreach against that shell script with multiple instances
available to koha-foreach
3) Before the patch, koha-foreach will die after the first "Hello"
4) After the patch, koha-foreach will continue, through all the
instances, and report which instances returned non-zero statuses
by which command.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

debian/scripts/koha-foreach

index 9682f14..2f5a150 100755 (executable)
@@ -61,7 +61,12 @@ do
         # Change to the instance's home dir if required
         [ "$chdir" != "no" ] && eval cd ~$name"-koha"
 
-        koha-shell ${name} -c "${cmd}"
+        if koha-shell ${name} -c "${cmd}"; then
+            : #noop
+        else
+            rv=$?
+            echo "${name}: $rv status returned by \"${cmd}\""
+        fi
 
         # Go back to the original dir if required
         [ "$chdir" != "no" ] && cd "$starting_dir"