diff --git a/mender-convert b/mender-convert index 38e46e8..9ebc885 100755 --- a/mender-convert +++ b/mender-convert @@ -44,6 +44,12 @@ function show_version() { } function trap_exit() { + EXIT_CODE=$? + if [[ ${EXIT_CODE} -ne 0 && ${EXIT_CODE} -ne ${FATAL_EXIT_CODE} ]]; then + log_error "mender-convert failed" + tac work/convert.log | sed '/DEBUG/q' | tac | sed 's/Running/When running/' + log_error "mender-convert exit code: ${EXIT_CODE}" + fi sudo rm -rf work } diff --git a/mender-convert-extract b/mender-convert-extract index b1fc92f..3981368 100755 --- a/mender-convert-extract +++ b/mender-convert-extract @@ -14,6 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +function trap_exit() { + echo "mender-convert-extract has finished. Cleaning up..." +} + +function trap_term() { + true +} + +trap trap_term INT TERM +trap trap_exit EXIT + echo "Running $(basename $0): $@" source modules/bootstrap.sh diff --git a/modules/log.sh b/modules/log.sh index d065509..e22c577 100644 --- a/modules/log.sh +++ b/modules/log.sh @@ -68,8 +68,9 @@ function log_error { } # Log the given message at FATAL level. +FATAL_EXIT_CODE=90 function log_fatal { local -r message="$1" log "${IRED}FATAL${NC}" "$message" - exit 1 + exit ${FATAL_EXIT_CODE} } diff --git a/modules/run.sh b/modules/run.sh index 6a1a618..d430470 100644 --- a/modules/run.sh +++ b/modules/run.sh @@ -19,10 +19,15 @@ # $1 - command to run function run_and_log_cmd() { local -r cmd="${1}" - - log_debug "Running: \n\r\n\r\t ${cmd}" - log_debug "Run result: \n\r" - - result=$(eval ${cmd}) - log_debug "${result}" + local -r position="(${BASH_SOURCE[1]}:${BASH_LINENO[0]}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }" + local exit_code=0 + output="$({ eval ${cmd}; } 2>&1)" || exit_code=$? + local log_msg="Running: ${position} \n\r\n\r\t${cmd}" + if [[ "${output}" != "" ]]; then + log_msg="${log_msg}\n\t${output}\n" + fi + log_debug "${log_msg}" + if [[ ${exit_code} -ne 0 ]]; then + exit ${exit_code} + fi }