Skip to content

Commit

Permalink
feat: Boot detection (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Feb 5, 2024
1 parent 1c2c8c5 commit d5f4b47
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d5f4b47

Please sign in to comment.