Skip to content

Commit 89d8ff9

Browse files
authored
feat: Boot detection
1 parent 1c2c8c5 commit 89d8ff9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/power.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ QEMU_PTY="/run/shm/qemu.pty"
1111
QEMU_LOG="/run/shm/qemu.log"
1212
QEMU_OUT="/run/shm/qemu.out"
1313
QEMU_END="/run/shm/qemu.end"
14+
BOOT_LINE="starting Boot0002"
1415

1516
rm -f /run/shm/qemu.*
1617
touch "$QEMU_LOG"
@@ -40,6 +41,15 @@ finish() {
4041
done
4142
fi
4243

44+
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then
45+
if grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
46+
if [ -f "$STORAGE/$BASE" ]; then
47+
rm -f "$STORAGE/$BASE"
48+
touch "$STORAGE/windows.boot"
49+
fi
50+
fi
51+
fi
52+
4353
pid="/var/run/tpm.pid"
4454
[ -f "$pid" ] && pKill "$(<"$pid")"
4555

@@ -116,12 +126,8 @@ _graceful_shutdown() {
116126
finish "$code" && return "$code"
117127
fi
118128

119-
local remove_iso=""
120-
121129
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then
122-
if grep -Fq "starting Boot0002" "$QEMU_PTY"; then
123-
[ -f "$STORAGE/$BASE" ] && remove_iso="y"
124-
else
130+
if ! grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
125131
info "Cannot send ACPI signal during Windows setup, aborting..."
126132
finish "$code" && return "$code"
127133
fi
@@ -149,11 +155,6 @@ _graceful_shutdown() {
149155

150156
if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then
151157
error "Shutdown timeout reached, aborting..."
152-
else
153-
if [ -n "$remove_iso" ]; then
154-
rm -f "$STORAGE/$BASE"
155-
touch "$STORAGE/windows.boot"
156-
fi
157158
fi
158159

159160
finish "$code" && return "$code"

0 commit comments

Comments
 (0)