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.

214 lines
6.5 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. #if ! [ -f "$HOST_CONFIG_FILE" ]; then
  12. # cfg-init
  13. #fi
  14. #exit 17
  15. # Please note that postgres detect on its own if its datadir needs to be populated
  16. service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
  17. options="$(e "$service_def" | shyaml -y get-value options)" || true
  18. SYNAPSE_OPTIONS=(
  19. server_name:string ## The server name
  20. report_stats:bool ## Enable anon stat reporting back to the Matrix project
  21. enable_registration:bool ## Enable registration on the Synapse instance.
  22. allow_guest_access:bool ## allow guest joining this server.
  23. event_cache_size:size ## event cache size [default 10K].
  24. max_upload_size:size ## max upload size [default 10M].
  25. ## shared secrets
  26. registration_shared_secret:string ## registrering users if registration is disable.
  27. macaroon_secret_key:string ## secret for signing access tokens to the server.
  28. ## recaptcha
  29. recaptcha_public_key:string ## required to have recaptcha upon registration
  30. recaptcha_private_key:string ## required to have recaptcha upon registration
  31. enable_registration_captcha:bool ## required to have recaptcha upon registration
  32. recaptcha_siteverify_api:string
  33. ## others
  34. soft_file_limit:numeric
  35. rc_messages_per_second:float
  36. rc_message_burst_count:float
  37. federation_rc_window_size:numeric
  38. federation_rc_sleep_limit:numeric
  39. federation_rc_sleep_delay:numeric
  40. federation_rc_reject_limit:numeric
  41. federation_rc_concurrent:numeric
  42. max_image_pixels:size
  43. dynamic_thumbnails:bool
  44. url_preview_enabled:bool
  45. max_spider_size:size
  46. bcrypt_rounds:numeric
  47. enable_group_creation:bool
  48. trusted_third_party_id_servers:sequence
  49. enable_metrics:bool
  50. room_invite_state_types:sequence
  51. expire_access_token:bool
  52. key_refresh_interval:string
  53. perspectives:struct
  54. password_config:struct
  55. ## NOT SUPPORTED YET
  56. #thumbnail_sizes
  57. )
  58. OPTIONS_CONCAT=" ${SYNAPSE_OPTIONS[*]} "
  59. yaml_opts=()
  60. while read-0 key val; do
  61. key_option="$key"
  62. case "$OPTIONS_CONCAT" in
  63. *" ${key_option}:bool "*)
  64. case "${val,,}" in
  65. true|ok|yes|y|1)
  66. val="\"yes\""
  67. ;;
  68. false|ko|nok|no|n|0)
  69. val="\"no\""
  70. ;;
  71. *)
  72. die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value."
  73. ;;
  74. esac
  75. ;;
  76. *" ${key_option}:numeric "*)
  77. if ! is_int "$val"; then
  78. die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value."
  79. fi
  80. ;;
  81. *" ${key_option}:float "*)
  82. if ! is_float "$val"; then
  83. die "Invalid value for ${WHITE}$key$NORMAL, please use float value."
  84. fi
  85. ;;
  86. *" ${key_option}:struct "*)
  87. val_type=$(e "$val" | shyaml get-type) || return 1
  88. if [ "$val_type" != "struct" ]; then
  89. die "Invalid value for ${WHITE}$key$NORMAL, please use struct value."
  90. fi
  91. ;;
  92. *" ${key_option}:sequence "*)
  93. val_type=$(e "$val" | shyaml get-type) || return 1
  94. if [ "$val_type" != "sequence" ]; then
  95. die "Invalid value for ${WHITE}$key$NORMAL, please use sequence value."
  96. fi
  97. ;;
  98. *" ${key_option}:string "*)
  99. :
  100. ;;
  101. *" ${key_option}:size "*)
  102. [[ "${val}" =~ ^[0-9\.]+[KkMmGgTtPp]$ ]] || {
  103. die "Unknown size specification '${val}'."
  104. }
  105. ;;
  106. *)
  107. case "${key//_/-}" in
  108. *) die "Unknown option ${WHITE}$key$NORMAL.";;
  109. esac
  110. continue
  111. ;;
  112. esac
  113. yaml_opts+=("$key" "$val")
  114. done < <(e "$options" | shyaml key-values-0)
  115. setup_dirs || exit 1
  116. cfg-base || exit 1
  117. cfg-merge "$options" || exit 1
  118. HOST_KEY_DIR=$SERVICE_DATASTORE$DATA_DIR/keys
  119. for name_secret in registration_shared_secret macaroon_secret_key; do
  120. secret=$(e "$options" | shyaml -q get-value "$name_secret") || true
  121. if [ "$secret" == "None" ]; then
  122. secret=""
  123. fi
  124. coming_from_file=
  125. key_file="$HOST_KEY_DIR/${name_secret}.key"
  126. if [ -z "$secret" ]; then
  127. if [ -e "$key_file" ]; then
  128. secret="$(cat "$key_file")"
  129. coming_from_file=true
  130. else
  131. secret="$(gen_password 64)"
  132. fi
  133. cfg-merge "${name_secret}: \"$secret\"" || exit 1
  134. fi
  135. if [ -z "$coming_from_file" ]; then
  136. e "$secret" > "$key_file"
  137. chown -v "$uid:$gid" "$key_file" &&
  138. chmod -v 600 "$key_file" || exit 1
  139. fi
  140. done
  141. ## XXXvlab: what to do with appservices ?
  142. # environ["SYNAPSE_APPSERVICES"] = glob.glob("/data/appservices/*.yaml")
  143. # {% if SYNAPSE_APPSERVICES %}
  144. # app_service_config_files:
  145. # {% for appservice in SYNAPSE_APPSERVICES %} - "{{ appservice }}"
  146. # {% endfor %}
  147. # {% else %}
  148. # app_service_config_files: []
  149. # {% endif %}
  150. # ## Turn ##
  151. # {% if SYNAPSE_TURN_URIS %}
  152. # turn_uris:
  153. # {% for uri in SYNAPSE_TURN_URIS.split(',') %} - "{{ uri }}"
  154. # {% endfor %}
  155. # turn_shared_secret: "{{ SYNAPSE_TURN_SECRET }}"
  156. # turn_user_lifetime: "1h"
  157. # turn_allow_guests: True
  158. # {% else %}
  159. # turn_uris: []
  160. # turn_shared_secret: "YOUR_SHARED_SECRET"
  161. # turn_user_lifetime: "1h"
  162. # turn_allow_guests: True
  163. # {% endif %}
  164. ## XXXvlab: for SMTP relation
  165. # {% if SYNAPSE_SMTP_HOST %}
  166. # email:
  167. # enable_notifs: false
  168. # smtp_host: "{{ SYNAPSE_SMTP_HOST }}"
  169. # smtp_port: {{ SYNAPSE_SMTP_PORT or "25" }}
  170. # smtp_user: "{{ SYNAPSE_SMTP_USER }}"
  171. # smtp_pass: "{{ SYNAPSE_SMTP_PASSWORD }}"
  172. # require_transport_security: False
  173. # notif_from: "{{ SYNAPSE_SMTP_FROM or "hostmaster@" + SYNAPSE_SERVER_NAME }}"
  174. # app_name: Matrix
  175. # # if template_dir is unset, uses the example templates that are part of
  176. # # the Synapse distribution.
  177. # #template_dir: res/templates
  178. # notif_template_html: notif_mail.html
  179. # notif_template_text: notif_mail.txt
  180. # notif_for_new_users: True
  181. # riot_base_url: "https://{{ SYNAPSE_SERVER_NAME }}"
  182. # {% endif %}