Allow writing of logfiles instead of all to stderr.

This commit is contained in:
redxef 2022-11-21 23:59:23 +01:00
parent 60d235765d
commit c9d4d151ac
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
3 changed files with 41 additions and 6 deletions

View file

@ -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)"

View file

@ -8,6 +8,11 @@ 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"
@ -16,5 +21,22 @@ extract="${EXTRACT}"
)
(
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
)

View file

@ -2,3 +2,5 @@ ${DIRECTORY}
${EXTRACT}
${WORKDIR}
${COMMAND}
${STDERR_FILE}
${STDOUT_FILE}