canonicalize prompting to prompt if MONKEYSPHERE_PROMPT != 'false'
[monkeysphere.git] / src / share / mh / publish_key
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host publish-key subcommand
5 #
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 #
11 # They are Copyright 2008-2010, and are all released under the GPL,
12 # version 3 or later.
13
14 # publish keys to keyserver
15
16 publish_key() {
17
18 local keyID="$1"
19 local GNUPGHOME
20
21 if [ "$PROMPT" != "false" ] ; then
22     printf "Really publish key '$keyID' to $KEYSERVER? (Y/n) " >&2
23     read OK; OK=${OK:=Y}
24     if [ "${OK/y/Y}" != 'Y' ] ; then
25         failure "key not published."
26     fi
27 else
28     log debug "publishing key '$keyID' without prompting."
29 fi
30
31 # create a temporary gnupg directory from which to publish the key
32 export GNUPGHOME=$(msmktempdir)
33 chmod 0700 "$GNUPGHOME"
34 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$GNUPGHOME"
35
36 # trap to remove tmp dir if break
37 trap "rm -rf $GNUPGHOME" EXIT
38
39 # import the key into the tmp dir
40 su_monkeysphere_user \
41     "gpg --quiet --import" <"$HOST_KEY_FILE"
42
43 # publish key
44 su_monkeysphere_user \
45     "gpg --keyserver $KEYSERVER --send-keys '0x${keyID}!'"
46
47 # remove the tmp file
48 trap - EXIT
49 rm -rf "$GNUPGHOME"
50
51 }