diff --git a/Justfile b/Justfile index 721df5b..d2f73e1 100755 --- a/Justfile +++ b/Justfile @@ -99,3 +99,30 @@ disk-umount dir: # Perform an offline installation on the mounted target disk, specified by device configuration directory disk-install dir: _render_templates just -v _device diskInstall {{dir}} --argstr rebuildarg "dummy" + +verify-vnc sshserver attempts="10": + #!/usr/bin/env bash + set -e + export MAGICK_ARGS="-filter Catrom -density 72 -resample 300 -contrast -normalize -despeckle -type grayscale -sharpen 1 -posterize 3 -negate -gamma 100 -blur 1x65535" + export TESS_ARGS="-c debug_file=/dev/null --psm 4" + + send_and_compare() { + local EXPECT="$(pwgen -0 12)" + ssh -4 ${SSHOPTS} root@{{sshserver}} "echo -e '\0033\0143'${EXPECT}>> /dev/tty0" 1>/dev/null 2>&1 + vncdo --server=${VNCSOCK} --password=${VNCPW} --disable-desktop-resizing --nocursor capture $PWD/screenshot.bmp + convert ${MAGICK_ARGS} screenshot.bmp screenshot.tiff + tesseract ${TESS_ARGS} screenshot.tiff screenshot + grep --quiet ${EXPECT} screenshot.txt + } + + trap "E=$?; set +e; rm screenshot.*; echo Exiting...; exit $E" INT TERM HUP + + for i in `seq 1 {{attempts}}`; do + if send_and_compare; then + echo Verification succeeded at attempt $i. Unlocking remote drive... + # TODO: unlock drive + exit 0 + fi + done + echo Verification failed {{attempts}} times. Giving up... + exit 1 diff --git a/shell.nix b/shell.nix index a8fa72c..1bde9c2 100644 --- a/shell.nix +++ b/shell.nix @@ -11,6 +11,10 @@ stdenv.mkDerivation { git-crypt vcsh gnupg + + vncdo + tesseract + imagemagick ]; # Set Environment Variables