#! /bin/sh
# Thin wrapper around GnuPG to get it to use the (experimental) gpg agent
# for authentication, for ease of use.
#
# To fix:
#
# gpg: cancelled by user
# gpg: no default secret key: bad passphrase
# gpg: [stdin]: sign+encrypt failed: bad passphrase
#
# errors when running from a script
#
# Try to figure out what tty to use, if we can
if [ -z "${GPG_TTY}" ]; then 
  GPG_TTY=`/usr/bin/tty`
  if [ "$GPG_TTY" = "not a tty" ]; then
    GPG_TTY=`/usr/bin/tty <&2`
  fi
  if [ "$GPG_TTY" = "not a tty" ]; then
    echo "GPG_TTY must be set in shell (cannot determine automatically)." >&2
    exit 1
  fi
  export GPG_TTY
fi
#echo "TTY is $GPG_TTY" >&2
#echo Executing: /opt/local/bin/gpg --use-agent "$@"
exec /opt/local/bin/gpg --use-agent "$@"
