#!/bin/bash # Source YunoHost helpers source /usr/share/yunohost/helpers source ./psql.sh # Stop script if errors ynh_abort_if_errors # Import common cmd source ./_common.sh # Retrieve arguments domain=$(ynh_app_setting_get $app special_domain) path=$(ynh_app_setting_get $app special_path) final_path=$(ynh_app_setting_get $app final_path) synapse_old_version=$(ynh_app_setting_get $app synapse_version) synapse_db_pwd=$(ynh_app_setting_get $app synapse_db_pwd) is_public=$(ynh_app_setting_get $app is_public) synapse_port=$(ynh_app_setting_get $app synapse_port) synapse_tls_port=$(ynh_app_setting_get $app synapse_tls_port) turnserver_tls_port=$(ynh_app_setting_get $app turnserver_tls_port) turnserver_pwd=$(ynh_app_setting_get $app turnserver_pwd) # To be sure that the migration is sucessfull we check that the old synapse version is compatible with the synapse_port_db script. if [[ -z $synapse_old_version ]] && [[ $(dpkg -l | grep -c -E "ii.*matrix-synapse.*0.25") != 1 ]] && [[ $(dpkg -l | grep -c -E "ii.*matrix-synapse.*0.24") != 1 ]] then ynh_die "Update from this synapse version is not available now. You need to wait for the next update." fi systemctl stop matrix-synapse.service ynh_backup_before_upgrade ynh_clean_setup () { ynh_restore_upgradebackup } ynh_abort_if_errors if [[ -z $synapse_old_version ]] then ## We move from debian package to new package with python virtualenv # Change settings path="/_matrix" domain=$(ynh_app_setting_get $app domain) final_path="/opt/yunohost/matrix-synapse" ynh_app_setting_set $app special_domain $domain ynh_app_setting_set $app special_path $path ynh_app_setting_set $app final_path $final_path ynh_app_setting_delete $app domain ynh_app_setting_delete $app path ynh_app_setting_delete $app skipped_uris # Remove old package and add new package as dependance ynh_secure_remove /etc/apt/sources.list.d/matrix.list ynh_package_autoremove --purge matrix-synapse python-matrix-synapse-ldap3 || true # If we don't remove these line in dpkg config, dpkg fail on every new package install sudo sed --in-place ':a;N;$!ba;s@matrix-synapse nogroup 755 /var/lib/matrix-synapse\n@@g' /var/lib/dpkg/statoverride sudo sed --in-place ':a;N;$!ba;s@matrix-synapse nogroup 755 /var/log/matrix-synapse\n@@g' /var/lib/dpkg/statoverride sudo sed --in-place ':a;N;$!ba;s@matrix-synapse nogroup 755 /etc/matrix-synapse\n@@g' /var/lib/dpkg/statoverride # add new package as dependance and install dependance install_dependances # Create directory Install synapse in virtualenv setup_dir || true # If the dir aready exist the command could fail install_source cp /etc/yunohost/certs/$domain/dh.pem /etc/matrix-synapse/dh.pem set_permission # Open access to server without a button the home cp ../conf/add_sso_conf.py $final_path cp ../conf/remove_sso_conf.py $final_path python $final_path/add_sso_conf.py || echo "Error while sso config, please add '/_matrix' in /etc/ssowat/conf.json.persistent" # Create user ynh_system_user_create $synapse_user /var/lib/matrix-synapse adduser $synapse_user ssl-cert adduser turnserver ssl-cert # Create systemd service ynh_secure_remove /etc/init.d/matrix-synapse ynh_secure_remove /lib/systemd/system/matrix-synapse.service ynh_secure_remove /etc/systemd/system/matrix-synapse.service systemctl daemon-reload systemctl disable matrix-synapse.service cp ../conf/default_matrix-synapse /etc/default/matrix-synapse cp ../conf/matrix-synapse.service /etc/systemd/system/ systemctl daemon-reload systemctl enable matrix-synapse.service # Configuration de logrotate ynh_use_logrotate /var/log/matrix-synapse # register yunohost service yunohost service add matrix-synapse ## Move to postgresql from sqlite # We create the new settings synapse_db_pwd=$(ynh_string_random 30) ynh_app_setting_set $app synapse_db_pwd $synapse_db_pwd # Create postgresql database ynh_psql_create_user $synapse_db_user $synapse_db_pwd ynh_psql_execute_as_root \ "CREATE DATABASE $synapse_db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $synapse_db_user;" # Create config file for synapse with postgresql config_synapse # We get the last version of the synapse_port_db script because an old version could be buggy. cp ../sources/synapse_port_db /opt/yunohost/matrix-synapse/bin/synapse_port_db # Migrate database (in virtualenv) source $final_path/bin/activate /opt/yunohost/matrix-synapse/bin/synapse_port_db --sqlite-database /var/lib/matrix-synapse/homeserver.db \ --postgres-config /etc/matrix-synapse/homeserver.yaml deactivate fi # If the turnserver log is not ready configured we configure it now test -e /var/log/turnserver || (mkdir -p /var/log/turnserver && ynh_use_logrotate /var/log/turnserver) # Fix issue about certificates access if [[ ! $(grep "ssl-cert:x:[0-9]*:.*matrix-synapse" /etc/group) ]] then adduser $synapse_user ssl-cert adduser turnserver ssl-cert fi test -e /etc/matrix-synapse/dh.pem || cp /etc/yunohost/certs/$domain/dh.pem /etc/matrix-synapse/dh.pem # Upgrade manually Synapse install_source set_permission # Update nginx config config_nginx # Configure Synapse config_synapse # Configure Coturn config_coturn # Set new settings ynh_app_setting_set $app synapse_version $APP_VERSION # Recharge la configuration Nginx systemctl reload nginx.service systemctl start matrix-synapse.service systemctl restart coturn.service