Merge commit 'mlcastle/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     printf "Really publish host key to $KEYSERVER? (Y/n) " >&2
22     read OK; OK=${OK:=Y}
23     if [ "${OK/y/Y}" != 'Y' ] ; then
24         failure "key not published."
25     fi
26 else
27     log debug "publishing key without prompting."
28 fi
29
30 # create a temporary gnupg directory from which to publish the key
31 export GNUPGHOME=$(msmktempdir)
32 chmod 0700 "$GNUPGHOME"
33 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$GNUPGHOME"
34
35 # trap to remove tmp dir if break
36 trap "rm -rf $GNUPGHOME" EXIT
37
38 # import the host key into the tmp dir
39 su_monkeysphere_user \
40     "gpg --quiet --import" <"$HOST_KEY_FILE"
41
42 # publish host key
43 su_monkeysphere_user \
44     "gpg --keyserver $KEYSERVER --send-keys '0x${HOST_FINGERPRINT}!'"
45
46 # remove the tmp file
47 trap - EXIT
48 rm -rf "$GNUPGHOME"
49
50 }