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.

94 lines
3.1 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. . lib/common
  11. # Please note that postgres detect on its own if its datadir needs to be populated
  12. service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
  13. options="$(e "$service_def" | shyaml -y get-value options)" || true
  14. SYNAPSE_OPTIONS=(
  15. report-stats:bool ## Enable anon stat reporting back to the Matrix project
  16. enable-registration:bool ## Enable registration on the Synapse instance.
  17. allow-guest:bool ## allow guest joining this server.
  18. event-cache-size:size ## event cache size [default 10K].
  19. max-upload-size:size ## max upload size [default 10M].
  20. ## shared secrets
  21. registration-shared-secret:string ## registrering users if registration is disable.
  22. macaroon-secret-key:string ## secret for signing access tokens to the server.
  23. ## recaptcha
  24. recaptcha-public-key:string ## required in order to enable recaptcha upon registration
  25. recaptcha-private-key:string ## required in order to enable recaptcha upon registration
  26. ## turn
  27. turn-uris:string ## coma-separated list of TURN uris to enable TURN for this homeserver.
  28. turn-secret:string ## TURN shared secret if required.
  29. )
  30. OPTIONS_CONCAT=" ${SYNAPSE_OPTIONS[*]} "
  31. yaml_opts=()
  32. while read-0 key val; do
  33. key_option="$key"
  34. case "$OPTIONS_CONCAT" in
  35. *" ${key_option}:bool "*)
  36. case "${val,,}" in
  37. true|ok|yes|y|1)
  38. val="\"yes\""
  39. ;;
  40. false|ko|nok|no|n|0)
  41. val="\"no\""
  42. ;;
  43. *)
  44. die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value."
  45. ;;
  46. esac
  47. ;;
  48. *" ${key_option}:numeric "*)
  49. if ! is_int "$val"; then
  50. die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value."
  51. fi
  52. ;;
  53. *" ${key_option}:string "*)
  54. :
  55. ;;
  56. *" ${key_option}:size "*)
  57. [[ "${val}" =~ ^[0-9\.]+[KkMmGgTtPp]$ ]] || {
  58. die "Unknown size specification '${val}'."
  59. }
  60. ;;
  61. *)
  62. case "${key//_/-}" in
  63. *) die "Unknown option ${WHITE}$key$NORMAL.";;
  64. esac
  65. continue
  66. ;;
  67. esac
  68. yaml_opts+=("$key" "$val")
  69. done < <(e "$options" | yaml_opt_flatten)
  70. config="\
  71. $SERVICE_NAME:
  72. environment:
  73. SYNAPSE_NO_TLS: \"yes\"
  74. "
  75. while read-0 key value; do
  76. key=${key//-/_}
  77. config+="$(printf "\n SYNAPSE_%s: %s" "${key^^}" "$value")"
  78. done < <(array_values_to_stdin yaml_opts)
  79. init-config-add "$config"