From e9447929b63fbe91b47b634c2e1dfb52c488982e Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 14 Oct 2022 03:48:16 +0200 Subject: [PATCH] add debug output via tesseract --- wfvm/utils.nix | 10 +++++++++- wfvm/win.nix | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/wfvm/utils.nix b/wfvm/utils.nix index 7138d0b..38a6331 100644 --- a/wfvm/utils.nix +++ b/wfvm/utils.nix @@ -36,6 +36,7 @@ rec { # Wait for VM to be accessible sleep 20 echo "Waiting for SSH..." + TEXT="" while true; do if test "$timeout" -eq 0; then echo "SSH connection timed out" @@ -47,6 +48,13 @@ rec { break fi + ${pkgs.vncdo}/bin/vncdo rcapture cap.png 0 0 1024 768 + ${pkgs.imagemagick}/bin/mogrify -density 70x70 -units PixelsPerInch cap.png + NEW_TEXT="$(${pkgs.tesseract}/bin/tesseract cap.png stdout)" + if [ "$TEXT" != "$NEW_TEXT" ]; then + echo "$NEW_TEXT" + TEXT="$NEW_TEXT" + fi echo "Retrying in 1 second, timing out in $timeout seconds" ((timeout=$timeout-1)) @@ -85,7 +93,7 @@ rec { (map ({ listenAddr, targetAddr, port }: ",guestfwd=tcp:${listenAddr}:${toString port}-cmd:${pkgs.socat}/bin/socat\\ -\\ tcp:${targetAddr}:${toString port}" ) forwardedPorts); - qemuParams = mkQemuFlags (pkgs.lib.optional (!display) "-display none" ++ pkgs.lib.optional (!fakeRtc) "-rtc base=localtime" ++ [ + qemuParams = mkQemuFlags (pkgs.lib.optional (!display) "-vnc 127.0.0.1:0" ++ pkgs.lib.optional (!fakeRtc) "-rtc base=localtime" ++ [ "-drive" "file=${image},index=0,media=disk,cache=unsafe" "-snapshot" diff --git a/wfvm/win.nix b/wfvm/win.nix index c818e2e..091273b 100644 --- a/wfvm/win.nix +++ b/wfvm/win.nix @@ -88,7 +88,7 @@ let installScript = pkgs.writeScript "windows-install-script" ( let - qemuParams = utils.mkQemuFlags (lib.optional (!impureMode) "-display none" ++ [ + qemuParams = utils.mkQemuFlags (lib.optional (!impureMode) "-vnc 127.0.0.1:0" ++ [ # "CD" drive with bootstrap pkgs "-drive" "id=virtio-win,file=${bootstrapPkgs},if=none,format=raw,readonly=on" @@ -108,7 +108,7 @@ let in '' #!${pkgs.runtimeShell} - set -euxo pipefail + set -euo pipefail export PATH=${lib.makeBinPath [ p7zip utils.qemu guestfs-tools pkgs.wimlib ]}:$PATH # Create a bootable "USB" image @@ -134,7 +134,19 @@ let # Qemu requires files to be rw qemu-img create -f qcow2 c.img ${diskImageSize} - qemu-system-x86_64 ${lib.concatStringsSep " " qemuParams} + qemu-system-x86_64 ${lib.concatStringsSep " " qemuParams} & + + TEXT="" + while [ -n "$(jobs)" ]; do + ${pkgs.vncdo}/bin/vncdo rcapture cap.png 0 0 1024 768 + ${pkgs.imagemagick}/bin/mogrify -density 70x70 -units PixelsPerInch cap.png + NEW_TEXT="$(${pkgs.tesseract5}/bin/tesseract cap.png stdout)" + if [ "$TEXT" != "$NEW_TEXT" ]; then + echo "$NEW_TEXT" + TEXT="$NEW_TEXT" + fi + sleep 1 + done '' );