diff --git a/README.md b/README.md index 94bd21e..469c146 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ If your server name is identical to the domain on which synapse is installed, an If not, you may need to put the following line in the dns configuration: ``` -_matrix._tcp. IN SRV 10 0 +_matrix._tcp. IN SRV 10 0 ``` for example ``` -_matrix._tcp.example.com. 3600 IN SRV 10 0 SYNAPSE_PORT example.com. +_matrix._tcp.example.com. 3600 IN SRV 10 0 SYNAPSE_PORT synapse.example.com. ``` You need to replace SYNAPSE_PORT by the real port. This port can be obtained by the command: `yunohost app setting SYNAPSE_INSTANCE_NAME synapse_tls_port` diff --git a/conf/homeserver.yaml b/conf/homeserver.yaml index c866bf7..c6224d3 100644 --- a/conf/homeserver.yaml +++ b/conf/homeserver.yaml @@ -50,7 +50,7 @@ tls_fingerprints: [] # This is used by remote servers to connect to this server, # e.g. matrix.org, localhost:8080, etc. # This is also the last part of your UserID. -server_name: "__DOMAIN__" +server_name: "__SERVER_NAME__" # When running as a daemon, the file to store the pid in pid_file: "/var/run/matrix-__APP__.pid" diff --git a/manifest.json b/manifest.json index 916959f..8758aa1 100644 --- a/manifest.json +++ b/manifest.json @@ -29,7 +29,17 @@ "en": "Choose a domain for Synapse", "fr": "Choisissez un domaine pour Synapse" }, - "example": "domain.org" + "example": "synapse.domain.org" + }, + { + "name": "server_name", + "type": "string", + "ask": { + "en": "If your synapse domain is a subdomain, you can choose a name for your Synapse server to have your matrix user-ids looking like @user:domain.org instead of @user:synapse.domain.org", + "fr": "Si votre domaine pour synapse est un sous-domaine, vous pouvez choisir un nom pour votre serveur Synapse afin que vos identifiants matrix soient @utilisateur:domain.org plutôt que @utilisateur:synapse.domain.org" + }, + "example": "domain.org", + "default": "Same than the domain" }, { "name": "is_public", diff --git a/scripts/config b/scripts/config index 44a23ea..2843819 100644 --- a/scripts/config +++ b/scripts/config @@ -69,6 +69,7 @@ apply_config() { fi domain=$(ynh_app_setting_get --app $app --key special_domain) + server_name=$(ynh_app_setting_get --app $app --key server_name) synapse_db_pwd=$(ynh_app_setting_get --app $app --key synapse_db_pwd) is_public=$(ynh_app_setting_get --app $app --key is_public) port=$(ynh_app_setting_get --app $app --key synapse_port) @@ -96,6 +97,7 @@ apply_config() { ynh_replace_string --match_string __APP__ --replace_string $app --target_file "$homeserver_config_path" ynh_replace_string --match_string __DOMAIN__ --replace_string $domain --target_file "$homeserver_config_path" + ynh_replace_string --match_string __SERVER_NAME__ --replace_string $server_name --target_file "$homeserver_config_path" ynh_replace_string --match_string __SYNAPSE_DB_USER__ --replace_string $synapse_db_user --target_file "$homeserver_config_path" ynh_replace_string --match_string __SYNAPSE_DB_PWD__ --replace_string $synapse_db_pwd --target_file "$homeserver_config_path" ynh_replace_string --match_string __PORT__ --replace_string $port --target_file "$homeserver_config_path" diff --git a/scripts/install b/scripts/install index 72c26bf..280b99f 100644 --- a/scripts/install +++ b/scripts/install @@ -39,10 +39,22 @@ synapse_db_name="matrix_$app" synapse_db_user="matrix_$app" upstream_version=$(ynh_app_upstream_version) report_stats="False" +default_domain_value="Same than the domain" +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + +domain=$YNH_APP_ARG_DOMAIN +server_name=$YNH_APP_ARG_SERVER_NAME +is_public=$YNH_APP_ARG_IS_PUBLIC path_url="/_matrix" final_path="/opt/yunohost/matrix-$app" +if [[ "$server_name" == "$default_domain_value" ]]; then + server_name=$domain +fi + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -65,6 +77,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 # This hack solve the issue : https://github.com/YunoHost-Apps/synapse_ynh/issues/14 ynh_app_setting_set --app=$app --key=special_domain --value=$domain ynh_app_setting_set --app=$app --key=special_path --value=$path_url +ynh_app_setting_set --app=$app --key=server_name --value=$server_name ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=synapse_version --value=$upstream_version ynh_app_setting_set --app=$app --key=is_public --value=$is_public @@ -198,7 +211,7 @@ PS1=${PS1:-} source $final_path/bin/activate # Generate config -python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $domain --report-stats=no -c homeserver.yml +python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $server_name --report-stats=no -c homeserver.yml # This function was defined when we called "source $final_path/bin/activate". With this function we undo what "$final_path/bin/activate" does deactivate @@ -255,6 +268,7 @@ cp ../conf/log.yaml /etc/matrix-$app/log.yaml ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$homeserver_config_path" ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$homeserver_config_path" +ynh_replace_string --match_string=__SERVER_NAME__ --replace_string=$server_name --target_file="$homeserver_config_path" ynh_replace_string --match_string=__SYNAPSE_DB_USER__ --replace_string=$synapse_db_user --target_file="$homeserver_config_path" ynh_replace_string --match_string=__PORT__ --replace_string=$port --target_file="$homeserver_config_path" ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$synapse_tls_port --target_file="$homeserver_config_path" @@ -361,7 +375,7 @@ chown $synapse_user:root -R /var/lib/matrix-$app chown $synapse_user:root -R /var/log/matrix-$app chown $synapse_user:root -R /etc/matrix-$app chmod u=rwX,g=rX,o= -R /etc/matrix-$app -chmod 600 /etc/matrix-$app/$domain.signing.key +chmod 600 /etc/matrix-$app/$server_name.signing.key setfacl -R -m user:turnserver:rX /etc/matrix-$app setfacl -R -m user:turnserver:rwX /var/log/matrix-$app diff --git a/scripts/restore b/scripts/restore index 651e551..89d963f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +30,7 @@ ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=special_domain) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) path_url=$(ynh_app_setting_get --app=$app --key=special_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) synapse_tls_port=$(ynh_app_setting_get --app=$app --key=synapse_tls_port) @@ -236,7 +237,7 @@ chown $synapse_user:root -R /var/lib/matrix-$app chown $synapse_user:root -R /var/log/matrix-$app chown $synapse_user:root -R /etc/matrix-$app chmod u=rwX,g=rX,o= -R /etc/matrix-$app -chmod 600 /etc/matrix-$app/$domain.signing.key +chmod 600 /etc/matrix-$app/$server_name.signing.key setfacl -R -m user:turnserver:rX /etc/matrix-$app setfacl -R -m user:turnserver:rwX /var/log/matrix-$app diff --git a/scripts/upgrade b/scripts/upgrade index 6ea1837..a763bc9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,6 +18,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=3 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=special_domain) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) path_url=$(ynh_app_setting_get --app=$app --key=special_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) synapse_old_version=$(ynh_app_setting_get --app=$app --key=synapse_version) @@ -61,6 +62,10 @@ then ynh_die --message="Update from this synapse version is not available. You need to remove this package and reinstall the new package version." fi +if [ -z $server_name ]; then + server_name=$domain + ynh_app_setting_set $app server_name $domain +fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -147,7 +152,7 @@ then source $final_path/bin/activate # Generate config and keys - python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $domain --report-stats=no -c homeserver.yml + python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $server_name --report-stats=no -c homeserver.yml # This function was defined when we called "source $final_path/bin/activate". With this function we undo what "$final_path/bin/activate" does deactivate @@ -182,6 +187,7 @@ cp ../conf/log.yaml /etc/matrix-$app/log.yaml ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$homeserver_config_path" ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$homeserver_config_path" +ynh_replace_string --match_string=__SERVER_NAME__ --replace_string=$server_name --target_file="$homeserver_config_path" ynh_replace_string --match_string=__SYNAPSE_DB_USER__ --replace_string=$synapse_db_user --target_file="$homeserver_config_path" ynh_replace_string --match_string=__PORT__ --replace_string=$port --target_file="$homeserver_config_path" ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$synapse_tls_port --target_file="$homeserver_config_path" @@ -371,7 +377,7 @@ chown $synapse_user:root -R /var/lib/matrix-$app chown $synapse_user:root -R /var/log/matrix-$app chown $synapse_user:root -R /etc/matrix-$app chmod u=rwX,g=rX,o= -R /etc/matrix-$app -chmod 600 /etc/matrix-$app/$domain.signing.key +chmod 600 /etc/matrix-$app/$server_name.signing.key setfacl -R -m user:turnserver:rX /etc/matrix-$app setfacl -R -m user:turnserver:rwX /var/log/matrix-$app