Improve DEBUG and DO_WITH_DEBUG output handling to also keep output of kexec -l when BOARD is in DEBUG+TRACE mode (configuration settings menu + flash)

Signed-off-by: Thierry Laurion <insurgo@riseup.net>
This commit is contained in:
Thierry Laurion
2024-04-18 12:21:27 -04:00
parent 82179e4e98
commit ae5f9c5416
4 changed files with 26 additions and 14 deletions

View File

@ -151,7 +151,7 @@ if [ "$dryrun" = "y" ]; then exit 0; fi
echo "Loading the new kernel:"
echo "$kexeccmd"
eval "$kexeccmd" \
DO_WITH_DEBUG "$kexeccmd" \
|| die "Failed to load the new kernel"
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ];then

View File

@ -61,6 +61,7 @@ if [ "$unseal_failed" = "y" ]; then
-n 1 \
-p "Do you wish to boot and use the LUKS Disk Recovery Key? [Y/n] " \
confirm_boot
echo
if [ "$confirm_boot" != 'y' \
-a "$confirm_boot" != 'Y' \

View File

@ -24,7 +24,8 @@ warn() {
DEBUG() {
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
echo "DEBUG: $*" | while read line; do
# fold -s -w 960 will wrap lines at 960 characters on the last space before the limit
echo "DEBUG: $*" | fold -s -w 960 | while read line; do
echo "$line" | tee -a /tmp/debug.log /dev/kmsg >/dev/null
done
fi

View File

@ -19,18 +19,28 @@ mask_param() {
# N=0 is the name of the command to be executed, N=1 is its first parameter,
# etc.
DO_WITH_DEBUG() {
if [ "$1" == "--mask-position" ]; then
mask_position="$2"
local exit_status
local cmd_output
DEBUG "PATH: $PATH"
local cmd=("$@")
if [[ "$1" == "--mask-position" ]]; then
local mask_position="$2"
shift
shift
DEBUG_ARGS=("$@")
DEBUG_ARGS[$mask_position]="$(mask_param "${DEBUG_ARGS[$mask_position]}")"
DEBUG "${DEBUG_ARGS[@]}"
else
DEBUG "$@"
cmd=("$@")
cmd[$mask_position]="$(mask_param "${cmd[$mask_position]}")"
fi
"$@"
if [[ ${#cmd[@]} -eq 1 ]]; then
# If there's only one argument, try to split it into multiple arguments
read -a cmd <<< "${cmd[0]}"
fi
DEBUG "Executing command with cmd: ${cmd[*]}"
# Sanitize the command output by removing special characters
cmd_output=$("${cmd[@]}" 2>&1 | sed 's/[&;|`$(){}<>]//g')
exit_status=$?
DEBUG "Command output: $cmd_output"
DEBUG "Command exited with status: $exit_status"
return $exit_status
}
# Trace the current script and function.
@ -682,7 +692,7 @@ scan_boot_options() {
if [ -r $option_file ]; then rm $option_file; fi
for i in $(find $bootdir -name "$config"); do
DO_WITH_DEBUG kexec-parse-boot "$bootdir" "$i" >>$option_file
kexec-parse-boot "$bootdir" "$i" >>$option_file
done
# FC29/30+ may use BLS format grub config files
# https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault