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.

251 lines
4.9 KiB

  1. # -*- mode: shell-script -*-
  2. yaml_opt_flatten() {
  3. local prefix="$1" key value
  4. while read-0 key value; do
  5. if [ "$prefix" ]; then
  6. new_prefix="${prefix}-${key}"
  7. else
  8. new_prefix="${key}"
  9. fi
  10. if [[ "$(echo "$value" | shyaml get-type)" == "struct" ]]; then
  11. echo "$value" | yaml_opt_flatten "${new_prefix}"
  12. else
  13. printf "%s\0%s\0" "${new_prefix}" "$value"
  14. fi
  15. done < <(shyaml key-values-0)
  16. }
  17. CFG_DIR=/etc/synapse
  18. DATA_DIR=/var/lib/synapse
  19. CONFIG_FILE="$CFG_DIR/config.yml"
  20. HOST_CONFIG_FILE="${SERVICE_CONFIGSTORE}$CONFIG_FILE"
  21. setup_dirs() {
  22. local dirs dir
  23. dirs=("$SERVICE_DATASTORE/var/lib/synapse")
  24. uid_gid=($(docker_get_uid_gid "$SERVICE_NAME" "synapse" "synapse")) || {
  25. err "Could not fetch uid/gid on image of service ${DARKYELLOW}$SERVICE_NAME${NORMAL}."
  26. return 1
  27. }
  28. uid="${uid_gid[0]}"
  29. gid="${uid_gid[1]}"
  30. for dir in "${dirs[@]}"; do
  31. mkdir -p "$dir"
  32. find "$dir" \! -uid "$uid" -exec chown -v "$uid" {} \;
  33. find "$dir" \! -gid "$gid" -exec chgrp -v "$gid" {} \;
  34. done
  35. dirs=(
  36. "${SERVICE_CONFIGSTORE}/$CFG_DIR"
  37. "${SERVICE_DATASTORE}/var/lib/synapse/keys"
  38. )
  39. for dir in "${dirs[@]}"; do
  40. mkdir -p "$dir"
  41. chown "$uid:$gid" "$dir"
  42. done
  43. }
  44. cfg-merge() {
  45. local yaml="$1"
  46. merge_yaml_str "$(cat "$HOST_CONFIG_FILE" 2>/dev/null)" \
  47. "$yaml" > "$HOST_CONFIG_FILE.tmp" || return 1
  48. mv "$HOST_CONFIG_FILE.tmp" "$HOST_CONFIG_FILE"
  49. }
  50. cfg-base() {
  51. cat <<EOF > "$HOST_CONFIG_FILE"
  52. ## Server
  53. ## Not running as a daemon
  54. # pid_file: /var/run/synapse/synapse.pid
  55. web_client: False
  56. soft_file_limit: 0
  57. log_config: "$CFG_DIR/logging.yml"
  58. ## Ports
  59. listeners:
  60. - port: 8008
  61. tls: false
  62. bind_addresses: ['::']
  63. type: http
  64. x_forwarded: false
  65. resources:
  66. - names: [client]
  67. compress: true
  68. - names: [federation]
  69. compress: false
  70. ## Database ##
  71. database:
  72. name: "sqlite3"
  73. args:
  74. database: "$DATA_DIR/homeserver.db"
  75. ## Performance ##
  76. event_cache_size: 10K
  77. ## Ratelimiting ##
  78. rc_messages_per_second: 0.2
  79. rc_message_burst_count: 10.0
  80. federation_rc_window_size: 1000
  81. federation_rc_sleep_limit: 10
  82. federation_rc_sleep_delay: 500
  83. federation_rc_reject_limit: 50
  84. federation_rc_concurrent: 3
  85. ## Files ##
  86. media_store_path: "$DATA_DIR/media"
  87. uploads_path: "$DATA_DIR/uploads"
  88. max_upload_size: "10M"
  89. max_image_pixels: "32M"
  90. dynamic_thumbnails: false
  91. # List of thumbnail to precalculate when an image is uploaded.
  92. thumbnail_sizes:
  93. - width: 32
  94. height: 32
  95. method: crop
  96. - width: 96
  97. height: 96
  98. method: crop
  99. - width: 320
  100. height: 240
  101. method: scale
  102. - width: 640
  103. height: 480
  104. method: scale
  105. - width: 800
  106. height: 600
  107. method: scale
  108. url_preview_enabled: false
  109. max_spider_size: "10M"
  110. ## Registration ##
  111. enable_registration: false
  112. enable_registration_captcha: false
  113. bcrypt_rounds: 12
  114. allow_guest_access: true
  115. enable_group_creation: true
  116. ## TURN
  117. turn_allow_guests: true
  118. turn_shared_secret: YOUR_SHARED_SECRET
  119. turn_uris: []
  120. turn_user_lifetime: 1h
  121. # The list of identity servers trusted to verify third party
  122. # identifiers by this server.
  123. #
  124. # Also defines the ID server which will be called when an account is
  125. # deactivated (one will be picked arbitrarily).
  126. trusted_third_party_id_servers:
  127. - matrix.org
  128. - vector.im
  129. ## Metrics
  130. enable_metrics: false
  131. report_stats: false
  132. ## API Configuration
  133. room_invite_state_types:
  134. - "m.room.join_rules"
  135. - "m.room.canonical_alias"
  136. - "m.room.avatar"
  137. - "m.room.name"
  138. expire_access_token: False
  139. ## Signing Keys ##
  140. signing_key_path: "$DATA_DIR/keys/synapse.signing.key"
  141. old_signing_keys: {}
  142. key_refresh_interval: "1d" # 1 Day.
  143. # The trusted servers to download signing keys from.
  144. perspectives:
  145. servers:
  146. "matrix.org":
  147. verify_keys:
  148. "ed25519:auto":
  149. key: "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw"
  150. password_config:
  151. enabled: true
  152. recaptcha_siteverify_api: https://www.google.com/recaptcha/api/siteverify
  153. app_service_config_files: []
  154. EOF
  155. cat <<EOF > "$SERVICE_CONFIGSTORE$CFG_DIR"/logging.yml
  156. version: 1
  157. formatters:
  158. precise:
  159. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s- %(message)s'
  160. filters:
  161. context:
  162. (): synapse.util.logcontext.LoggingContextFilter
  163. request: ""
  164. handlers:
  165. console:
  166. class: logging.StreamHandler
  167. formatter: precise
  168. filters: [context]
  169. loggers:
  170. synapse:
  171. level: WARNING
  172. synapse.storage.SQL:
  173. # beware: increasing this to DEBUG will make synapse log sensitive
  174. # information such as access tokens.
  175. level: WARNING
  176. root:
  177. level: WARNING
  178. handlers: [console]
  179. EOF
  180. }
  181. config_hash() {
  182. debug "Adding config hash to enable recreating upon config change."
  183. config_hash=$({
  184. cat "$HOST_CONFIG_FILE"
  185. } | md5_compat) || exit 1
  186. init-config-add "
  187. $SERVICE_NAME:
  188. labels:
  189. - compose.config_hash=$config_hash
  190. "
  191. }