summaryrefslogtreecommitdiff
path: root/src/share/mh/add_name
blob: 39ebaceeb0dfe684b8713b547cc08af31f61efa5 (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. # test that a key with that user ID does not already exist
  30. prompt_userid_exists "$serviceName"
  31. check_service_name "$serviceName"
  32. if [ "$PROMPT" != "false" ] ; then
  33. 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
  34. read OK; OK=${OK:=Y}
  35. if [ "${OK/y/Y}" != 'Y' ] ; then
  36. failure "Service name not added."
  37. fi
  38. else
  39. log debug "adding service name without prompting."
  40. fi
  41. # execute edit-key script
  42. if PEM2OPENPGP_USAGE_FLAGS=authenticate \
  43. <"$GNUPGHOME_HOST/secring.gpg" \
  44. "$SYSSHAREDIR/keytrans" adduserid "$keyID" "$serviceName" \
  45. | gpg_host --import ; then
  46. gpg_host --check-trustdb
  47. update_pgp_pub_file
  48. show_key "$keyID"
  49. echo
  50. echo "NOTE: Service name added to key, but key not published."
  51. echo "Run '$PGRM publish-key' to publish the new service name."
  52. else
  53. failure "Problem adding service name."
  54. fi
  55. }