|
5 | 5 | # Pause for the configured timeout before booting automatically. Returns 0 to |
6 | 6 | # continue with automatic boot, nonzero if user interrupted. |
7 | 7 | 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 |
13 | 41 | } |
14 | 42 |
|
15 | 43 | mount_usb() { |
|
0 commit comments