#!/usr/bin/env bash
set -x
#apt install -y rng-tools gnupg2 

REAL_NAME="Joe Tester"
NAME_COMMENT="with stupid passphrase"
EMAIL="joe@foo.bar"
PASSPHRASE="abc"
EXPIRE_DATE="0"

sudo rngd -b -r /dev/urandom

GNUPGHOME="$(mktemp -d)"
export GNUPGHOME

cat >keydetails <<-EOF
     %echo Generating a basic OpenPGP key
     Key-Type: DSA
     Key-Length: 1024
     Subkey-Type: ELG-E
     Subkey-Length: 1024    
     Name-Real: ${REAL_NAME}
     Name-Comment: ${NAME_COMMENT}
     Name-Email: ${EMAIL}
     Expire-Date: ${EXPIRE_DATE}
     Passphrase: ${PASSPHRASE}
     # Do a commit here, so that we can later print "done" :-)
     %commit
     %echo done
EOF

gpg --batch --full-gen-key keydetails

gpg --list-secret-keys

echo -e "5\ny\n" |  gpg --command-fd 0 --expert --edit-key ${EMAIL} trust;

gpg --list-keys

gpg -e -a -r ${EMAIL} keydetails
