|
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 |
| 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)" |
11 | 17 | 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 |
12 | 49 | return 0 # Continue with automatic boot
|
13 | 50 | }
|
14 | 51 |
|
|
0 commit comments