V8.02.512.2025.05.30
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
60
lib/lib_debug.sh
Normal file
60
lib/lib_debug.sh
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
# SPDX-Version: 3.0
|
||||
# SPDX-CreationInfo: 2025-05-05; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.live.builder.git
|
||||
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
|
||||
# SPDX-FileCopyrightText: 2024–2025; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-FileType: SOURCE
|
||||
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
|
||||
# SPDX-LicenseComment: This file is part of the CISS.hardened.installer framework.
|
||||
# SPDX-PackageName: CISS.debian.live.builder
|
||||
# SPDX-Security-Contact: security@coresecret.eu
|
||||
|
||||
#######################################
|
||||
# Debugger Wrapper for xtrace to Debug Log
|
||||
# Globals:
|
||||
# BASH_XTRACEFD
|
||||
# DEBUG_LOG
|
||||
# EARLY_DEBUG
|
||||
# PS4
|
||||
# SHELLOPTS
|
||||
# dump_vars_initial
|
||||
# var
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
debugger() {
|
||||
### Capture an initial snapshot of all variables (excluding '^(BASH|_).*')
|
||||
# shellcheck disable=SC2155
|
||||
declare -grx dump_vars_initial=$(mktemp)
|
||||
{
|
||||
declare var
|
||||
while IFS= read -r var; do
|
||||
declare -p "${var}" 2>/dev/null
|
||||
done < <(compgen -v | grep -Ev '^(BASH|_).*')
|
||||
} | sort >| "${dump_vars_initial}"
|
||||
declare -grx EARLY_DEBUG=true
|
||||
### Set a verbose PS4 prompt including timestamp, source, line, exit status, and function name
|
||||
declare -grx PS4='\e[97m+\e[0m\e[96m$(date +%T.%4N)\e[0m\e[97m:\e[0m\e[92m[${BASH_SOURCE[0]}:${LINENO}]\e[0m\e[97m|\e[0m\e[93m${?}\e[0m\e[97m>\e[0m\e[95m${FUNCNAME[0]:-main}()\e[0m \e[97m>>\e[0m '
|
||||
# shellcheck disable=SC2155
|
||||
declare -grx DEBUG_LOG="/tmp/ciss_live_builder_$$_debug.log"
|
||||
### Generates empty DEBUG_LOG
|
||||
touch "${DEBUG_LOG}" && chmod 0600 "${DEBUG_LOG}"
|
||||
### Open file descriptor 42 for writing to the debug log
|
||||
exec 42>| "${DEBUG_LOG}"
|
||||
### Write Debug Log Header https://www.gnu.org/software/bash/manual/html_node/Bash-Variables
|
||||
### Determine the directory of this script, even if sourced.
|
||||
# shellcheck disable=SC2155
|
||||
declare script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
### Source the header from the same directory. This ensures we always load lib/lib_debug_header.sh correctly.
|
||||
. "${script_dir}/lib_debug_header.sh"
|
||||
# shellcheck disable=SC2119
|
||||
debug_header "$#" "$*"
|
||||
### Tell Bash to send xtrace output to FD 42
|
||||
export BASH_XTRACEFD=42
|
||||
### Enable inheritable shell options
|
||||
export SHELLOPTS
|
||||
### Turn on xtrace
|
||||
set -x
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
Reference in New Issue
Block a user