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