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