From 7e4554cf705c243c526eb94aef73cebabcc6b45a Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Eugenio Halili Date: Sun, 29 Aug 2021 21:36:14 +0800 Subject: [PATCH] Move entrypoint script to common/bin directory Also, finalized stuff, KEK. --- tests/common/bin/logger.sh | 19 +++++++++++++++++++ tests/ubuntu/bin/logger.sh | 7 ------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 tests/common/bin/logger.sh delete mode 100644 tests/ubuntu/bin/logger.sh diff --git a/tests/common/bin/logger.sh b/tests/common/bin/logger.sh new file mode 100644 index 0000000..c861d0e --- /dev/null +++ b/tests/common/bin/logger.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +LOGGER_TARGET_FILE="/var/tests/exec-log.txt" + +if [[ $LOG_EVERYTHING == "" || $LOG_EVERYTHING == "false" ]]; then + exec "$@" +fi + +# based on https://gitlab.com/friendly-telegram/friendly-telegram/-/blob/master/install.sh#L43-49, but a bit modified +# for our use case +log() { + # Runs the arguments and spins once per line of stdout (tee'd to logfile), also piping stderr to logfile + { "$@" 2>>$LOGGER_TARGET_FILE || return $?; } | while read -r line; do + spin + printf "%s\n" "$line" >> $LOGGER_TARGET_FILE + done +} + +log "$@" diff --git a/tests/ubuntu/bin/logger.sh b/tests/ubuntu/bin/logger.sh deleted file mode 100644 index 06e5a35..0000000 --- a/tests/ubuntu/bin/logger.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -LOGGER_TARGET_FILE="/var/tests/exec-log.txt" - -if [[ $LOG_EVERYTHING == "" || $LOG_EVERYTHING == "false" ]]; then - exec "$@" -fi