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() {
|
get_command() {
|
||||||
jq -r '.params.command // ["true"]' < "$INPUT_PATH" | jq -r '.[]' | tr '\n"' " '"
|
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)"
|
HOSTNAME="$(get_hostname)"
|
||||||
PORT="$(get_port)"
|
PORT="$(get_port)"
|
||||||
USER="$(get_user)"
|
USER="$(get_user)"
|
||||||
|
@ -78,6 +85,8 @@ DIRECTORY="$(get_directory)"
|
||||||
WORKDIR="$(get_workdir)"
|
WORKDIR="$(get_workdir)"
|
||||||
VERSION="$(get_version)"
|
VERSION="$(get_version)"
|
||||||
COMMAND="$(get_command)"
|
COMMAND="$(get_command)"
|
||||||
|
STDERR_FILE="$(get_stderr_file)"
|
||||||
|
STDOUT_FILE="$(get_stdout_file)"
|
||||||
|
|
||||||
export HOSTNAME
|
export HOSTNAME
|
||||||
export PORT
|
export PORT
|
||||||
|
@ -89,6 +98,8 @@ export DIRECTORY
|
||||||
export WORKDIR
|
export WORKDIR
|
||||||
export VERSION
|
export VERSION
|
||||||
export COMMAND
|
export COMMAND
|
||||||
|
export STDERR_FILE
|
||||||
|
export STDOUT_FILE
|
||||||
|
|
||||||
write_config() {
|
write_config() {
|
||||||
config="$(tmpfile)"
|
config="$(tmpfile)"
|
||||||
|
|
|
@ -8,13 +8,35 @@ directory="${DIRECTORY}"
|
||||||
workdir="${WORKDIR}"
|
workdir="${WORKDIR}"
|
||||||
# shellcheck disable=SC2153
|
# shellcheck disable=SC2153
|
||||||
extract="${EXTRACT}"
|
extract="${EXTRACT}"
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
stderr_file="${STDERR_FILE}"
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
stdout_file="${STDOUT_FILE}"
|
||||||
|
|
||||||
(
|
(
|
||||||
if "$extract"; then
|
if "$extract"; then
|
||||||
cd "$directory"
|
cd "$directory"
|
||||||
tar x
|
tar x
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
cd "$workdir"
|
cd "$workdir"
|
||||||
${COMMAND} >&2
|
[ "$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}
|
${EXTRACT}
|
||||||
${WORKDIR}
|
${WORKDIR}
|
||||||
${COMMAND}
|
${COMMAND}
|
||||||
|
${STDERR_FILE}
|
||||||
|
${STDOUT_FILE}
|
||||||
|
|
Loading…
Reference in a new issue