Justfile: prototype remote drive unlock
This commit is contained in:
parent
97abdf17e0
commit
2636941546
1 changed files with 37 additions and 10 deletions
47
Justfile
47
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 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"
|
export TESS_ARGS="-c debug_file=/dev/null --psm 4"
|
||||||
|
|
||||||
send_and_compare() {
|
function send() {
|
||||||
local EXPECT="$(pwgen -0 12)"
|
local what="${1:?need something to send}"
|
||||||
ssh -4 ${SSHOPTS} root@{{sshserver}} "echo -e '\0033\0143'${EXPECT}>> /dev/tty0" 1>/dev/null 2>&1
|
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
|
vncdo --server=${VNCSOCK} --password=${VNCPW} --disable-desktop-resizing --nocursor capture $PWD/screenshot.bmp
|
||||||
convert ${MAGICK_ARGS} screenshot.bmp screenshot.tiff
|
convert ${MAGICK_ARGS} screenshot.bmp screenshot.tiff
|
||||||
tesseract ${TESS_ARGS} screenshot.tiff screenshot
|
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
|
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...
|
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
|
ssh -4 ${SSHOPTS} root@{{sshserver}} "cryptsetup-askpass" <&3 &>/dev/null &
|
||||||
echo Unlock successful!
|
eval ${GETPW} | head -n1 >&3
|
||||||
exit 0
|
|
||||||
fi
|
for j in `seq 1 120`; do
|
||||||
|
sleep 0.5
|
||||||
|
if expect '— success'; then
|
||||||
|
echo Unlock successful.
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo Unlock failed...
|
echo Unlock failed...
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo Verification failed {{attempts}} times. Giving up...
|
echo Verification failed {{attempts}} times. Giving up...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue