Skip to content

Conversation

tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Aug 26, 2025

This pull request refactors the pause_automatic_boot function in initrd/etc/gui_functions to improve user experience and add TOTP display support during the automatic boot countdown. The main changes include switching to a live countdown display, optionally showing the current TOTP code, and handling user interruption more interactively.

User experience improvements:

  • The boot countdown now updates live on the same line, showing the remaining seconds and the current UTC timestamp, instead of a static message.
  • If TPM and TOTP are enabled and QR code display is not skipped, the current TOTP code is shown alongside the countdown. Errors in retrieving the TOTP are handled gracefully.

Interactive interruption:

  • The function checks for user keypresses every second during the countdown, allowing interruption at any time, and prints a newline for clarity after an interrupt.

In action under qemu-coreboot-whiptail-tpm2-hotp-prod (not silent, not debug):
2025-08-27-180603
2025-08-27-180613
2025-08-27-180647

@tlaurion
Copy link
Collaborator Author

tlaurion commented Aug 27, 2025

Old OP (in link of deprecated superseeded commit e0fb3e7)

This pull request enhances the user experience during the automatic boot countdown in the initrd/etc/gui_functions script. The main improvement is the addition of a dynamic countdown display that updates every second and optionally shows the current TOTP code if TPM is enabled and QR code display is not skipped.

User experience improvements:

  • The automatic boot countdown now updates every second, providing a more interactive and visible countdown for the user.
  • If TPM is enabled and QR code display is not skipped, the current TOTP code is retrieved and displayed alongside the countdown, giving users immediate access to authentication information.
  • The script checks for a keypress each second, allowing the user to interrupt the boot process at any time during the countdown.

In action under qemu-coreboot-whiptail-tpm2-hotp-prod (not silent, not debug):

2025-08-26-160027 2025-08-26-160100 2025-08-26-160142

@tlaurion
Copy link
Collaborator Author

Small UX bug to fix, time shown on screen is updated every 2 seconds, not every seconds.

…OTP code while waiting for automatic boot when a default boot is set and hotp is valid

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion tlaurion force-pushed the totp_on_automatic_boot branch from dbd095a to 25b3d80 Compare September 22, 2025 18:00
@tlaurion
Copy link
Collaborator Author

signal-2025-09-22-144315

Self reviewed. @JonathonHall-Purism comments?

@tlaurion tlaurion requested a review from Copilot September 22, 2025 18:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the pause_automatic_boot function to provide an enhanced user experience during the automatic boot countdown with live updates and optional TOTP display. The changes replace a simple single-line timeout with an interactive countdown loop.

  • Implements live countdown display that updates every second with current UTC timestamp
  • Adds optional TOTP code display when TPM is enabled and QR code display is not skipped
  • Enables real-time user interruption by checking for keypresses every second

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +24 to +27
if ! current_totp=$(unseal-totp 2>/dev/null); then
die "Failed to unseal TOTP"
fi
status_line="$status_line | TOTP: $current_totp"
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function calls die when TOTP unsealing fails, which will terminate the entire process. This contradicts the PR description which states that 'Errors in retrieving the TOTP are handled gracefully.' Consider continuing the countdown without TOTP display instead of terminating.

Suggested change
if ! current_totp=$(unseal-totp 2>/dev/null); then
die "Failed to unseal TOTP"
fi
status_line="$status_line | TOTP: $current_totp"
if current_totp=$(unseal-totp 2>/dev/null); then
status_line="$status_line | TOTP: $current_totp"
fi

Copilot uses AI. Check for mistakes.


# Wait for keypress for the remaining time in this second
# IFS= disables word splitting, -t sets timeout, -s disables echo, -n 1 reads one char, -r disables backslash escapes
if IFS= read -t $sleep_time -s -n 1 -r; then
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sleep_time variable should be quoted to prevent word splitting issues when passed to the -t option. Use \"$sleep_time\" instead of $sleep_time.

Suggested change
if IFS= read -t $sleep_time -s -n 1 -r; then
if IFS= read -t "$sleep_time" -s -n 1 -r; then

Copilot uses AI. Check for mistakes.

Comment on lines +36 to +37
sleep_time=$(( 1 - elapsed ))
[ $sleep_time -lt 0 ] && sleep_time=0
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the loop processing takes longer than 1 second, sleep_time becomes 0, but the countdown will still decrement by 1. This could cause the countdown to complete faster than the configured timeout. Consider adjusting the remaining time based on actual elapsed time instead of always decrementing by 1.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant