fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. #!/bin/bash
  2. ## Should be executable N time in a row with same result.
  3. . lib/common
  4. set -e
  5. DOMAIN=$(relation-get domain)
  6. TARGET=$(relation-get target)
  7. APACHE_CUSTOM_RULES=$(relation-get apache-custom-rules 2>/dev/null) || true
  8. CREDS=$(relation-get creds 2>/dev/null) || true
  9. SERVER_ALIAS=$(relation-get server-alias 2>/dev/null) || true
  10. export SERVER_ALIAS
  11. if SSL_CERT_LOCATION=$(relation-get ssl-cert-file 2>/dev/null); then
  12. SSL_CERT=/etc/ssl/certs/${DOMAIN}.pem
  13. config-add "\
  14. $MASTER_TARGET_CHARM_NAME:
  15. volumes:
  16. - ${SSL_CERT_LOCATION}:${SSL_CERT}
  17. "
  18. fi
  19. if SSL_KEY_LOCATION=$(relation-get ssl-key-file 2>/dev/null); then
  20. SSL_KEY=/etc/ssl/private/${DOMAIN}.key
  21. config-add "\
  22. $MASTER_TARGET_CHARM_NAME:
  23. volumes:
  24. - ${SSL_KEY_LOCATION}:${SSL_KEY}
  25. "
  26. fi
  27. if SSL_CA_CERT_LOCATION=$(relation-get ssl-ca-cert-file 2>/dev/null); then
  28. SSL_CA_CERT=/etc/ssl/cert/${DOMAIN}-ca.pem
  29. config-add "\
  30. $MASTER_TARGET_CHARM_NAME:
  31. volumes:
  32. - ${SSL_CA_CERT_LOCATION}:${SSL_CA_CERT}
  33. "
  34. fi
  35. control=$(echo "$DOMAIN%$TARGET%$APACHE_CUSTOM_RULES%$CREDS%$SSL_CERT%$SSL_CA_CERT%$SSL_KEY" | md5_compat)
  36. [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
  37. ## XXXvlab: could probably figure target ourselves
  38. apache_ssl_proxy_add "$DOMAIN" "$TARGET" "$APACHE_CUSTOM_RULES" "$CREDS"
  39. relation-set control "$control"
  40. info "Configured $DARKYELLOW$BASE_CHARM_NAME$NORMAL for proxy access."