summaryrefslogtreecommitdiff
path: root/src/share/mh/add_name
blob: b5922db412c2a8c2f1f701bed4a65d4290c8c7cb (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host add-hostname 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. # add servicename user ID to server key
  13. add_name() {
  14. local serviceName
  15. local keyID
  16. local fingerprint
  17. local tmpuidMatch
  18. local line
  19. local adduidCommand
  20. if [ -z "$1" ] ; then
  21. failure "You must specify a service name to add."
  22. fi
  23. serviceName="$1"
  24. shift
  25. keyID=$(check_key_input "$@")
  26. # test that the desired user ID does not already exist
  27. check_key_userid "$keyID" "$serviceName" && \
  28. failure "Service name '$serviceName' already exists on key '$keyID'."
  29. check_service_name "$serviceName"
  30. if [ "$PROMPT" = "true" ] ; then
  31. printf "The following service name will be added to key '$keyID':\n %s\nAre you sure you would like to add this service name? (Y/n) " "$serviceName" >&2
  32. read OK; OK=${OK:=Y}
  33. if [ "${OK/y/Y}" != 'Y' ] ; then
  34. failure "Service name not added."
  35. fi
  36. else
  37. log debug "adding service name without prompting."
  38. fi
  39. # execute edit-key script
  40. if PEM2OPENPGP_USAGE_FLAGS=authenticate \
  41. <"$GNUPGHOME_HOST/secring.gpg" \
  42. "$SYSSHAREDIR/keytrans" adduserid "$keyID" "$serviceName" \
  43. | gpg_host --import ; then
  44. gpg_host --check-trustdb
  45. update_gpg_pub_file
  46. show_key "$keyID"
  47. echo
  48. echo "NOTE: Service name added to key, but key not published."
  49. echo "Run '$PGRM publish-key' to publish the new service name."
  50. else
  51. failure "Problem adding service name."
  52. fi
  53. }