#!/usr/bin/expect --
# -*- mode: tcl; tab-width: 8; encoding: utf-8-unix -*-

set ROLE gpgkey
set PREFIX /usr/local

set timeout 30

#? spawn /usr/local/bin/pinentry.py
spawn /usr/local/bin/pinentry_gridfire.py

expect "OK Your orders please"
send_user   "OPTION grab\n"
send   "OPTION grab\n"
expect "OK"
send_user   "OPTION ttyname=/dev/pts/6\n"
send   "OPTION ttyname=/dev/pts/6\n"
expect "OK"
send_user   "OPTION ttytype=xterm\n"
send   "OPTION ttytype=xterm\n"
expect "OK"
send_user   "OPTION lc-ctype=en_US.UTF-8\n"
send   "OPTION lc-ctype=en_US.UTF-8\n"
expect "OK"
send_user   "OPTION lc-messages=en_US.UTF-8\n"
send   "OPTION lc-messages=en_US.UTF-8\n"
expect "OK"
send_user   "OPTION allow-external-password-cache\n"
send   "OPTION allow-external-password-cache\n"
expect "OK"
send_user   "OPTION default-ok=_OK\n"
send   "OPTION default-ok=_OK\n"
expect "OK"
send_user   "OPTION default-cancel=_Cancel\n"
send   "OPTION default-cancel=_Cancel\n"
expect "OK"
send_user   "OPTION default-yes=_Yes\n"
send   "OPTION default-yes=_Yes\n"
expect "OK"
send_user   "OPTION default-no=_No\n"
send   "OPTION default-no=_No\n"
expect "OK"
send_user   "OPTION default-prompt=PIN:\n"
send   "OPTION default-prompt=PIN:\n"
expect "OK"
send_user   "OPTION default-pwmngr=_Save in password manager\n"
send   "OPTION default-pwmngr=_Save in password manager\n"
expect "OK"
send_user   "OPTION default-cf-visi=Do you really want to make your passphrase visible on the screen?\n"
send   "OPTION default-cf-visi=Do you really want to make your passphrase visible on the screen?\n"
expect "OK"
send_user   "OPTION default-tt-visi=Make passphrase visible\n"
send   "OPTION default-tt-visi=Make passphrase visible\n"
expect "OK"
send_user   "OPTION default-tt-hide=Hide passphrase\n"
send   "OPTION default-tt-hide=Hide passphrase\n"
expect "OK"
send_user   "GETINFO pid\n"
send   "GETINFO pid\n"
expect "D 14309"
expect "OK"
send_user   "SETKEYINFO u/S9464F2C2825D2FE3\n"
send   "SETKEYINFO u/S9464F2C2825D2FE3\n"
expect "OK"
send_user   "SETDESC Enter passphrase%0A\n"
send   "SETDESC Enter passphrase%0A\n"
expect "OK"
send_user   "SETPROMPT Passphrase\n"
send   "SETPROMPT Passphrase\n"
expect "OK"
send_user   "GETPIN\n"
send   "GETPIN\n"
expect "D testing!"
expect "OK"
send_user   "BYE\n"
send   "BYE\n"
expect "OK closing connection"

expect -re .+ {
    exp_continue
  } timeout {
    exit 1
  } eof {
    exit 0
  }

# expect -r .+ {send "\r"}
