diff --git a/Justfile b/Justfile index 0095766..70c81c9 100755 --- a/Justfile +++ b/Justfile @@ -114,25 +114,52 @@ verify-vnc sshserver attempts="10": 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 + function send() { + local what="${1:?need something to send}" + ssh -4 ${SSHOPTS:?need sshopts} root@{{sshserver}} "echo -e ${what}>> /dev/tty0" &>/dev/null + } + + function expect() { + local what="${1:?need something to expect}" 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 + grep --quiet "${what}" screenshot.txt } - trap "E=$?; set +e; rm screenshot.*; echo Exiting...; exit $E" INT TERM HUP + function send_and_expect() { + local send="${1:?need something to send}" + local expect="${2:?need something to expect}" + send "${send}" + expect "${expect}" + } + + trap 'E=$?; set +e; rm screenshot.*; echo Exiting...; kill $(jobs -p | cut -d " " -f 4); exit $E' EXIT for i in `seq 1 {{attempts}}`; do - if send_and_compare; then + echo Attempt $i... + expect="$(pwgen -0 12)" + send="'\0033\0143'${expect}" + if send_and_expect "${send}" "${expect}"; then + pipe=$(mktemp -u) + mkfifo ${pipe} + exec 3<>${pipe} + rm ${pipe} + echo Verification succeeded at attempt $i. Unlocking remote drive... - if $GETPWD | head -n1 | ssh -4 ${SSHOPTS} root@{{sshserver}} "cryptsetup-askpass && exit 0" 1>/dev/null 2>&1 > /dev/null; then - echo Unlock successful! - exit 0 - fi + ssh -4 ${SSHOPTS} root@{{sshserver}} "cryptsetup-askpass" <&3 &>/dev/null & + eval ${GETPW} | head -n1 >&3 + + for j in `seq 1 120`; do + sleep 0.5 + if expect '— success'; then + echo Unlock successful. + exit 0 + fi + done + echo Unlock failed... + exit 1 fi done echo Verification failed {{attempts}} times. Giving up...