Skip to content

Commit b5188bc

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 440288e commit b5188bc

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

initrd/etc/gui_functions

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,47 @@
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
8+
local remaining="$CONFIG_AUTO_BOOT_TIMEOUT"
9+
10+
# Calculate boot time for initial message
11+
local now_epoch boot_epoch boot_str
12+
now_epoch=$(date -u +%s)
13+
boot_epoch=$((now_epoch + CONFIG_AUTO_BOOT_TIMEOUT))
14+
boot_str=$(date -u -d "@$boot_epoch" '+%Y-%m-%d %H:%M:%S UTC' 2>/dev/null)
15+
if [ -z "$boot_str" ]; then
16+
boot_str="(epoch: $boot_epoch)"
1117
fi
18+
echo "Automatic boot in $CONFIG_AUTO_BOOT_TIMEOUT seconds at $boot_str unless interrupted by keypress..."
19+
printf "\n" # Reserve space for the updating line
20+
21+
while [ $remaining -gt 0 ]; do
22+
local now_epoch now_str status_line
23+
now_epoch=$(date -u +%s)
24+
now_str=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
25+
status_line="$now_str | Booting in $remaining seconds..."
26+
27+
if [ "$CONFIG_TPM" = "y" ] && [ "$CONFIG_TOTP_SKIP_QRCODE" != "y" ]; then
28+
# Get current TOTP if available and not skipped
29+
local current_totp
30+
if ! current_totp=$(unseal-totp 2>/dev/null); then
31+
die "Failed to unseal TOTP"
32+
fi
33+
status_line="$status_line | TOTP: $current_totp"
34+
fi
35+
36+
# Update the status line in place
37+
printf "\r%s" "$status_line"
38+
39+
# Check for keypress
40+
if IFS= read -t 1 -s -n 1 -r; then
41+
printf "\n" # New line after interrupt
42+
return 1 # Interrupt automatic boot
43+
fi
44+
45+
remaining=$((remaining - 1))
46+
done
47+
48+
printf "\n" # New line after countdown
1249
return 0 # Continue with automatic boot
1350
}
1451

0 commit comments

Comments
 (0)