explicitly set MONKEYSPHERE_GROUP
[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 chmod 0700 "$GNUPGHOME"
32 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$GNUPGHOME"
33
34 # trap to remove tmp dir if break
35 trap "rm -rf $GNUPGHOME" EXIT
36
37 # import the host key into the tmp dir
38 su_monkeysphere_user \
39     "gpg --quiet --import" <"$HOST_KEY_FILE"
40
41 # publish host key
42 su_monkeysphere_user \
43     "gpg --keyserver $KEYSERVER --send-keys '0x${HOST_FINGERPRINT}!'"
44
45 # remove the tmp file
46 trap - EXIT
47 rm -rf "$GNUPGHOME"
48
49 }