From 775cd6c6198f629e4a46f7503dc17f1a6184ce31 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 9 Oct 2022 17:17:31 +0200 Subject: [PATCH] armbian-next: logging: don't bomb due to lack of `git` or `zstdmt` - logging might run super early when dependencies are not installed - or say in a container, without git --- lib/functions/logging/logging.sh | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/functions/logging/logging.sh b/lib/functions/logging/logging.sh index 6590224b5..d9ff7026e 100644 --- a/lib/functions/logging/logging.sh +++ b/lib/functions/logging/logging.sh @@ -293,17 +293,26 @@ function export_ansi_logs() { ---------------------------------------------------------------------------------------------------------------- # ARGs: ${ARMBIAN_ORIGINAL_ARGV[@]@Q} ---------------------------------------------------------------------------------------------------------------- - # Last revision: - $(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --color --format=short --decorate) - ---------------------------------------------------------------------------------------------------------------- - # Git status: - $(LC_ALL=C LANG=C git -c color.status=always --work-tree="${SRC}" --git-dir="${SRC}/.git" status) - ---------------------------------------------------------------------------------------------------------------- - # Git changes: - $(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u --color) - ---------------------------------------------------------------------------------------------------------------- ANSI_HEADER + if [[ -n "$(command -v git)" ]]; then + display_alert "Gathering git info for logs" "Processing git information, please wait..." "debug" + cat <<- GIT_ANSI_HEADER > "${target_file}" + ---------------------------------------------------------------------------------------------------------------- + # Last revision: + $(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --color --format=short --decorate) + ---------------------------------------------------------------------------------------------------------------- + # Git status: + $(LC_ALL=C LANG=C git -c color.status=always --work-tree="${SRC}" --git-dir="${SRC}/.git" status) + ---------------------------------------------------------------------------------------------------------------- + # Git changes: + $(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u --color) + ---------------------------------------------------------------------------------------------------------------- + GIT_ANSI_HEADER + fi + + display_alert "Preparing ANSI logs..." "Processing log files..." "debug" + # Find and sort the files there, store in array one per logfile declare -a logfiles_array mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | LC_ALL=C sort -h) @@ -405,8 +414,14 @@ function trap_handler_cleanup_logging() { old_logfile_fn="$(basename "${one_old_logfile}")" display_alert "Archiving old logfile" "${old_logfile_fn}" "debug" mkdir -p "${target_archive_path}" - # shellcheck disable=SC2002 # my cat is not useless. a bit whiny. not useless. - zstdmt --quiet "${one_old_logfile}" -o "${target_archive_path}/${old_logfile_fn}.zst" + + # Check if we have `zstdmt` at this stage; if not, use standard gzip + if [[ -n "$(command -v zstdmt)" ]]; then + zstdmt --quiet "${one_old_logfile}" -o "${target_archive_path}/${old_logfile_fn}.zst" + else + # shellcheck disable=SC2002 # my cat is not useless. a bit whiny. not useless. + cat "${one_old_logfile}" | gzip > "${target_archive_path}/${old_logfile_fn}.gz" + fi rm -f "${one_old_logfile}" done fi