summaryrefslogtreecommitdiff
path: root/dehydrated/hook.sh
blob: 2aa257c56e1c62acabbd0e665a7205697decb65f (plain)
  1. #!/bin/sh
  2. set -e
  3. ACTION=$1; shift
  4. REALM=$(cat /etc/local-ORG/realm)
  5. # resolve hostnames of service installed and registered with Redpill
  6. servicehosts() {
  7. SERVICE=$1; shift
  8. for binary in "$@"; do
  9. which -- "$binary" || exit
  10. done
  11. cat "/etc/local-REDPILL/$REALM/${SERVICE}host" \
  12. "/etc/local-REDPILL/$REALM/${SERVICE}althosts" \
  13. 2> /dev/null \
  14. | perl -0777 -pe 's/\s*\#.*//gm;s/^\s+//;s/\s+$//;s/\s+/|/g'
  15. }
  16. MAILHOSTS=$(servicehosts mail postconf)
  17. MAILHOSTS=$(servicehosts chat ejabberdctl)
  18. case "$ACTION" in
  19. deploy_challenge) ;;
  20. clean_challenge) ;;
  21. # deploy_cert)
  22. deploy_cert|unchanged_cert)
  23. DOMAIN="$1"; KEYFILE="$2"; FULLCHAINFILE="$4"
  24. case "$DOMAIN" in
  25. "$MAILHOSTS")
  26. cat "$FULLCHAINFILE" > "/etc/dovecot/$DOMAIN.pem"
  27. sg dovecot -c "umask 027; cat '$KEYFILE' > '/etc/dovecot/private/$DOMAIN.pem'"
  28. #service dovecot force-reload
  29. ;;
  30. "$CHATHOSTS")
  31. sg ejabberd -c "umask 027; cat '$KEYFILE' '$FULLCHAINFILE' > '/etc/ejabberd/$DOMAIN.pem'"
  32. #service ejabberd force-reload
  33. ;;
  34. esac
  35. ;;
  36. unchanged_cert) ;;
  37. *)
  38. >&2 echo "ERROR: unsupported action \"$ACTION\""
  39. exit 1
  40. ;;
  41. esac