summaryrefslogtreecommitdiff
path: root/src/share/mh/add_hostname
blob: ec741ee5a114f8eb99cfc3e99f15d6a202c91a18 (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 > /dev/null && \
  25. failure "Host userID '$userID' already exists."
  26. if [ "$PROMPT" = "true" ] ; then
  27. cat <<EOF
  28. The following user ID will be added to the host key:
  29. $userID
  30. EOF
  31. read -p "Are you sure you would like to add this user ID? (Y/n) " OK; OK=${OK:=Y}
  32. if [ "${OK/y/Y}" != 'Y' ] ; then
  33. failure "User ID not added."
  34. fi
  35. else
  36. log debug "adding user ID without prompting."
  37. fi
  38. # edit-key script command to add user ID
  39. adduidCommand=$(cat <<EOF
  40. adduid
  41. $userID
  42. save
  43. EOF
  44. )
  45. # execute edit-key script
  46. if echo "$adduidCommand" | gpg_host_edit ; then
  47. update_gpg_pub_file
  48. show_key
  49. echo
  50. echo "NOTE: User ID added to key, but key not published."
  51. echo "Run '$PGRM publish-key' to publish the new user ID."
  52. else
  53. failure "Problem adding user ID."
  54. fi
  55. }