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

#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
. lib/common
# Please note that postgres detect on its own if its datadir needs to be populated
service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
options="$(e "$service_def" | shyaml -y get-value options)" || true
SYNAPSE_OPTIONS=(
server-name:string ## The server name
report-stats:bool ## Enable anon stat reporting back to the Matrix project
enable-registration:bool ## Enable registration on the Synapse instance.
allow-guest:bool ## allow guest joining this server.
event-cache-size:size ## event cache size [default 10K].
max-upload-size:size ## max upload size [default 10M].
## shared secrets
registration-shared-secret:string ## registrering users if registration is disable.
macaroon-secret-key:string ## secret for signing access tokens to the server.
## recaptcha
recaptcha-public-key:string ## required in order to enable recaptcha upon registration
recaptcha-private-key:string ## required in order to enable recaptcha upon registration
## turn
turn-uris:string ## coma-separated list of TURN uris to enable TURN for this homeserver.
turn-secret:string ## TURN shared secret if required.
)
OPTIONS_CONCAT=" ${SYNAPSE_OPTIONS[*]} "
yaml_opts=()
while read-0 key val; do
key_option="$key"
case "$OPTIONS_CONCAT" in
*" ${key_option}:bool "*)
case "${val,,}" in
true|ok|yes|y|1)
val="\"yes\""
;;
false|ko|nok|no|n|0)
val="\"no\""
;;
*)
die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value."
;;
esac
;;
*" ${key_option}:numeric "*)
if ! is_int "$val"; then
die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value."
fi
;;
*" ${key_option}:string "*)
:
;;
*" ${key_option}:size "*)
[[ "${val}" =~ ^[0-9\.]+[KkMmGgTtPp]$ ]] || {
die "Unknown size specification '${val}'."
}
;;
*)
case "${key//_/-}" in
*) die "Unknown option ${WHITE}$key$NORMAL.";;
esac
continue
;;
esac
yaml_opts+=("$key" "$val")
done < <(e "$options" | yaml_opt_flatten)
config="\
$SERVICE_NAME:
environment:
SYNAPSE_NO_TLS: \"yes\"
"
while read-0 key value; do
key=${key//-/_}
config+="$(printf "\n SYNAPSE_%s: %s" "${key^^}" "$value")"
done < <(array_values_to_stdin yaml_opts)
init-config-add "$config"