summaryrefslogtreecommitdiff
path: root/src/share/mh/set_expire
blob: 371cd76b540df1e0fb31a03bc66fe599fb4aeeb2 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host set-expire subcommand
  4. #
  5. # This is a function to set the expiration date of the monkeysphere
  6. # host key.
  7. #
  8. # The monkeysphere scripts are written by:
  9. # Jameson Rollins <jrollins@finestructure.net>
  10. # Jamie McClelland <jm@mayfirst.org>
  11. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  12. #
  13. # They are Copyright 2008-2010, and are all released under the GPL,
  14. # version 3 or later.
  15. set_expire() {
  16. local extendBy
  17. local keyID
  18. local formatMsg='
  19. The possibilities are:
  20. 0 = key does not expire
  21. <n> = key expires in n days
  22. <n>w = key expires in n weeks
  23. <n>m = key expires in n months
  24. <n>y = key expires in n years'
  25. if [ -z "$1" ] ; then
  26. failure "Must specify expiration.$formatMsg"
  27. fi
  28. extendBy="$1"
  29. shift
  30. if ! <<<"$extendBy" egrep -q '^[[:digit:]]+[wmy]?$' ; then
  31. failure "'$extendBy' is not a valid expiration date.$formatMsg"
  32. fi
  33. keyID=$(check_key_input "$@")
  34. if [ "$PROMPT" != "false" ] ; then
  35. printf "Are you sure you want to change the expiration on key '$keyID' by '%s'? (Y/n) " "$extendBy" >&2
  36. read OK; OK=${OK:-Y}
  37. if [ "${OK/y/Y}" != 'Y' ] ; then
  38. failure "expiration not set."
  39. fi
  40. else
  41. log debug "extending without prompting."
  42. fi
  43. log info "setting key expiration to ${extendBy}."
  44. log debug "executing key expire script..."
  45. gpg_host_edit "0x${keyID}!" expire <<EOF
  46. $extendBy
  47. save
  48. EOF
  49. update_pgp_pub_file
  50. if [ 0 == "$extendBy" ] ; then
  51. log info "Key ${keyID} no longer expires."
  52. else
  53. if expiry=$(gpg_host_list_keys "${keyID}" | grep ^pub: | head -n1 | cut -f7 -d: ) ; then
  54. log info "Key ${keyID} now expires at $(print_date_from_seconds_since_the_epoch ${expiry})"
  55. else
  56. log error "Failed to retrieve new expiration date for key ${keyID}"
  57. fi
  58. fi
  59. log info <<EOF
  60. NOTE: Key expiration date adjusted, but not yet published.
  61. Run '$PGRM publish-key' to publish the new expiration date.
  62. EOF
  63. }