feat: Detect SeaBIOS status (#153)

This commit is contained in:
Kroese 2024-02-06 03:47:32 +01:00 committed by GitHub
parent 249c5b7731
commit 42a5295306
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,29 @@ _trap() {
done done
} }
ready() {
[ -f "$STORAGE/windows.boot" ] && return 0
[ ! -f "$QEMU_PTY" ] && return 1
if [ -f "$STORAGE/windows.old" ]; then
local last
local bios="Booting from Hard Disk"
last=$(grep "^B.*" "$QEMU_PTY" | tail -1)
if [[ "${last,,}" == "${bios,,}"* ]]; then
return 0
fi
return 1
fi
local line="Windows Boot Manager"
if grep -Fq "$line" "$QEMU_PTY"; then
return 0
fi
return 1
}
finish() { finish() {
local pid local pid
@ -40,6 +63,14 @@ finish() {
done done
fi 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
pid="/var/run/tpm.pid" pid="/var/run/tpm.pid"
[ -f "$pid" ] && pKill "$(<"$pid")" [ -f "$pid" ] && pKill "$(<"$pid")"
@ -116,18 +147,10 @@ _graceful_shutdown() {
finish "$code" && return "$code" finish "$code" && return "$code"
fi fi
local remove_iso="" if ! ready; then
if [ ! -f "$STORAGE/windows.old" ]; then
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$QEMU_PTY" ]; then
if grep -Fq "Windows Boot Manager" "$QEMU_PTY"; then
[ -f "$STORAGE/$BASE" ] && remove_iso="y"
else
info "Cannot send ACPI signal during Windows setup, aborting..." info "Cannot send ACPI signal during Windows setup, aborting..."
finish "$code" && return "$code" finish "$code" && return "$code"
fi fi
fi
fi
# Send ACPI shutdown signal # Send ACPI shutdown signal
echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
@ -151,11 +174,6 @@ _graceful_shutdown() {
if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then
error "Shutdown timeout reached, aborting..." error "Shutdown timeout reached, aborting..."
else
if [ -n "$remove_iso" ]; then
rm -f "$STORAGE/$BASE"
touch "$STORAGE/windows.boot"
fi
fi fi
finish "$code" && return "$code" finish "$code" && return "$code"