Skip to content

Commit

Permalink
Update power.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Feb 6, 2024
1 parent 893ca1f commit 58051bb
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ QEMU_LOG="/run/shm/qemu.log"
QEMU_OUT="/run/shm/qemu.out"
QEMU_END="/run/shm/qemu.end"

BOOT_LINE="Windows Boot Manager"

rm -f /run/shm/qemu.*
touch "$QEMU_LOG"

Expand All @@ -24,6 +22,19 @@ _trap() {
done
}

ready() {

[ -f "$STORAGE/windows.boot" ] && return 0
[ ! -f "$QEMU_PTY" ] && return 1

local line="Windows Boot Manager"
if grep -Fq "$line" "$QEMU_PTY"; then
return 0
fi

return 1
}

finish() {

local pid
Expand All @@ -42,12 +53,11 @@ finish() {
done
fi

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"
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

Expand Down Expand Up @@ -127,12 +137,9 @@ _graceful_shutdown() {
finish "$code" && return "$code"
fi

local abort="Cannot send ACPI signal during Windows setup, aborting..."

if [ -f "$QEMU_PTY" ] && [ ! -f "$STORAGE/windows.boot" ]; then
if ! grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
info "$abort" && finish "$code" && return "$code"
fi
if ! ready; then
info "Cannot send ACPI signal during Windows setup, aborting..."
finish "$code" && return "$code"
fi

# Send ACPI shutdown signal
Expand Down

0 comments on commit 58051bb

Please sign in to comment.