Merge commit 'dkg/master'
[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-2009, and are all released under the GPL, version 3
12 # or later.
13
14 # publish server key to keyserver
15
16 publish_key() {
17
18 local GNUPGHOME
19
20 if [ "$PROMPT" = "true" ] ; then
21     read -p "Really publish host key to $KEYSERVER? (Y/n) " OK; OK=${OK:=Y}
22     if [ "${OK/y/Y}" != 'Y' ] ; then
23         failure "key not published."
24     fi
25 else
26     log debug "publishing key without prompting."
27 fi
28
29 # create a temporary gnupg directory from which to publish the key
30 export GNUPGHOME=$(msmktempdir)
31
32 # trap to remove tmp dir if break
33 trap "rm -rf $GNUPGHOME" EXIT
34
35 # import the host key into the tmp dir
36 su_monkeysphere_user \
37     "gpg --quiet --import" <"$HOST_KEY_FILE"
38
39 # publish host key
40 su_monkeysphere_user \
41     "gpg --keyserver $KEYSERVER --send-keys '0x${HOST_FINGERPRINT}!'"
42
43 # remove the tmp file
44 trap - EXIT
45 rm -rf "$GNUPGHOME"
46
47 }