2017-02-13 20:43:41 +01:00
#!/bin/bash
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-04-30 19:15:33 +02:00
source _common.sh
source experimental_helper.sh
2017-07-21 22:28:49 +02:00
source /usr/share/yunohost/helpers
2018-01-30 23:44:49 +01:00
#=================================================
# SET ALL CONSTANT
#=================================================
2020-12-15 22:25:29 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2023-01-11 14:53:53 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2018-05-30 08:24:29 +02:00
# STANDARD UPGRADE STEPS
2019-12-14 15:11:33 +01:00
#=================================================
2019-12-18 20:50:48 +01:00
# MIGRATION 5 : Manage old settings
2019-12-14 15:11:33 +01:00
#=================================================
# Migrate from settings 'special_domain' to 'domain' and 'special_path' to 'path'
if [ -z $domain ]; then
2023-11-01 18:52:07 +01:00
domain=$(ynh_app_setting_get --app=$app --key=special_domain)
path=$(ynh_app_setting_get --app=$app --key=special_path)
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path
2019-12-18 20:36:05 +01:00
ynh_app_setting_delete --app=$app --key=special_domain
ynh_app_setting_delete --app=$app --key=special_path
2019-12-14 15:11:33 +01:00
ynh_app_setting_set --app=$app --key=no_sso --value true
fi
2019-12-18 20:50:48 +01:00
# Define $server_name if not already defined
if [ -z $server_name ]; then
2023-11-01 18:52:07 +01:00
server_name=$domain
ynh_app_setting_set --app=$app --key=server_name --value=$domain
2020-05-07 14:41:35 +02:00
fi
2020-12-07 16:34:41 +01:00
# Define $jitsi_server if not already defined
2020-05-07 14:41:35 +02:00
if [ -z $jitsi_server ]; then
2023-11-01 18:52:07 +01:00
jitsi_server='jitsi.riot.im'
ynh_app_setting_set --app=$app --key=jitsi_server --value=$jitsi_server
2019-12-18 20:50:48 +01:00
fi
2020-12-12 15:38:13 +01:00
# Define $e2e_enabled_by_default if not already defined
2023-01-11 12:29:02 +01:00
if [ -z $e2e_enabled_by_default ] ; then
2023-11-01 18:52:07 +01:00
e2e_enabled_by_default="invite"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
2023-01-10 16:36:46 +01:00
fi
2023-01-11 12:29:02 +01:00
if [ "$e2e_enabled_by_default" = "true" ] ; then
2023-11-01 18:52:07 +01:00
e2e_enabled_by_default="all"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
2023-01-10 16:36:46 +01:00
fi
2023-01-11 12:29:02 +01:00
if [ "$e2e_enabled_by_default" = "false" ]; then
2023-11-01 18:52:07 +01:00
e2e_enabled_by_default="off"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
2020-12-12 15:38:13 +01:00
fi
2020-05-29 22:39:15 +02:00
if [ -z $report_stats ]; then
report_stats="false"
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=report_stats --value=$report_stats
2022-05-26 16:41:22 +02:00
fi
2023-01-10 00:20:52 +01:00
# Get app name of first Element Instance
2023-07-03 22:30:08 +02:00
element_ynh_url="https://matrix.to/"
web_client_location=$element_ynh_url
client_base_url=$element_ynh_url
invite_client_location=$element_ynh_url
2023-11-01 18:52:07 +01:00
2023-01-11 14:03:52 +01:00
if [ -z "$web_client_location" ]
2023-01-06 14:38:14 +01:00
then
2023-11-01 18:52:07 +01:00
element_instance="element"
if yunohost --output-as plain app list | grep -q "^$element_instance"'$'; then
element_domain=$(ynh_app_setting_get --app $element_instance --key domain)
element_path=$(ynh_app_setting_get --app $element_instance --key path)
element_ynh_url="https://""$element_domain""$element_path"
fi
web_client_location=$element_ynh_url
client_base_url=$element_ynh_url
invite_client_location=$element_ynh_url
ynh_app_setting_set --app=$app --key=web_client_location --value=$web_client_location
ynh_app_setting_set --app=$app --key=client_base_url --value=$client_base_url
ynh_app_setting_set --app=$app --key=invite_client_location --value=$invite_client_location
2023-01-06 14:38:14 +01:00
fi
2023-01-10 00:20:52 +01:00
2023-01-06 14:38:14 +01:00
if [ -z "$allow_public_rooms_without_auth" ]
then
2023-11-01 18:52:07 +01:00
allow_public_rooms_without_auth=${allow_public_rooms:-false}
ynh_app_setting_set --app=$app --key=allow_public_rooms_without_auth --value=$allow_public_rooms_without_auth
2023-01-06 14:38:14 +01:00
fi
if [ -z "$allow_public_rooms_over_federation" ]
then
2023-11-01 18:52:07 +01:00
allow_public_rooms_over_federation=${allow_public_rooms:-false}
ynh_app_setting_set --app=$app --key=allow_public_rooms_over_federation --value=$allow_public_rooms_over_federation
2023-01-06 14:38:14 +01:00
fi
2023-01-13 12:38:30 +01:00
if [ -z "$max_upload_size" ]
then
2023-11-22 18:58:42 +01:00
max_upload_size="100M"
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=max_upload_size --value=$max_upload_size
2023-01-13 12:38:30 +01:00
fi
2023-01-06 14:38:14 +01:00
if [ -z "$disable_msisdn_registration" ]
then
2023-11-01 18:52:07 +01:00
disable_msisdn_registration="true"
ynh_app_setting_set --app=$app --key=disable_msisdn_registration --value=$disable_msisdn_registration
2023-01-06 14:38:14 +01:00
fi
2023-01-10 12:37:02 +01:00
if [ -z "$registrations_require_3pid" ]
then
2024-02-16 23:31:30 +01:00
registrations_require_3pid=email
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=registrations_require_3pid --value=$registrations_require_3pid
2023-01-10 12:37:02 +01:00
fi
2023-01-19 10:08:18 +01:00
if [ -z "$allowed_local_3pids_email" ]
2023-01-06 14:38:14 +01:00
then
2024-02-16 23:31:30 +01:00
allowed_local_3pids_email=''
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value=$allowed_local_3pids_email
2023-01-19 10:08:18 +01:00
fi
if [ -z "$allowed_local_3pids_msisdn" ]
then
2024-02-16 23:31:30 +01:00
allowed_local_3pids_msisdn=''
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn
2023-01-06 14:38:14 +01:00
fi
2023-08-21 22:45:22 +02:00
if [ -z "$account_threepid_delegates_msisdn" ]
then
2023-11-01 18:52:07 +01:00
account_threepid_delegates_msisdn=""
ynh_app_setting_set --app=$app --key=account_threepid_delegates_msisdn --value=$account_threepid_delegates_msisdn
2023-08-21 22:45:22 +02:00
fi
2023-01-06 14:38:14 +01:00
if [ -z "$allow_guest_access" ]
then
2023-11-01 18:52:07 +01:00
allow_guest_access="false"
ynh_app_setting_set --app=$app --key=allow_guest_access --value=$allow_guest_access
2023-01-06 14:38:14 +01:00
fi
if [ -z "$default_identity_server" ]
then
2023-11-01 18:52:07 +01:00
default_identity_server="https://matrix.org"
ynh_app_setting_set --app=$app --key=default_identity_server --value=$default_identity_server
2023-01-06 14:38:14 +01:00
fi
if [ -z "$auto_join_rooms" ]
then
2023-11-01 18:52:07 +01:00
auto_join_rooms="#auto_join_room:""$server_name"
ynh_app_setting_set --app=$app --key=auto_join_rooms --value=$auto_join_rooms
2023-01-06 14:38:14 +01:00
fi
2023-01-10 04:14:11 +01:00
if [ -z "$autocreate_auto_join_rooms" ]
then
2023-11-01 18:52:07 +01:00
autocreate_auto_join_rooms="false"
ynh_app_setting_set --app=$app --key=autocreate_auto_join_rooms --value=$autocreate_auto_join_rooms
2023-01-10 04:14:11 +01:00
fi
2023-01-06 14:38:14 +01:00
if [ -z "$auto_join_rooms_for_guests" ]
then
2023-11-01 18:52:07 +01:00
auto_join_rooms_for_guests="true"
ynh_app_setting_set --app=$app --key=auto_join_rooms_for_guests --value=$auto_join_rooms_for_guests
2023-01-06 14:38:14 +01:00
fi
if [ -z "$enable_notifs" ]
then
2023-11-01 18:52:07 +01:00
enable_notifs="true"
ynh_app_setting_set --app=$app --key=enable_notifs --value=$enable_notifs
2023-01-06 14:38:14 +01:00
fi
if [ -z "$notif_for_new_users" ]
then
2023-11-01 18:52:07 +01:00
notif_for_new_users="true"
ynh_app_setting_set --app=$app --key=notif_for_new_users --value=$notif_for_new_users
2023-01-06 14:38:14 +01:00
fi
if [ -z "$enable_group_creation" ]
then
2023-11-01 18:52:07 +01:00
enable_group_creation="true"
ynh_app_setting_set --app=$app --key=enable_group_creation --value=$enable_group_creation
2023-01-06 14:38:14 +01:00
fi
2024-02-16 23:31:30 +01:00
if [ -z "$enable_3pid_lookup" ]
then
enable_3pid_lookup=false
ynh_app_setting_set --app=$app --key=enable_3pid_lookup --value=$enable_3pid_lookup
fi
if [ -z "$turn_allow_guests" ]
then
turn_allow_guests=false
ynh_app_setting_set --app=$app --key=turn_allow_guests --value=$turn_allow_guests
fi
2023-01-06 14:38:14 +01:00
2023-01-11 17:36:28 +01:00
if [ -z "$enable_registration" ]
then
2023-11-01 18:52:07 +01:00
if [ -z $is_free_registration ]; then
is_free_registration=$(ynh_app_setting_get --app=$app --key=is_""public)
fi
2023-08-13 18:47:19 +02:00
if [ "$is_free_registration" -eq "0" ]
2023-01-11 14:53:53 +01:00
then
2023-01-11 17:11:43 +01:00
enable_registration="false"
password_enabled="false"
2024-02-16 23:31:30 +01:00
2023-01-11 14:53:53 +01:00
else
2023-01-11 17:11:43 +01:00
enable_registration="true"
password_enabled="true"
2023-01-11 14:53:53 +01:00
fi
2023-01-11 17:11:43 +01:00
ynh_app_setting_set --app=$app --key=enable_registration --value=$enable_registration
2023-11-01 18:52:07 +01:00
ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled
2023-01-11 14:53:53 +01:00
fi
2023-01-30 18:08:00 +01:00
if [ -z "$push_include_content" ]
then
2023-11-01 18:52:07 +01:00
push_include_content="true"
ynh_app_setting_set --app=$app --key=push_include_content --value=$push_include_content
2023-01-30 18:08:00 +01:00
fi
2024-02-06 20:42:00 +01:00
#=================================================
# MIGRATION 7 : STANDARDIZE SYSTEMD UNIT
#=================================================
2024-02-16 23:31:46 +01:00
if [ -e /etc/systemd/system/matrix-$app.service ]
2024-02-06 20:42:00 +01:00
then
2024-02-20 21:18:29 +01:00
ynh_script_progression --message='Migrating systemd unit to standard name...'
2024-02-06 20:42:00 +01:00
2024-02-16 23:31:46 +01:00
systemctl stop matrix-$app.service || true
2024-02-20 21:18:29 +01:00
systemctl stop coturn-$app.service || true
2024-02-06 20:42:00 +01:00
2024-02-16 23:31:46 +01:00
yunohost service remove matrix-$app || true
yunohost service remove coturn-$app || true
2024-02-06 20:42:00 +01:00
ynh_secure_remove --file=/etc/systemd/system/matrix-$app.service
ynh_secure_remove --file=/etc/systemd/system/coturn-$app.service
touch /etc/systemd/system/$app.service
2024-02-16 23:31:46 +01:00
systemctl daemon-reload || true
2024-02-06 20:42:00 +01:00
fi
#=================================================
# STOP SERVICES
#=================================================
2023-11-01 18:52:07 +01:00
# We stop the service
2024-02-06 20:42:00 +01:00
ynh_systemd_action --service_name=$app.service --action=stop
2018-12-21 08:51:45 +01:00
2024-02-20 21:18:29 +01:00
ynh_script_progression --message='Managing migrations...'
2018-02-06 16:31:03 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
# MIGRATION 6 : Migrate data directory
2018-02-06 16:31:03 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
if [ -e "/var/lib/matrix-$app" ]; then
ynh_script_progression --message="Moving data directory to $data_path..." --weight=1
if [ -e "$data_path" ]; then
old_data_dir_path="$data_path$(date '+%Y%m%d.%H%M%S')"
ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
mv "$data_path" "$old_data_dir_path"
fi
mv "/var/lib/matrix-$app" "$data_path"
fi
2018-01-30 23:44:49 +01:00
2020-02-22 00:42:32 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
# MIGRATION 3 : USE STANDARD ACCESS FOR CERTIFCATE
2018-08-01 00:32:10 +02:00
#=================================================
2023-11-01 18:52:07 +01:00
# Fix issue about certificates access
2024-02-20 21:18:29 +01:00
if [ ! $(grep "ssl-cert:x:[0-9]*:.*$app" /etc/group) ]
2018-08-01 00:32:10 +02:00
then
2023-11-01 18:52:07 +01:00
ynh_script_progression --message="Use standard access for certificate..." --weight=1
2018-08-01 00:32:10 +02:00
2023-12-18 14:35:56 +01:00
adduser $app ssl-cert
2023-11-01 18:52:07 +01:00
adduser turnserver ssl-cert
2018-08-01 00:32:10 +02:00
fi
2018-02-06 16:31:03 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
# MIGRATION 4 : CREATE A DH FILE
2018-02-06 16:31:03 +01:00
#=================================================
2017-07-21 22:28:49 +02:00
2023-11-01 18:52:07 +01:00
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
2018-02-06 16:31:03 +01:00
# For any update do it in all files
2018-01-30 23:44:49 +01:00
2023-11-01 18:52:07 +01:00
# Make dh cert for synapse if it doesn't exist
if [ ! -e /etc/ssl/private/dh2048.pem ]
then
ynh_script_progression --message="Creating a dh file..." --weight=1
2018-02-06 16:31:03 +01:00
2023-11-01 18:52:07 +01:00
openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam 2> /dev/null
chown root:ssl-cert /etc/ssl/private/dh2048.pem
chmod 640 /etc/ssl/private/dh2048.pem
fi
2018-02-06 16:31:03 +01:00
#=================================================
2018-08-01 00:32:10 +02:00
# MIGRATION 2 : MULTINSTANCE SUPPORT
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
if [ ! -e /etc/matrix-$app/coturn.conf ]
2018-01-19 22:05:39 +01:00
then
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Creating an independant service for coturn..." --weight=1
2018-01-30 23:44:49 +01:00
#=================================================
# CREATE AN INDEPENDANT SERVICE FOR COTURN
#=================================================
# Disable default config for turnserver and create a new service
2018-01-19 22:05:39 +01:00
systemctl stop coturn.service
2018-01-30 23:44:49 +01:00
#=================================================
# MAKE A CLEAN LOGROTATE CONFIG
#=================================================
2018-01-19 22:05:39 +01:00
2019-11-04 20:34:37 +01:00
ynh_use_logrotate --logfile /var/log/matrix-$app --nonappend
2018-01-19 22:05:39 +01:00
fi
2017-12-08 21:07:37 +01:00
2024-02-20 21:18:29 +01:00
#=================================================
# MIGRATION 8 : Migrate database to managed database (Migrate db name from matrix_$app to $app)
#=================================================
if ynh_psql_execute_as_root --sql='\list' | grep matrix_$app; then
ynh_psql_remove_db --db_user="user_wich_must_dont_exist_and_keep_current_user" --db_name=$db_name
ynh_psql_execute_as_root --sql="ALTER DATABASE matrix_$app RENAME TO $db_name;"
ynh_psql_execute_as_root --database=$db_name --sql="REASSIGN OWNED BY matrix_$app TO $db_user;"
ynh_psql_execute_as_root --sql="UPDATE pg_database SET datcollate='C', datctype='C' WHERE datname='$db_name';"
ynh_psql_execute_as_root --sql="DROP USER matrix_$app;"
fi
#=================================================
# MIGRATION 9 : migrate data path (from matrix-$app to $app)
#=================================================
if [ -e /home/yunohost.app/matrix-$app ]; then
mv -t $data_dir /home/yunohost.app/matrix-$app/*
ynh_secure_remove --file=/home/yunohost.app/matrix-$app
fi
#=================================================
# MIGRATION 10 : leave port managed by yunohost
#=================================================
# TODO check on v2 how it works
closeport() {
local port=$1
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port"
ynh_exec_warn_less yunohost firewall disallow Both $port
fi
}
# closeport $synapse_tls_port
# closeport $turnserver_tls_port
# closeport $turnserver_alt_tls_port
#=================================================
# MIGRATION 11 : make this app using full domain
#=================================================
ynh_app_setting_set --app=$app --key=path --value=/
if yunohost app map -r --output-as json | jq '."'$domain'" | .[] | .id' | grep -v "$app" -q; then
ynh_print_warn 'An other app is installed on this domain. Now synapse require to be alone on the domain.'
ynh_print_warn 'To solve this you can:'
ynh_print_warn "- Remove or move all other app which use '$domain'"
ynh_print_warn '- Change the url of synapse with the yunohost change-url tool. Note that you will keep the same "server_name" so your users will keep the same username.'
fi
#=================================================
# MIGRATION 12 : update system user and drop yunohost user
#=================================================
if grep -q matrix-$app /etc/passwd; then
ynh_system_user_delete --username=matrix-$app
yunohost user delete $app || true
ynh_system_user_create --username=$app --home_dir=$code_dir
adduser $app ssl-cert
fi
2023-11-01 18:52:07 +01:00
######################################### WARNING ################################
# TODO delete legacy user matrix-synapse
2024-02-20 21:18:29 +01:00
2023-11-01 18:52:07 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-01-30 23:44:49 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ] || [ ! -e $code_dir/bin/python3 ] || [ ! -e $code_dir/lib/python$python_version ]
2017-12-30 15:59:05 +01:00
then
2023-11-01 18:52:07 +01:00
ynh_script_progression --message="Upgrading source files..." --weight=6
install_sources
2017-12-30 15:59:05 +01:00
fi
2019-02-08 11:24:08 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
# MIGRATION 1 : GENERATE SYNAPSE SECRET
2019-02-08 11:24:08 +01:00
#=================================================
2023-11-01 18:52:07 +01:00
if [ -z "$registration_shared_secret" ] || [ "$form_secret" == "form_secret: " ]
2019-02-08 11:24:08 +01:00
then
2023-11-01 18:52:07 +01:00
ynh_script_progression --message="Generating synapse secret..." --weight=1
2019-04-30 19:15:33 +02:00
2023-11-01 18:52:07 +01:00
# Go in virtualenvironnement
u_arg='u'
set +$u_arg;
source $code_dir/bin/activate
set -$u_arg;
# Generate config and keys
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 $code_dir/bin/activate". With this function we undo what "$code_dir/bin/activate" does
set +$u_arg;
deactivate
set -$u_arg;
# Get random values from config
registration_shared_secret=$(egrep "^registration_shared_secret:" homeserver.yml | cut -d'"' -f2)
form_secret=$(egrep "^form_secret:" homeserver.yml | cut -d'"' -f2)
# store in yunohost settings
ynh_app_setting_set --app=$app --key=registration_shared_secret --value="$registration_shared_secret"
ynh_app_setting_set --app=$app --key=form_secret --value="$form_secret"
2019-02-08 11:24:08 +01:00
fi
2018-01-30 23:44:49 +01:00
#=================================================
# STANDARD UPGRADE STEPS
2023-11-01 18:52:07 +01:00
#=================================================
#=================================================
# UPDATE SYNAPSE CONFIG
#=================================================
ynh_script_progression --message="Updating synapse config..." --weight=2
configure_synapse
#=================================================
# CREATE SMALL CAS SERVER
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE
# For any update do it in all files
mkdir -p $install_dir
cp ../sources/cas_server.php $install_dir/
chmod u=rwX,g=rX,o= -R $install_dir
2023-12-18 14:35:56 +01:00
chown $app:root -R $install_dir
2023-11-01 18:52:07 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2022-10-28 10:59:40 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
2017-07-21 22:28:49 +02:00
2020-02-22 00:42:32 +01:00
# Create a dedicated php-fpm config
ynh_script_progression --message="Configuring application..."
2023-08-26 12:07:09 +02:00
ynh_add_fpm_config --usage=low --footprint=low
2020-02-22 00:42:32 +01:00
2023-11-01 18:52:07 +01:00
configure_nginx
2020-05-07 14:41:35 +02:00
2019-04-30 19:15:33 +02:00
#=================================================
# SPECIFIC UPGRADE
2018-01-30 23:44:49 +01:00
#=================================================
# UPDATE COTURN CONFIG
#=================================================
2022-10-28 10:59:40 +02:00
ynh_script_progression --message="Updating Coturn config..." --weight=1
2018-01-30 23:44:49 +01:00
2023-11-01 18:52:07 +01:00
configure_coturn
2018-01-30 23:44:49 +01:00
2018-06-20 19:16:01 +02:00
#=================================================
2020-07-24 23:33:53 +02:00
# ADD SCRIPT FOR COTURN CRON AND APP SERVICE
2018-06-20 19:16:01 +02:00
#=================================================
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE
2018-06-20 19:16:01 +02:00
# For any update do it in all files
2023-11-01 18:52:07 +01:00
ynh_add_config --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh"
ynh_add_config --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh"
2018-06-20 19:16:01 +02:00
2020-10-06 22:28:23 +02:00
# Ensure app-service folder has exists and the config file exit (Migration)
2020-09-18 22:17:22 +02:00
mkdir -p /etc/matrix-$app/app-service
2023-06-06 08:48:53 +02:00
if [ -e /etc/matrix-$app/conf.d/app_service.yaml ]; then
# ensure that the file is empty if no app service are installed (fix issue #385)
if [ ! "$(ls -A /etc/matrix-$app/app-service)" ]; then
echo "" > /etc/matrix-$app/conf.d/app_service.yaml
fi
else
touch /etc/matrix-$app/conf.d/app_service.yaml
fi
2020-09-15 22:44:09 +02:00
2020-07-24 00:34:52 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2024-02-06 20:42:00 +01:00
yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls
yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls
2020-07-24 00:34:52 +02:00
2018-07-28 23:57:36 +02:00
#=================================================
# UPDATE SYSTEMD
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=3
2018-07-28 23:57:36 +02:00
# Create systemd service for synapse and turnserver
cp ../conf/default_matrix-synapse /etc/default/matrix-$app
2024-02-06 20:42:00 +01:00
ynh_add_systemd_config --service=$app --template=synapse.service
2018-07-28 23:57:36 +02:00
cp ../conf/default_coturn /etc/default/coturn-$app
2024-02-06 20:42:00 +01:00
ynh_add_systemd_config --service=$app-coturn --template=synapse-coturn.service
2018-07-28 23:57:36 +02:00
2019-02-12 21:24:25 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# UPGRADE FAIL2BAN
2019-02-12 21:24:25 +01:00
#=================================================
2022-10-28 10:59:40 +02:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
2019-02-12 21:24:25 +01:00
2019-04-30 19:15:33 +02:00
ynh_add_fail2ban_config --use_template
2019-02-12 21:24:25 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC FINALIZATION
2020-02-22 00:48:55 +01:00
#=================================================
2020-12-15 22:25:29 +01:00
# SETUP PERMISSIONS
2020-02-22 00:48:55 +01:00
#=================================================
2020-12-15 22:25:29 +01:00
2023-11-01 18:52:07 +01:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2020-02-22 00:48:55 +01:00
2023-11-01 18:52:07 +01:00
if yunohost --output-as plain domain list | grep -q "^$server_name"'$'; then
if ! ynh_""permission_exists --permission=server_client_infos; then
ynh_""permission_create --permission=server_client_infos --url=$server_name/.well-known/matrix \
--label="Server info for clients. (well-known)" --show_tile=false --allowed=visitors \
--auth_header=false --protected=true
2024-02-16 23:24:17 +01:00
else yunohost --output-as plain domain list | grep -q "^$server_name"'$'
2023-11-01 18:52:07 +01:00
ynh_""permission_url --permission=server_client_infos --url=$server_name/.well-known/matrix \
--auth_header=false
ynh_""permission_update --permission=server_client_infos --label="Server info for clients. (well-known)" --show_tile=false \
--protected=true
fi
2022-03-05 12:46:12 +01:00
fi
2018-01-30 23:44:49 +01:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2023-11-01 18:52:07 +01:00
ynh_script_progression --message="Protecting directories..." --weight=3
set_permissions
2018-01-30 23:44:49 +01:00
2019-09-03 15:26:09 +02:00
#=================================================
# UPDATE HOOKS
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE
# For any update do it in all files
ynh_replace_string __APP__ $app ../hooks/post_cert_update
ynh_replace_string __DOMAIN__ $domain ../hooks/post_cert_update
2018-01-30 23:44:49 +01:00
#=================================================
# RELOAD SERVICES
#=================================================
2022-10-28 10:59:40 +02:00
ynh_script_progression --message="Restarting Synapse services..." --weight=5
2019-04-30 19:15:33 +02:00
2024-02-06 20:42:00 +01:00
ynh_systemd_action --service_name=$app-coturn.service --action=restart
ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
2019-04-30 19:15:33 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last