From 4f1a27132876af5df548546acd0a57918cdba7a6 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 16 Sep 2020 17:59:37 -0400 Subject: implement subcommand "cryptonomic gpg" --- selfpublish.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/selfpublish.sh b/selfpublish.sh index da906c9..f1c8af7 100644 --- a/selfpublish.sh +++ b/selfpublish.sh @@ -108,6 +108,117 @@ EOF cat <}" in + uid:u:*.${domain}) $action "$@";; + esac +} + +match_first_secret_key() +{ + action=$1 + shift + is_secret_key || return + case "$1:$2" in + fpr:*) $action "$@" + process_colons_break=y + ;; + esac +} + +show_fpr() +{ + echo ${CURRENT_FPR} +} + +find_secret_key_with_domain() +{ + process_colons match_domain "$1" show_fpr +} + +force() { [ "$FORCE" ]; } +verbose() +{ + if [ "$VERBOSE" ] + then + "$@" + fi +} + +set -e + +# 1. GET CRYPTONOMIC UID +cryptonomic_hostname=$(cryptonomic hostname) +[ "$cryptonomic_hostname" ] +username=$(id -un) +[ "$username" ] +uid=${username}@${cryptonomic_hostname} + +# 2. CHECK IF EXISTING SECRET KEY +t=$(gpg -K --with-colons) +if [ "$t" ] +then + # 3. CHECK IF EXISTING KEY HAS UID + if gpg -K --with-colons | find_secret_key_with_domain "${cryptonomic_hostname#*.}" | grep -q . && ! force + then + exit + fi + + # 4. ADD UID TO EXISTING KEY + gpg_default_key=$(gpg -K --with-colons | process_colons match_first_secret_key show_fpr) + [ "$gpg_default_key" ] + gpg --quick-add-uid "$gpg_default_key" "$uid" || force + verbose gpg -K "$gpg_default_key" + exit 0 +else + # 2.5 GENERATE NEW KEY + gpg --batch --passphrase '' --quick-generate-key "$uid" + verbose gpg -K "$uid" + exit 0 +fi EOF control_file_file /usr/bin/cryptonomic 755 <<'EOF' #!/bin/dash @@ -161,8 +272,12 @@ then su -c "$(bash -c 'printf "%q " "$@"' bash "$@")" fi +elif [ -f /usr/lib/cryptonomic/cryptonomic-"$1" ] +then + exec /usr/lib/cryptonomic/cryptonomic-"$1" "$@" + else - echo "Usage: $0 [dyndns|hostname]" >&2 + echo "Usage: $0 [dyndns|hostname|gpg]" >&2 exit 1 fi EOF -- cgit v1.2.3