i cannot believe this works and cannot wait to live in a world without gpg
Last active
April 8, 2024 14:38
-
-
Save alexanderankin/a4509b6ccdbcf809eac555aa268ee5df to your computer and use it in GitHub Desktop.
gnupg delenda est
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
# set timeout 120 # debugging | |
foreach { | |
name | |
} $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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment