From 638a70f020f4ccda3deb15e5c697d384e0f705d7 Mon Sep 17 00:00:00 2001 From: Jameson Rollins Date: Mon, 18 Jan 2010 18:22:22 -0500 Subject: add prompt if a service name is already being used then importing a key or adding a name. This can be overridden with the MONKEYSPHERE_PROMPT var. --- src/monkeysphere-host | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 1fa3aea..4f536e2 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -79,9 +79,14 @@ gpg_host() { # list the info about the a key, in colon format, to stdout gpg_host_list_keys() { - gpg_host --list-keys --with-colons --fixed-list-mode \ - --with-fingerprint --with-fingerprint \ - "$1" + if [ "$1" ] ; then + gpg_host --list-keys --with-colons --fixed-list-mode \ + --with-fingerprint --with-fingerprint \ + "$1" + else + gpg_host --list-keys --with-colons --fixed-list-mode \ + --with-fingerprint --with-fingerprint + fi } # edit key scripts, takes scripts on stdin, and keyID as first input @@ -151,6 +156,25 @@ check_key_userid() { grep -q -x -F "$tmpuidMatch" 2>/dev/null } +prompt_userid_exists() { + local userID="$1" + local gpgOut + local fingerprint + + if gpgOut=$(gpg_host_list_keys "=${userID}" 2>/dev/null) ; then + fingerprint=$(echo "$gpgOut" | grep '^fpr:' | cut -d: -f10) + if [ "$PROMPT" = "true" ] ; then + printf "Service name '%s' is already being used by key '%s'.\nAre you sure you want to use it again? (y/N) " "$fingerprint" "$userID" >&2 + read OK; OK=${OK:=N} + if [ "${OK/y/Y}" != 'Y' ] ; then + failure "Service name not added." + fi + else + log info "Key '%s' is already using the service name '%s'." "$fingerprint" "$userID" >&2 + fi + fi +} + # run command looped over keys multi_key() { local cmd="$1" -- cgit v1.2.3