Allow writing of logfiles instead of all to stderr.
This commit is contained in:
parent
60d235765d
commit
c9d4d151ac
3 changed files with 41 additions and 6 deletions
11
src/common
11
src/common
|
@ -68,6 +68,13 @@ get_version() {
|
|||
get_command() {
|
||||
jq -r '.params.command // ["true"]' < "$INPUT_PATH" | jq -r '.[]' | tr '\n"' " '"
|
||||
}
|
||||
get_stdout_file() {
|
||||
jq -r '.params.stderr_file // "-"' | jq -r tostring
|
||||
}
|
||||
get_stdout_file() {
|
||||
jq -r '.params.stdout_file // "-"' | jq -r tostring
|
||||
}
|
||||
|
||||
HOSTNAME="$(get_hostname)"
|
||||
PORT="$(get_port)"
|
||||
USER="$(get_user)"
|
||||
|
@ -78,6 +85,8 @@ DIRECTORY="$(get_directory)"
|
|||
WORKDIR="$(get_workdir)"
|
||||
VERSION="$(get_version)"
|
||||
COMMAND="$(get_command)"
|
||||
STDERR_FILE="$(get_stderr_file)"
|
||||
STDOUT_FILE="$(get_stdout_file)"
|
||||
|
||||
export HOSTNAME
|
||||
export PORT
|
||||
|
@ -89,6 +98,8 @@ export DIRECTORY
|
|||
export WORKDIR
|
||||
export VERSION
|
||||
export COMMAND
|
||||
export STDERR_FILE
|
||||
export STDOUT_FILE
|
||||
|
||||
write_config() {
|
||||
config="$(tmpfile)"
|
||||
|
|
|
@ -8,13 +8,35 @@ directory="${DIRECTORY}"
|
|||
workdir="${WORKDIR}"
|
||||
# shellcheck disable=SC2153
|
||||
extract="${EXTRACT}"
|
||||
# shellcheck disable=SC2153
|
||||
stderr_file="${STDERR_FILE}"
|
||||
# shellcheck disable=SC2153
|
||||
stdout_file="${STDOUT_FILE}"
|
||||
|
||||
(
|
||||
if "$extract"; then
|
||||
cd "$directory"
|
||||
tar x
|
||||
fi
|
||||
if "$extract"; then
|
||||
cd "$directory"
|
||||
tar x
|
||||
fi
|
||||
)
|
||||
(
|
||||
cd "$workdir"
|
||||
${COMMAND} >&2
|
||||
cd "$workdir"
|
||||
[ "$stderr_file" != "-" ] && truncate -s 0 "$stderr_file"
|
||||
[ "$stdout_file" != "-" ] && truncate -s 0 "$stdout_file"
|
||||
|
||||
# don't write anything to stdout, since that would get appended to the tar file
|
||||
if [ "$stderr_file" = "-" ] && [ "$stdout_file" = "-" ]; then
|
||||
# redirect stdout to stderr
|
||||
${COMMAND} 1>&2
|
||||
elif [ "$stderr_file" != "-" ] && [ "$stdout_file" = "-" ]; then
|
||||
# stderr to file, stdout to stderr
|
||||
( ${COMMAND} 2>"$stderr_file" ) 1>&2
|
||||
|
||||
elif [ "$stderr_file" = "-" ] && [ "$stdout_file" != "-" ]; then
|
||||
# stdout to file
|
||||
${COMMAND} 1>"$stdout_file"
|
||||
else
|
||||
# both files specified
|
||||
${COMMAND} 1>"$stdout_file" 2>"$stderr_file"
|
||||
fi
|
||||
)
|
||||
|
|
|
@ -2,3 +2,5 @@ ${DIRECTORY}
|
|||
${EXTRACT}
|
||||
${WORKDIR}
|
||||
${COMMAND}
|
||||
${STDERR_FILE}
|
||||
${STDOUT_FILE}
|
||||
|
|
Loading…
Reference in a new issue