-
Notifications
You must be signed in to change notification settings - Fork 6
/
liquid
executable file
·37 lines (28 loc) · 1.08 KB
/
liquid
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
#!/bin/bash
set -e
set -o pipefail
if [ "$EUID" -eq 0 ]; then
echo "ERROR: do NOT run script as the root user." >&2
exit 1
fi
# cd to file
cd "$(dirname ${BASH_SOURCE[0]})"
# create and truncate logfiles for subcommand
first_arg="$1"
logfile_out=".logs/$1.stdout"
logfile_err=".logs/$1.stderr"
mkdir -p ./.logs
echo "" > "$logfile_out"
echo "" > "$logfile_err"
if [[ "$1" == "dockerexec" ]]; then
# The "dockerexec" command should not be logged to file, since it is used in
# other commands as data input/output pipe.
( set -x; pipenv run ./liquid.py "$@" )
else
# Log stdout and stderr from the command in separate files.
# Need to swap stdin with stdout, because tee only takes stdin as input,
# and then finally, swap it back, so our dump/restore commands
# that use `./liquid dockerexec` will still work.
# https://unix.stackexchange.com/questions/6430/how-to-redirect-stderr-and-stdout-to-different-files-and-also-display-in-termina/6431#6431
( ( ( set -x; pipenv run ./liquid.py "$@" ) | tee "$logfile_out" ) 3>&1 1>&2 2>&3 | tee "$logfile_err" ) 3>&1 1>&2 2>&3
fi