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