summaryrefslogtreecommitdiffstats
path: root/run_null.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
commitee17e45964b786b48b455959dfe68715971893fb (patch)
tree118f40aa65dc838499053413b05adfd00f839c62 /run_null.sh
parentInitial commit. (diff)
downloadmmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.tar.xz
mmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.zip
Adding upstream version 1.4.3.upstream/1.4.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'run_null.sh')
-rwxr-xr-xrun_null.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/run_null.sh b/run_null.sh
new file mode 100755
index 0000000..17b42fa
--- /dev/null
+++ b/run_null.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+set -eu
+
+SUDO=
+while [ "$#" -gt 0 ]; do
+ key="$1"
+ case "$key" in
+ SUDO)
+ SUDO=sudo
+ ;;
+ *)
+ echo "Unknown argument: $key"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# - Run command with fds 3 and 4 closed so that whatever test.sh does it
+# cannot interfere with these.
+# - Both stdin and stderr of test.sh are written to stdout
+# - Write exit status of test.sh to fd 3
+# - Write stdout to shared/output.txt as well as to fd 4
+# - Redirect fd 3 to stdout
+# - Read fd 3 and let the group exit with that value
+# - Redirect fd 4 to stdout
+ret=0
+{ { { {
+ ret=0;
+ ( exec 3>&- 4>&-; env --chdir=./shared $SUDO sh -x ./test.sh 2>&1) || ret=$?;
+ echo $ret >&3;
+ } | tee shared/output.txt >&4;
+ } 3>&1;
+ } | { read -r xs; exit "$xs"; }
+} 4>&1 || ret=$?
+if [ "$ret" -ne 0 ]; then
+ echo "test.sh failed"
+ exit 1
+fi