Skip to content

Commit db9f55e

Browse files
committed
initrd/etc/gui_functions pause_automatic_boot: show UTC timestamp + TOTP code while waiting for automatic boot when a default boot is set and HOTP is valid
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent ca0a90b commit db9f55e

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

initrd/etc/gui_functions

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,39 @@
55
# Pause for the configured timeout before booting automatically. Returns 0 to
66
# continue with automatic boot, nonzero if user interrupted.
77
pause_automatic_boot() {
8-
if IFS= read -t "$CONFIG_AUTO_BOOT_TIMEOUT" -s -n 1 -r -p \
9-
$'Automatic boot in '"$CONFIG_AUTO_BOOT_TIMEOUT"$' seconds unless interrupted by keypress...\n'; then
10-
return 1 # Interrupt automatic boot
11-
fi
12-
return 0 # Continue with automatic boot
8+
local target now remaining now_str status_line current_totp
9+
10+
# Compute absolute target time so remaining is accurate regardless of
11+
# per-iteration processing time. This keeps the visible timestamp/TOTP
12+
# updated each second while the countdown decrements correctly.
13+
target=$(( $(date +%s) + CONFIG_AUTO_BOOT_TIMEOUT ))
14+
printf "\n" # Reserve space for the updating line
15+
while :; do
16+
now=$(date +%s)
17+
remaining=$((target - now))
18+
if [ $remaining -le 0 ]; then
19+
break
20+
fi
21+
22+
now_str=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
23+
status_line="$now_str | Booting in $remaining seconds..."
24+
if [ "$CONFIG_TPM" = "y" ] && [ "$CONFIG_TOTP_SKIP_QRCODE" != "y" ]; then
25+
if current_totp=$(unseal-totp 2>/dev/null); then
26+
status_line="$status_line | TOTP: $current_totp"
27+
fi
28+
fi
29+
30+
# Print status on single refreshed line and wait up to 1s for a key
31+
# (any key, no Enter required). Use a throwaway var to avoid linter
32+
# warnings about an unused variable.
33+
printf "\r%s\033[K" "$status_line"
34+
if IFS= read -t 1 -n 1 _; then
35+
printf "\n"
36+
return 1
37+
fi
38+
done
39+
printf "\n"
40+
return 0
1341
}
1442

1543
mount_usb() {

0 commit comments

Comments
 (0)