From 554dd91f7fb5ddbeaf3bf6da29f3bf01881bafa7 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 6 Feb 2024 00:24:30 +0100 Subject: [PATCH] Update power.sh --- src/power.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/power.sh b/src/power.sh index b615501..e46a31a 100644 --- a/src/power.sh +++ b/src/power.sh @@ -11,8 +11,10 @@ QEMU_PTY="/run/shm/qemu.pty" QEMU_LOG="/run/shm/qemu.log" QEMU_OUT="/run/shm/qemu.out" QEMU_END="/run/shm/qemu.end" -BOOT_LINE="Windows Boot Manager" +BIOS_LINE="Booting from Hard Disk..." +BOOT_LINE="Windows Boot Manager" + rm -f /run/shm/qemu.* touch "$QEMU_LOG" @@ -41,11 +43,20 @@ finish() { done fi - if [ ! -f "$STORAGE/windows.old" ] && [ ! -f "$STORAGE/windows.boot" ]; then + if [ -f "$STORAGE/$BASE" ] && [ ! -f "$STORAGE/windows.boot" ]; then if [ -f "$QEMU_PTY" ]; then - if grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then - rm -f "$STORAGE/$BASE" - touch "$STORAGE/windows.boot" + if [ ! -f "$STORAGE/windows.old" ]; then + if grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then + rm -f "$STORAGE/$BASE" + touch "$STORAGE/windows.boot" + fi + else + local last + last=$(tail -n 1 "$QEMU_PTY") + if [[ "${last,,}" == "${BIOS_LINE,,}" ]]; then + rm -f "$STORAGE/$BASE" + touch "$STORAGE/windows.boot" + fi fi fi fi @@ -126,12 +137,19 @@ _graceful_shutdown() { finish "$code" && return "$code" fi - if [ ! -f "$STORAGE/windows.old" ] && [ ! -f "$STORAGE/windows.boot" ]; then - if [ -f "$QEMU_PTY" ]; then + if [ -f "$QEMU_PTY" ] && [ ! -f "$STORAGE/windows.boot" ]; then + if [ ! -f "$STORAGE/windows.old" ]; then if ! grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then info "Cannot send ACPI signal during Windows setup, aborting..." finish "$code" && return "$code" fi + else + local last + last=$(tail -n 1 "$QEMU_PTY") + if [[ "${last,,}" != "${BIOS_LINE,,}" ]]; then + info "Cannot send ACPI signal during Windows setup, aborting..." + finish "$code" && return "$code" + fi fi fi