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.

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