summaryrefslogtreecommitdiff
path: root/src/share/mh/add_hostname
blob: c1b32a9cccc3bd7aadbd696c64c2da0ea0ce3749 (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-2009, and are all released under the GPL,
  11. # version 3 or later.
  12. # add hostname user ID to server key
  13. add_hostname() {
  14. local userID
  15. local fingerprint
  16. local tmpuidMatch
  17. local line
  18. local adduidCommand
  19. if [ -z "$1" ] ; then
  20. failure "You must specify a hostname to add."
  21. fi
  22. userID="ssh://${1}"
  23. # test that the desired user ID does not already exist
  24. find_host_userid "$userID" && \
  25. failure "Host userID '$userID' already exists."
  26. if [ "$PROMPT" = "true" ] ; then
  27. printf "The following user ID will be added to the host key:\n %s\nAre you sure you would like to add this user ID? (Y/n) " "$userID" >&2
  28. read OK; OK=${OK:=Y}
  29. if [ "${OK/y/Y}" != 'Y' ] ; then
  30. failure "User ID not added."
  31. fi
  32. else
  33. log debug "adding user ID without prompting."
  34. fi
  35. # execute edit-key script
  36. if PEM2OPENPGP_USAGE_FLAGS=authenticate \
  37. <"$GNUPGHOME_HOST/secring.gpg" \
  38. "$SYSSHAREDIR/keytrans" adduserid \
  39. "$HOST_FINGERPRINT" "$userID" | gpg_host --import ; then
  40. gpg_host --check-trustdb
  41. update_gpg_pub_file
  42. show_key
  43. echo
  44. echo "NOTE: User ID added to key, but key not published."
  45. echo "Run '$PGRM publish-key' to publish the new user ID."
  46. else
  47. failure "Problem adding user ID."
  48. fi
  49. }