File: run_null.sh

package info (click to toggle)
mmdebstrap 1.5.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,724 kB
  • sloc: perl: 6,092; sh: 4,497; python: 1,269; makefile: 22
file content (50 lines) | stat: -rwxr-xr-x 970 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh

set -eu

SUDO=
while [ "$#" -gt 0 ]; do
  key="$1"
  case "$key" in
    SUDO)
      SUDO="sudo --preserve-env"
      ;;
    *)
      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>&-
          # shellcheck disable=SC2086
          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