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.

76 lines
1.9 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. DATA_DIRS=$(relation-get data_dirs 2>/dev/null | shyaml get-values 2>/dev/null) || true
  7. LOCATION=$(relation-get location 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_BASE_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_BASE_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_BASE_CHARM_NAME:
  31. volumes:
  32. - ${SSL_CA_CERT_LOCATION}:${SSL_CA_CERT}
  33. "
  34. fi
  35. export CREDS
  36. apache_ssl_add "$DOMAIN"
  37. if [ "$LOCATION" ]; then
  38. if [ -d "$LOCATION" -a ! -d "$LOCATION/.git" ]; then
  39. err "Hum, location '$LOCATION' does not seem to be a git directory."
  40. exit 1
  41. fi
  42. if ! [ -d "$LOCATION/.git" ]; then
  43. BRANCH=$(relation-get branch)
  44. BRANCH=${BRANCH:-master}
  45. SOURCE=$(relation-get source)
  46. parent="$(dirname "$LOCATION")"
  47. (
  48. mkdir -p "$parent" && cd "$parent"
  49. git clone -b "$BRANCH" "$SOURCE" "$(basename "$LOCATION")"
  50. )
  51. fi
  52. apache_code_dir "$DOMAIN" "$LOCATION"
  53. else
  54. mkdir -p "$SERVICE_DATASTORE/var/www/${DOMAIN}" || return 1
  55. config-add "
  56. $MASTER_BASE_CHARM_NAME:
  57. volumes:
  58. - $DATASTORE/$BASE_CHARM_NAME/var/www/${DOMAIN}:/var/www/${DOMAIN}
  59. "
  60. fi
  61. if [ "$DATA_DIRS" ]; then
  62. apache_data_dir "$DOMAIN" "$DATA_DIRS"
  63. fi