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.

71 lines
2.2 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. set -e
  11. service_def=$(get_compose_service_def "$SERVICE_NAME")
  12. USER_EMAIL=$(echo "$service_def" | shyaml get-value options.email 2>/dev/null) || {
  13. err "No ${WHITE}email${NORMAL} value in ${DARKYELLOW}$SERVICE_NAME${NORMAL} compose's ${WHITE}options${NORMAL}."
  14. exit 1
  15. }
  16. yaml_opt_bash_env() {
  17. local prefix="$1" key value
  18. while read-0 key value; do
  19. new_prefix="${prefix}_${key^^}"
  20. if [[ "$(echo "$value" | shyaml get-type)" == "struct" ]]; then
  21. echo "$value" | yaml_opt_bash_env "${new_prefix}"
  22. else
  23. printf "%s\0%s\0" "${new_prefix}" "$value"
  24. fi
  25. done < <(shyaml key-values-0)
  26. }
  27. yaml_opt_bash_env_ignore_first_level() {
  28. local prefix="$1" key value
  29. while read-0 key value; do
  30. new_prefix="${prefix}_${key^^}"
  31. if [[ "$(echo "$value" | shyaml get-type)" == "struct" ]]; then
  32. echo "$value" | yaml_opt_bash_env "${new_prefix}"
  33. fi
  34. done < <(shyaml key-values-0)
  35. }
  36. config="
  37. $SERVICE_NAME:
  38. environment:
  39. LETSENCRYPT_USER_MAIL: $USER_EMAIL"
  40. while read-0 key value; do
  41. config+="$(printf "\n %s: %s" "$key" "$value")"
  42. done < <(yaml_opt_bash_env_ignore_first_level LEXICON < <(echo "$service_def" | shyaml -y get-value options))
  43. ## XXXvlab: this is very temporary, we should change image to support more
  44. ## than one provider (cf: https://github.com/adferrand/docker-letsencrypt-dns/issues/24)
  45. first_key=
  46. while read-0 key value; do
  47. [[ "$(echo "$value" | shyaml get-type)" == "struct" ]] && {
  48. first_key="$key"
  49. break
  50. }
  51. done < <(echo "$service_def" | shyaml key-values-0 options)
  52. config+=$(echo -en "\n LEXICON_PROVIDER: $first_key")
  53. init-config-add "$config"
  54. mkdir -p "$SERVICE_DATASTORE/etc/letsencrypt"
  55. touch "$SERVICE_DATASTORE/etc/letsencrypt/domains.conf"