Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Last active April 8, 2024 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderankin/a4509b6ccdbcf809eac555aa268ee5df to your computer and use it in GitHub Desktop.
Save alexanderankin/a4509b6ccdbcf809eac555aa268ee5df to your computer and use it in GitHub Desktop.
gnupg delenda est
#!/usr/bin/expect
# set timeout 120 # debugging
foreach {
name
email
} $argv break
# Check if the variable is set
if {![info exists name]} { error "needs name" }
if {![info exists email]} { error "needs email" }
spawn gpg --passphrase-fd 0 --pinentry-mode loopback --full-generate-key
sleep 0.5
send -- "\n"
# rsa and rsa
expect "Your selection?*"
send -- "1\n"
expect "What keysize do you want?*"
send -- "4096\n"
expect "Key is valid for?*"
send -- "1y\n"
expect "Is this correct?*"
send -- "y\n"
# simple prompt is these two:
expect "Real name: "
send -- "$name\n"
expect "Email address: "
send -- "$email\n"
expect "Comment: "
send -- "\n"
expect "Change*"
send -- "O\n"
# expect "*Passphrase:*"
# send -- "this-is-not-a-real-password"
# sleep 0.1
# send -- "\t"
# send -- "\t"
# send -- "\n"
# expect "*Please re-enter:*"
# send -- "this-is-not-a-real-password\n"
expect "*public and secret*"
# expect "public and secret key created and signed."
#!/usr/bin/env bash
if [[ "$0" != "$BASH_SOURCE" ]]; then echo "no sourcing">&2; return 1; fi;
full="$(readlink -f "$BASH_SOURCE")"; dir=${full%\/*}; file=${full##*/};
set -eu -o pipefail
name="$1"
email="$2"
file_base="$3"
tmp=$(mktemp -d)
clean() { echo clean; rm -rfv $tmp || true; }
trap clean EXIT
GNUPGHOME="$tmp" $dir/expect-gnupg-keyring.expect.sh "$name" "$email"
GNUPGHOME="$tmp" gpg --export "$email" | gpg --enarmor | tee "$file_base".gpg
GNUPGHOME="$tmp" gpg --export-secret-keys "$email" | gpg --enarmor | tee "$file_base".gpg.sec

i cannot believe this works and cannot wait to live in a world without gpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment