Update power.sh

This commit is contained in:
Kroese 2024-02-06 02:32:38 +01:00 committed by GitHub
parent 9a9832f57b
commit 8b53d3c8b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,9 +12,6 @@ QEMU_LOG="/run/shm/qemu.log"
QEMU_OUT="/run/shm/qemu.out" QEMU_OUT="/run/shm/qemu.out"
QEMU_END="/run/shm/qemu.end" QEMU_END="/run/shm/qemu.end"
BIOS_LINE="Booting from Hard Disk..."
BOOT_LINE="Windows Boot Manager"
rm -f /run/shm/qemu.* rm -f /run/shm/qemu.*
touch "$QEMU_LOG" touch "$QEMU_LOG"
@ -25,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
@ -43,21 +63,11 @@ finish() {
done done
fi fi
if [ -f "$STORAGE/$BASE" ] && [ ! -f "$STORAGE/windows.boot" ]; then if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$STORAGE/$BASE" ]; then
if [ -f "$QEMU_PTY" ]; then # Remove CD-ROM ISO after install
if [ ! -f "$STORAGE/windows.old" ]; then if ready; then
if grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then rm -f "$STORAGE/$BASE"
rm -f "$STORAGE/$BASE" touch "$STORAGE/windows.boot"
touch "$STORAGE/windows.boot"
fi
else
local last
last=$(tail -n 1 "$QEMU_PTY")
if [[ "${last,,}" == "${BIOS_LINE,,}" ]]; then
rm -f "$STORAGE/$BASE"
touch "$STORAGE/windows.boot"
fi
fi
fi fi
fi fi
@ -137,20 +147,9 @@ _graceful_shutdown() {
finish "$code" && return "$code" finish "$code" && return "$code"
fi fi
local abort="Cannot send ACPI signal during Windows setup, aborting..." if ! ready; then
info "Cannot send ACPI signal during Windows setup, aborting..."
if [ -f "$QEMU_PTY" ] && [ ! -f "$STORAGE/windows.boot" ]; then finish "$code" && return "$code"
if [ ! -f "$STORAGE/windows.old" ]; then
if ! grep -Fq "$BOOT_LINE" "$QEMU_PTY"; then
info "$abort" && finish "$code" && return "$code"
fi
else
local last
last=$(tail -n 1 "$QEMU_PTY")
if [[ "${last,,}" != "${BIOS_LINE,,}" ]]; then
info "$abort" && finish "$code" && return "$code"
fi
fi
fi fi
# Send ACPI shutdown signal # Send ACPI shutdown signal