2018-08-03 16:06:29 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
# Import common fonctions
source ./experimental_helper.sh
source ./_common.sh
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
2018-08-27 21:08:26 +02:00
app=$YNH_APP_INSTANCE_NAME
2019-11-13 21:39:22 +01:00
report_stats=$(ynh_app_setting_get --app $app --key report_stats)
allow_public_rooms=$(ynh_app_setting_get --app=$app --key=allow_public_rooms)
2020-05-07 14:41:35 +02:00
disable_backup_before_upgrade=$(ynh_app_setting_get --app $app --key disable_backup_before_upgrade)
2022-05-26 16:41:22 +02:00
is_free_registration=$(ynh_app_setting_get --app $app --key is_free_registration)
2020-05-07 14:41:35 +02:00
jitsi_server=$(ynh_app_setting_get --app=$app --key=jitsi_server)
2020-12-12 15:38:13 +01:00
e2e_enabled_by_default=$(ynh_app_setting_get --app=$app --key=e2e_enabled_by_default)
2022-05-26 17:19:33 +02:00
synapse_user_app_pwd=$(ynh_app_setting_get --app=$app --key=synapse_user_app_pwd)
2022-09-10 15:39:56 +02:00
domain_whitelist_client_=$(get_domain_list)
domain_whitelist_client=${domain_whitelist_client_%"\n"}
2022-06-24 13:10:12 +02:00
main_domain=$(yunohost domain list --output-as json | jq -r .main)
2018-08-03 16:06:29 +02:00
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
show_config() {
# here you are supposed to read some config file/database/other then print the values
2019-11-28 22:48:23 +01:00
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
2019-11-28 22:44:05 +01:00
ynh_return "YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_SERVER_STATISTICS=$report_stats"
2019-11-28 22:48:23 +01:00
ynh_return "YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_ALLOW_PUBLIC_ROOMS=$allow_public_rooms"
2020-05-07 14:41:35 +02:00
ynh_return "YNH_CONFIG_SYNAPSE_CONFIG_CLIENT_CONFIG_JITSI_SERVER=$jitsi_server"
2022-05-26 16:41:22 +02:00
ynh_return "YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_IS_FREE_REGISTRATION=${is_free_registration}"
2020-12-12 15:38:13 +01:00
ynh_return "YNH_CONFIG_SYNAPSE_CONFIG_CLIENT_CONFIG_E2E_ENABLED_BY_DEFAULT=${e2e_enabled_by_default}"
2018-08-03 16:06:29 +02:00
2020-05-07 14:41:35 +02:00
if [[ ${disable_backup_before_upgrade:-0} -eq 1 ]]
2018-08-03 16:06:29 +02:00
then
2020-12-12 15:38:13 +01:00
ynh_return "YNH_CONFIG_PACKAGE_CONFIG_PACKAGE_CONFIG_BACKUP_BEFORE_UPGRADE=0"
2018-08-03 16:06:29 +02:00
else
2020-12-12 15:38:13 +01:00
ynh_return "YNH_CONFIG_PACKAGE_CONFIG_PACKAGE_CONFIG_BACKUP_BEFORE_UPGRADE=1"
2018-08-03 16:06:29 +02:00
fi
}
#=================================================
# MODIFY THE CONFIGURATION
#=================================================
apply_config() {
2019-11-13 21:39:22 +01:00
report_stats=${YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_SERVER_STATISTICS:-$report_stats}
allow_public_rooms=${YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_ALLOW_PUBLIC_ROOMS:-$allow_public_rooms}
2020-05-07 14:41:35 +02:00
do_backup_before_upgrade=${YNH_CONFIG_PACKAGE_CONFIG_PACKAGE_CONFIG_BACKUP_BEFORE_UPGRADE:-}
2022-05-26 16:41:22 +02:00
is_free_registration=${YNH_CONFIG_SYNAPSE_CONFIG_SERVER_CONFIG_IS_FREE_REGISTRATION:-$is_free_registration}
2020-05-07 14:41:35 +02:00
jitsi_server=${YNH_CONFIG_SYNAPSE_CONFIG_CLIENT_CONFIG_JITSI_SERVER:-$jitsi_server}
2020-12-12 15:38:13 +01:00
e2e_enabled_by_default=${YNH_CONFIG_SYNAPSE_CONFIG_CLIENT_CONFIG_E2E_ENABLED_BY_DEFAULT:-$e2e_enabled_by_default}
2019-11-13 21:39:22 +01:00
2020-05-29 22:39:15 +02:00
if [ $report_stats == 1 ]; then
report_stats=true
fi
if [ $report_stats == 0 ]; then
report_stats=false
fi
if [ $allow_public_rooms == 1 ]; then
allow_public_rooms=true
fi
if [ $allow_public_rooms == 0 ]; then
allow_public_rooms=false
fi
2020-12-12 15:38:13 +01:00
if [ $e2e_enabled_by_default == 1 ]; then
e2e_enabled_by_default=true
fi
if [ $e2e_enabled_by_default == 0 ]; then
e2e_enabled_by_default=false
fi
2020-05-29 22:39:15 +02:00
2019-11-13 21:39:22 +01:00
ynh_app_setting_set --app $app --key report_stats --value $report_stats
ynh_app_setting_set --app $app --key allow_public_rooms --value $allow_public_rooms
2022-05-26 16:41:22 +02:00
ynh_app_setting_set --app $app --key is_free_registration --value $is_free_registration
2020-05-07 14:41:35 +02:00
ynh_app_setting_set --app $app --key jitsi_server --value $jitsi_server
2020-12-12 15:38:13 +01:00
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
2020-05-07 14:41:35 +02:00
if [[ -n $do_backup_before_upgrade ]]; then
if [ $do_backup_before_upgrade -eq 1 ]; then
ynh_app_setting_set --app $app --key disable_backup_before_upgrade --value 0
else
ynh_app_setting_set --app $app --key disable_backup_before_upgrade --value 1
fi
2019-02-08 20:01:35 +01:00
fi
2019-12-14 15:11:33 +01:00
domain=$(ynh_app_setting_get --app $app --key domain)
2019-10-30 21:15:22 +01:00
server_name=$(ynh_app_setting_get --app $app --key server_name)
2019-06-07 22:55:47 +02:00
synapse_db_pwd=$(ynh_app_setting_get --app $app --key synapse_db_pwd)
2022-05-26 16:41:22 +02:00
is_free_registration=$(ynh_app_setting_get --app $app --key is_free_registration)
2019-06-07 22:55:47 +02:00
port=$(ynh_app_setting_get --app $app --key synapse_port)
synapse_tls_port=$(ynh_app_setting_get --app $app --key synapse_tls_port)
turnserver_tls_port=$(ynh_app_setting_get --app $app --key turnserver_tls_port)
turnserver_pwd=$(ynh_app_setting_get --app $app --key turnserver_pwd)
registration_shared_secret=$(ynh_app_setting_get --app $app --key registration_shared_secret)
form_secret=$(ynh_app_setting_get --app $app --key form_secret)
2019-11-13 21:39:22 +01:00
macaroon_secret_key=$(ynh_app_setting_get --app=$app --key=macaroon_secret_key)
2019-02-08 20:01:35 +01:00
synapse_user="matrix-$app"
synapse_db_name="matrix_$app"
synapse_db_user="matrix_$app"
# Configure Synapse
2019-12-14 15:15:25 +01:00
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times)
2019-02-08 20:01:35 +01:00
# For any update do it in all files
2020-12-15 22:25:29 +01:00
if [ -z $macaroon_secret_key ]; then
# Well, in this package this value was not managed because it was not needed, synapse is able to generate this with some other secret in the config file but after some vulnerability was found with this practice.
# For more detail about this issue you can see : https://matrix.org/blog/2019/01/15/further-details-on-critical-security-update-in-synapse-affecting-all-versions-prior-to-0-34-1-cve-2019-5885/
# The problem is that we can't just say generate a new value if the package has not already defined a value. The reason is that changing this value logout all user. And in case of a user has enabled the encryption, the user might lost all conversation !!
# So for the old install we just leave this as it is. And for the new install we use a real macaroon.
macaroon_secret_key_param='# macaroon_secret_key: ""'
2019-11-12 21:59:46 +01:00
else
2020-12-15 22:25:29 +01:00
macaroon_secret_key_param='macaroon_secret_key: "'$macaroon_secret_key'"'
2019-11-12 21:59:46 +01:00
fi
2019-02-08 20:01:35 +01:00
2022-05-26 16:41:22 +02:00
if [ $is_free_registration -eq 0 ]
2019-02-08 20:01:35 +01:00
then
2020-12-15 22:25:29 +01:00
allowed_access=False
sso_enabled=True
2019-02-08 20:01:35 +01:00
else
2020-12-15 22:25:29 +01:00
allowed_access=True
sso_enabled=False
2019-02-08 20:01:35 +01:00
fi
2020-12-15 22:25:29 +01:00
ynh_add_config --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml"
ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml"
2020-05-07 14:41:35 +02:00
# Create .well-known redirection for access by federation
if yunohost --output-as plain domain list | grep -q "^$server_name$"
then
2020-12-15 22:25:29 +01:00
ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
2020-05-07 14:41:35 +02:00
fi
2019-06-15 09:57:14 +02:00
ynh_store_file_checksum --file "$homeserver_config_path"
2019-02-08 20:01:35 +01:00
setfacl -R -m user:turnserver:rX /etc/matrix-$app
systemctl restart matrix-$app
2020-05-07 14:41:35 +02:00
systemctl reload nginx
2018-08-03 16:06:29 +02:00
}
#=================================================
# GENERIC FINALIZATION
#=================================================
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
#=================================================
case $1 in
show) show_config;;
apply) apply_config;;
2018-08-27 21:08:26 +02:00
esac