feat: Boot detection (#6)

This commit is contained in:
Kroese 2024-02-05 21:23:07 +01:00 committed by GitHub
parent 1c2c8c5e14
commit d5f4b4784b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,7 @@ 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="starting Boot0002"
rm -f /run/shm/qemu.*
touch "$QEMU_LOG"
@ -40,6 +41,15 @@ finish() {
done
fi
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then
if grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
if [ -f "$STORAGE/$BASE" ]; then
rm -f "$STORAGE/$BASE"
touch "$STORAGE/windows.boot"
fi
fi
fi
pid="/var/run/tpm.pid"
[ -f "$pid" ] && pKill "$(<"$pid")"
@ -116,12 +126,8 @@ _graceful_shutdown() {
finish "$code" && return "$code"
fi
local remove_iso=""
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then
if grep -Fq "starting Boot0002" "$QEMU_PTY"; then
[ -f "$STORAGE/$BASE" ] && remove_iso="y"
else
if ! grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
info "Cannot send ACPI signal during Windows setup, aborting..."
finish "$code" && return "$code"
fi
@ -149,11 +155,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"