Skip to content

Instantly share code, notes, and snippets.

@bynect
Created September 8, 2023 15:16
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 bynect/60cb1427db6c6053ef74a69409d821d3 to your computer and use it in GitHub Desktop.
Save bynect/60cb1427db6c6053ef74a69409d821d3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# NOTE: This script exports only one uid
key_pattern=
remote_host=
remote_path=/var/www/html/.well-known/openpgpkey/hu/
for item in $(gpg --list-secret-keys --with-colons ${key_pattern:- } \
| awk -F: '($1 == "sec" && $2 == "u") { print $5}'); do
wkd_hash=$(gpg --with-wkd-hash --fingerprint "$item" \
| grep -A 1 '^uid' \
| tail -n 1 \
| tr -d '[[:space:]]')
#this saves the files locally
#gpg --export --no-armor "$item" > "${wkd_hash%%@*}"
#echo "Exported key $item to file $( realpath "${wkd_hash%%@*}")"
#this sends them directly to the server
#gpg --no-armor --export "$item" | ssh "$remote_host" "cat > $remote_path/${wkd_hash%%@*}"
echo "Exported key $item to file $remote_path/${wkd_hash%%@*} on host '$remote_host'"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment