Skip to content

Commit

Permalink
Merge pull request #1601 from tlaurion/switch_TRACE_to_TRACE_FUNC_eve…
Browse files Browse the repository at this point in the history
…rywhere_possible

all scripts: replace TRACE manual strings with dynamic tracing by bash debug
  • Loading branch information
tlaurion authored Feb 1, 2024
2 parents 5a75e6b + 40c3445 commit 5bff519
Show file tree
Hide file tree
Showing 43 changed files with 167 additions and 146 deletions.
2 changes: 1 addition & 1 deletion initrd/bin/cbfs-init
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e -o pipefail
. /etc/functions

TRACE "Under /bin/cbfs-init"
TRACE_FUNC

# Update initrd with CBFS files
if [ -z "$CONFIG_PCR" ]; then
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/cbfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e -o pipefail
. /etc/functions
. /tmp/config

TRACE "Under /bin/cbfs.sh"
TRACE_FUNC

if pnor "$2" -r HBI > /tmp/pnor.part 2>/dev/null; then
cbfs "$@" -o /tmp/pnor.part && pnor "$2" -w HBI < /tmp/pnor.part
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/config-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e -o pipefail
. /etc/gui_functions
. /tmp/config

TRACE "Under /bin/config-gui.sh"
TRACE_FUNC

ROOT_HASH_FILE="/boot/kexec_root_hashes.txt"

Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/flash-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e -o pipefail
. /etc/gui_functions
. /tmp/config

TRACE "Under /bin/flash-gui.sh"
TRACE_FUNC

if [ "$CONFIG_RESTRICTED_BOOT" = y ]; then
whiptail $BG_COLOR_ERROR --title 'Restricted Boot Active' \
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/flashrom-kgpe-d16-openbmc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
. /etc/functions

TRACE "Under /bin/flashrom-kgpe-d16-openbmc.sh"
TRACE_FUNC

ROM="$1"
if [ -z "$1" ]; then
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/generic-init
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mount_boot()
{
TRACE "Under /bin/generic-init:mount_boot"
TRACE_FUNC
# Mount local disk if it is not already mounted
if ! grep -q /boot /proc/mounts ; then
mount -o ro /boot \
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/gpg-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e -o pipefail
. /etc/gui_functions
. /tmp/config

TRACE "Under /bin/gpg-gui.sh"
TRACE_FUNC
gpg_flash_rom() {

if [ "$1" = "replace" ]; then
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/gpgv
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# if we are using the full GPG we need a wrapper for the gpgv executable
. /etc/functions

TRACE "Under /bin/gpgv"
TRACE_FUNC
exec gpg --verify "$@"
40 changes: 20 additions & 20 deletions initrd/bin/gui-init
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ skip_to_menu="false"

mount_boot()
{
TRACE "Under /bin/gui-init:mount_boot"
TRACE_FUNC
# Mount local disk if it is not already mounted
while ! grep -q /boot /proc/mounts ; do
# try to mount if CONFIG_BOOT_DEV exists
Expand Down Expand Up @@ -64,7 +64,7 @@ mount_boot()

verify_global_hashes()
{
TRACE "Under /bin/gui-init:verify_global_hashes"
TRACE_FUNC
# Check the hashes of all the files, ignoring signatures for now
check_config /boot force
TMP_HASH_FILE="/tmp/kexec/kexec_hashes.txt"
Expand Down Expand Up @@ -139,7 +139,7 @@ verify_global_hashes()

prompt_update_checksums()
{
TRACE "Under /bin/gui-init:prompt_update_checksums"
TRACE_FUNC
if (whiptail $BG_COLOR_WARNING --title 'Update Checksums and sign all files in /boot' \
--yesno "You have chosen to update the checksums and sign all of the files in /boot.\n\nThis means that you trust that these files have not been tampered with.\n\nYou will need your GPG key available, and this change will modify your disk.\n\nDo you want to continue?" 0 80) then
if ! update_checksums ; then
Expand All @@ -151,7 +151,7 @@ prompt_update_checksums()

generate_totp_hotp()
{
TRACE "Under /bin/gui-init:generate_totp_hotp"
TRACE_FUNC
tpm_owner_password="$1" # May be empty, will prompt if needed and empty
if [ "$CONFIG_TPM" != "y" ] && [ -x /bin/hotp_verification ]; then
echo "Generating new HOTP secret"
Expand Down Expand Up @@ -180,7 +180,7 @@ generate_totp_hotp()

update_totp()
{
TRACE "Under /bin/gui-init:update_totp"
TRACE_FUNC
# update the TOTP code
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
tries=0
Expand Down Expand Up @@ -249,7 +249,7 @@ update_totp()

update_hotp()
{
TRACE "Under /bin/gui-init:update_hotp"
TRACE_FUNC
if [ -x /bin/hotp_verification ]; then
HOTP=`unseal-hotp`
if ! hotp_verification info ; then
Expand Down Expand Up @@ -313,7 +313,7 @@ update_hotp()

clean_boot_check()
{
TRACE "Under /bin/gui-init:clean_boot_check"
TRACE_FUNC
# assume /boot mounted
if ! grep -q /boot /proc/mounts ; then
return
Expand Down Expand Up @@ -342,7 +342,7 @@ clean_boot_check()

check_gpg_key()
{
TRACE "Under /bin/gui-init:check_gpg_key"
TRACE_FUNC
GPG_KEY_COUNT=`gpg -k 2>/dev/null | wc -l`
if [ $GPG_KEY_COUNT -eq 0 ]; then
BG_COLOR_MAIN_MENU=$BG_COLOR_ERROR
Expand Down Expand Up @@ -379,7 +379,7 @@ check_gpg_key()

prompt_auto_default_boot()
{
TRACE "Under /bin/gui-init:prompt_auto_default_boot"
TRACE_FUNC
echo -e "\nHOTP verification success\n\n"
if pause_automatic_boot; then
echo -e "\n\nAttempting default boot...\n\n"
Expand All @@ -389,7 +389,7 @@ prompt_auto_default_boot()

show_main_menu()
{
TRACE "Under /bin/gui-init:show_main_menu"
TRACE_FUNC
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
whiptail $BG_COLOR_MAIN_MENU --title "$MAIN_MENU_TITLE" \
--menu "$date\nTOTP: $TOTP | HOTP: $HOTP" 0 80 10 \
Expand Down Expand Up @@ -422,7 +422,7 @@ show_main_menu()

show_options_menu()
{
TRACE "Under /bin/gui-init:show_options_menu"
TRACE_FUNC
whiptail $BG_COLOR_MAIN_MENU --title "$CONFIG_BRAND_NAME Options" \
--menu "" 0 80 10 \
'b' ' Boot Options -->' \
Expand Down Expand Up @@ -483,7 +483,7 @@ show_options_menu()

show_boot_options_menu()
{
TRACE "Under /bin/gui-init:show_boot_options_menu"
TRACE_FUNC
whiptail $BG_COLOR_MAIN_MENU --title "Boot Options" \
--menu "Select A Boot Option" 0 80 10 \
'm' ' Show OS boot menu' \
Expand Down Expand Up @@ -511,7 +511,7 @@ show_boot_options_menu()

show_tpm_totp_hotp_options_menu()
{
TRACE "Under /bin/gui-init:show_tpm_totp_hotp_options_menu"
TRACE_FUNC
whiptail $BG_COLOR_MAIN_MENU --title "TPM/TOTP/HOTP Options" \
--menu "Select An Option" 0 80 10 \
'g' ' Generate new TOTP/HOTP secret' \
Expand All @@ -538,7 +538,7 @@ show_tpm_totp_hotp_options_menu()

prompt_totp_mismatch()
{
TRACE "Under /bin/gui-init:prompt_totp_mismatch"
TRACE_FUNC
if (whiptail $BG_COLOR_WARNING --title "TOTP/HOTP code mismatched" \
--yesno "TOTP/HOTP code mismatches could indicate either TPM tampering or clock drift:\n\nTo correct clock drift: 'date -s yyyy-MM-DD hh:mm:ss' in UTC timezone\nand save it to the RTC: 'hwclock -w'\nthen reboot and try again.\n\nWould you like to exit to a recovery console?" 0 80) then
echo ""
Expand All @@ -555,7 +555,7 @@ prompt_totp_mismatch()

reset_tpm()
{
TRACE "Under /bin/gui-init:reset_tpm"
TRACE_FUNC
if [ "$CONFIG_TPM" = "y" ]; then
if (whiptail $BG_COLOR_WARNING --title 'Reset the TPM' \
--yesno "This will clear the TPM and TPM password, replace them with new ones!\n\nDo you want to proceed?" 0 80) then
Expand Down Expand Up @@ -599,7 +599,7 @@ reset_tpm()

select_os_boot_option()
{
TRACE "Under /bin/gui-init:select_os_boot_option"
TRACE_FUNC
mount_boot
if verify_global_hashes ; then
kexec-select-boot -m -b /boot -c "grub.cfg" -g
Expand All @@ -608,7 +608,7 @@ select_os_boot_option()

attempt_default_boot()
{
TRACE "Under /bin/gui-init:attempt_default_boot"
TRACE_FUNC
mount_boot

if ! verify_global_hashes; then
Expand All @@ -626,7 +626,7 @@ attempt_default_boot()

force_unsafe_boot()
{
TRACE "Under /bin/gui-init:force_unsafe_boot"
TRACE_FUNC
if [ "$CONFIG_RESTRICTED_BOOT" = y ]; then
whiptail $BG_COLOR_ERROR --title 'ERROR: Restricted Boot Enabled' --msgbox "Restricted Boot is Enabled, forced boot not allowed.\n\nPress OK to return to the Main Menu" 0 80
return
Expand All @@ -639,7 +639,7 @@ force_unsafe_boot()
}

# gui-init start
TRACE "Under /bin/gui-init, start"
TRACE_FUNC

# Use stored HOTP key branding
if [ -r /boot/kexec_hotp_key ]; then
Expand Down Expand Up @@ -673,7 +673,7 @@ if [ "$HOTP" = "Success" -a -n "$CONFIG_AUTO_BOOT_TIMEOUT" ]; then
fi

while true; do
TRACE "Under gui-init:while true loop"
TRACE_FUNC
skip_to_menu="false"
show_main_menu
done
Expand Down
18 changes: 9 additions & 9 deletions initrd/bin/gui-init-basic
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ skip_to_menu="false"

mount_boot()
{
TRACE "Under /bin/gui-init:mount_boot"
TRACE_FUNC
# Mount local disk if it is not already mounted
while ! grep -q /boot /proc/mounts ; do
# try to mount if CONFIG_BOOT_DEV exists
Expand Down Expand Up @@ -63,7 +63,7 @@ mount_boot()

prompt_auto_default_boot()
{
TRACE "Under /bin/gui-init:prompt_auto_default_boot"
TRACE_FUNC
echo -e "\n\n"
if pause_automatic_boot; then
echo -e "\n\nAttempting default boot...\n\n"
Expand All @@ -73,7 +73,7 @@ prompt_auto_default_boot()

show_main_menu()
{
TRACE "Under /bin/gui-init:show_main_menu"
TRACE_FUNC
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
whiptail $BG_COLOR_MAIN_MENU --title "$MAIN_MENU_TITLE" \
--menu "$date" 0 80 10 \
Expand Down Expand Up @@ -102,7 +102,7 @@ show_main_menu()

show_options_menu()
{
TRACE "Under /bin/gui-init:show_options_menu"
TRACE_FUNC
whiptail $BG_COLOR_MAIN_MENU --title "$CONFIG_BRAND_NAME Basic Options" \
--menu "" 0 80 10 \
'b' ' Boot Options -->' \
Expand Down Expand Up @@ -133,7 +133,7 @@ show_options_menu()

show_boot_options_menu()
{
TRACE "Under /bin/gui-init:show_boot_options_menu"
TRACE_FUNC
whiptail $BG_COLOR_MAIN_MENU --title "Boot Options" \
--menu "Select A Boot Option" 0 80 10 \
'm' ' Show OS boot menu' \
Expand All @@ -157,14 +157,14 @@ show_boot_options_menu()

select_os_boot_option()
{
TRACE "Under /bin/gui-init:select_os_boot_option"
TRACE_FUNC
mount_boot
kexec-select-boot -m -b /boot -c "grub.cfg" -g -i
}

attempt_default_boot()
{
TRACE "Under /bin/gui-init:attempt_default_boot"
TRACE_FUNC
mount_boot

DEFAULT_FILE=`find /boot/kexec_default.*.txt 2>/dev/null | head -1`
Expand All @@ -183,7 +183,7 @@ attempt_default_boot()
}

# gui-init-basic start
TRACE "Under /bin/gui-init, start"
TRACE_FUNC

# USB automatic boot (if configured) occurs before mounting /boot, this should
# work even if no OS is installed
Expand All @@ -204,7 +204,7 @@ if [ "$skip_to_menu" != "true" -a -n "$CONFIG_AUTO_BOOT_TIMEOUT" ]; then
fi

while true; do
TRACE "Under gui-init:while true loop"
TRACE_FUNC
skip_to_menu="false"
show_main_menu
done
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/kexec-boot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e -o pipefail
. /tmp/config
. /etc/functions

TRACE "Under /bin/kexec-boot"
TRACE_FUNC

dryrun="n"
printfiles="n"
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/kexec-insert-key
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e -o pipefail
. /etc/functions

TRACE "Under /bin/kexec-insert-key"
TRACE_FUNC

TMP_KEY_DEVICES="/tmp/kexec/kexec_key_devices.txt"
TMP_KEY_LVM="/tmp/kexec/kexec_key_lvm.txt"
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/kexec-iso-init
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e -o pipefail
. /etc/functions
. /tmp/config

TRACE "Under /bin/kexec-iso-init"
TRACE_FUNC

MOUNTED_ISO_PATH="$1"
ISO_PATH="$2"
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/kexec-parse-bls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e -o pipefail
. /etc/functions
TRACE "Under /bin/kexec-parse-bls"
TRACE_FUNC

bootdir="$1"
file="$2"
Expand Down
2 changes: 1 addition & 1 deletion initrd/bin/kexec-parse-boot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e -o pipefail
. /etc/functions

TRACE "Under /bin/kexec-parse-boot"
TRACE_FUNC

bootdir="$1"
file="$2"
Expand Down
4 changes: 2 additions & 2 deletions initrd/bin/kexec-save-default
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e -o pipefail
. /tmp/config
. /etc/functions

TRACE "Under /bin/kexec-save-default"
TRACE_FUNC

while getopts "b:d:p:i:" arg; do
case $arg in
Expand Down Expand Up @@ -71,7 +71,7 @@ fi

#Reusable function when user wants to define new TPM DUK for lvms/disks
prompt_for_existing_encrypted_lvms_or_disks() {
TRACE "Under kexec-save-default:prompt_for_existing_encrypted_lvms_or_disks"
TRACE_FUNC
DEBUG "num_lvm: $num_lvm, lvm_suggest: $lvm_suggest, num_devices: $num_devices, devices_suggest: $devices_suggest"

# Create an associative array to store the suggested LVMs and their paths
Expand Down
Loading

0 comments on commit 5bff519

Please sign in to comment.