From 6b205dcac7f772067d2ba9ae7b3334866d098aa0 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 22 Jun 2025 11:12:09 -0600 Subject: [PATCH] common: Add exit code functions --- usr/local/share/bastille/common.sh | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 1c6cb512..7c51afa3 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -93,6 +93,37 @@ warn() { echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" } +# This function checks and adds any error code +# that is not "0" to the tmp file +bastille_check_exit_code() { + + local jail="${1}" + local exit_code="${2}" + + # Set exit code variable + if [ -z "${TMP_BASTILLE_EXIT_CODE}" ]; then + error_exit "[ERROR]: Exit code status not set." + else + local old_exit_code="$(cat ${TMP_BASTILLE_EXIT_CODE})" + fi + + if [ "${exit_code}" -ne 0 ]; then + local new_exit_code="$(( ${old_exit_code} + ${exit_code} ))" + echo "${new_exit_code}" > "${TMP_BASTILLE_EXIT_CODE}" + error_notify "[ERROR CODE]: ${exit_code}" + fi +} + +# This needs to be the last function called +# if used on any command +bastille_print_exit_code() { + + local exit_code="$(cat ${TMP_BASTILLE_EXIT_CODE})" + + rm -f ${TMP_BASTILLE_EXIT_CODE} + return "${exit_code}" +} + # Parallel mode, don't exceed process limit bastille_running_jobs() {