Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions initrd/etc/gui_functions
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,48 @@
# Pause for the configured timeout before booting automatically. Returns 0 to
# continue with automatic boot, nonzero if user interrupted.
pause_automatic_boot() {
if IFS= read -t "$CONFIG_AUTO_BOOT_TIMEOUT" -s -n 1 -r -p \
$'Automatic boot in '"$CONFIG_AUTO_BOOT_TIMEOUT"$' seconds unless interrupted by keypress...\n'; then
return 1 # Interrupt automatic boot
fi
local remaining="$CONFIG_AUTO_BOOT_TIMEOUT"

echo "Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds unless interrupted by keypress..."
printf "\n" # Reserve space for the updating line

while [ $remaining -gt 0 ]; do
# Record the start time of this loop iteration (epoch seconds)
local loop_start now_str status_line elapsed sleep_time
loop_start=$(date +%s)

now_str=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
status_line="$now_str | Booting in $remaining seconds..."

if [ "$CONFIG_TPM" = "y" ] && [ "$CONFIG_TOTP_SKIP_QRCODE" != "y" ]; then
# Get current TOTP if available and not skipped
local current_totp
if ! current_totp=$(unseal-totp 2>/dev/null); then
die "Failed to unseal TOTP"
fi
status_line="$status_line | TOTP: $current_totp"
Comment on lines +24 to +27
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.

fi

# Update the status line in place (overwrites previous output)
printf "\r%s" "$status_line"

# Calculate elapsed time for this loop iteration
elapsed=$(( $(date +%s) - loop_start ))
# Calculate how much time to wait to complete 1 second
sleep_time=$(( 1 - elapsed ))
[ $sleep_time -lt 0 ] && sleep_time=0
Comment on lines +36 to +37
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.


# 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.

printf "\n" # New line after interrupt
return 1 # Interrupt automatic boot
fi

remaining=$((remaining - 1))
done

printf "\n" # New line after countdown
return 0 # Continue with automatic boot
}

Expand Down