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.

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