From 42a529530665b9087281eaf616a0e509e8cc1a5f Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 6 Feb 2024 03:47:32 +0100 Subject: [PATCH] feat: Detect SeaBIOS status (#153) --- src/power.sh | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/power.sh b/src/power.sh index e7f9b97..4280441 100644 --- a/src/power.sh +++ b/src/power.sh @@ -22,6 +22,29 @@ _trap() { done } +ready() { + + [ -f "$STORAGE/windows.boot" ] && return 0 + [ ! -f "$QEMU_PTY" ] && return 1 + + if [ -f "$STORAGE/windows.old" ]; then + local last + local bios="Booting from Hard Disk" + last=$(grep "^B.*" "$QEMU_PTY" | tail -1) + if [[ "${last,,}" == "${bios,,}"* ]]; then + return 0 + fi + return 1 + fi + + local line="Windows Boot Manager" + if grep -Fq "$line" "$QEMU_PTY"; then + return 0 + fi + + return 1 +} + finish() { local pid @@ -40,6 +63,14 @@ finish() { done fi + if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$STORAGE/$BASE" ]; then + # Remove CD-ROM ISO after install + if ready; then + rm -f "$STORAGE/$BASE" + touch "$STORAGE/windows.boot" + fi + fi + pid="/var/run/tpm.pid" [ -f "$pid" ] && pKill "$(<"$pid")" @@ -116,17 +147,9 @@ _graceful_shutdown() { finish "$code" && return "$code" fi - local remove_iso="" - - if [ ! -f "$STORAGE/windows.old" ]; then - if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then - if grep -Fq "Windows Boot Manager" "$QEMU_PTY"; then - [ -f "$STORAGE/$BASE" ] && remove_iso="y" - else - info "Cannot send ACPI signal during Windows setup, aborting..." - finish "$code" && return "$code" - fi - fi + if ! ready; then + info "Cannot send ACPI signal during Windows setup, aborting..." + finish "$code" && return "$code" fi # Send ACPI shutdown signal @@ -151,11 +174,6 @@ _graceful_shutdown() { if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then error "Shutdown timeout reached, aborting..." - else - if [ -n "$remove_iso" ]; then - rm -f "$STORAGE/$BASE" - touch "$STORAGE/windows.boot" - fi fi finish "$code" && return "$code"