Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ else
fi

pid=$!
( sleep 30; boot ) &
waitForBoot "$pid" 30 &

rc=0
wait "$pid" || rc=$?
Expand Down
74 changes: 59 additions & 15 deletions src/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,80 @@ CONSOLE_PID="$QEMU_DIR/console.pid"
CONSOLE_SOCKET="$QEMU_DIR/console.sock"
QEMU_START_PID="$QEMU_DIR/qemu.start.pid"

bootFailed() {
bootStatus() {

local fail=""
[ ! -s "$QEMU_PTY" ] && return 1

if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
grep -Fq "No bootable device." "$QEMU_PTY" && fail="y"
grep -Fq "BOOTMGR is missing" "$QEMU_PTY" && fail="y"
grep -Fq \
-e "No bootable device." \
-e "BOOTMGR is missing" \
-e "Boot failed: not a bootable disk" \
-e "Boot failed: could not read the boot disk" \
"$QEMU_PTY" && return 2

grep -Eq '^Booting from (Hard|DVD/CD)' "$QEMU_PTY"
return $?
fi

[ -n "$fail" ]
grep -Fq "UEFI Interactive Shell" "$QEMU_PTY" && return 2

local last
last=$(grep -E \
'BdsDxe: starting Boot[[:xdigit:]]{4} ' \
"$QEMU_PTY" | tail -1)

[ -z "$last" ] && return 1

grep -Eq \
-e '"Windows Boot Manager"' \
-e '"UEFI QEMU .*DVD-ROM' \
-e 'CDROM\(' \
-e 'USB\(' \
<<< "$last"
}

boot() {
waitForBoot() {

[ -f "$QEMU_END" ] && return 0
local pid="$1"
local timeout="${2:-30}"
local deadline=$((SECONDS + timeout))
local screen="visit http://127.0.0.1:$WEB_PORT/ to view the screen..."

while isAlive "$pid"; do

if [ -s "$QEMU_PTY" ]; then
if [ "$(stat -c%s "$QEMU_PTY")" -gt 7 ]; then
if ! bootFailed; then
if bootStatus; then
local status=0
else
local status=$?
fi

case "$status" in
0)
if [[ "${DISPLAY,,}" == "web" ]] && ! disabled "${WEB:-Y}"; then
info "$(app) started successfully, visit http://127.0.0.1:$WEB_PORT/ to view the screen..."
info "$(app) started successfully, $screen"
else
info "$(app) started successfully."
fi

return 0
fi
fi
fi
return 0 ;;
2)
if [[ "${DISPLAY,,}" == "web" ]] && ! disabled "${WEB:-Y}"; then
warn "$(app) could not boot, $screen"
else
warn "$(app) could not boot."
fi

return 0 ;;
esac

(( SECONDS >= deadline )) && break

sleep 0.1
done

! isAlive "$pid" && return 0
[ -f "$QEMU_END" ] && return 0

error "Timeout while waiting for QEMU to boot the machine, aborting..."
terminateQemu
Expand Down