#!/bin/bash # Source YunoHost helpers source /usr/share/yunohost/helpers # Stop script if errors ynh_abort_if_errors # Import common cmd source ./psql.sh source ./experimental_helper.sh source ./_common.sh # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN is_public=$YNH_APP_ARG_IS_PUBLIC path_url="/_matrix" final_path="/opt/yunohost/matrix-$app" # Check domain/path availability ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain." test ! -e "/etc/nginx/conf.d/$domain.d/synapse*.conf" || ynh_die "$domain is not available as domain, please use an other domain." # Check Final Path availability test ! -e "$final_path" || ynh_die "This path already contains a folder" # Ouvre le port dans le firewall synapse_tls_port=$(ynh_find_port 8448) port=$(ynh_find_port 8008) turnserver_tls_port=$(ynh_find_port 5349) turnserver_alt_tls_port=$(ynh_find_port $((turnserver_tls_port+1))) cli_port=$(ynh_find_port 5766) yunohost firewall allow --no-upnp TCP $synapse_tls_port > /dev/null 2>&1 yunohost firewall allow --no-upnp Both $turnserver_tls_port > /dev/null 2>&1 yunohost firewall allow --no-upnp Both $turnserver_alt_tls_port > /dev/null 2>&1 # Find password for turnserver and database turnserver_pwd=$(ynh_string_random 30) synapse_db_pwd=$(ynh_string_random 30) # Enregistre les infos dans la config YunoHost ynh_app_setting_set $app special_domain $domain ynh_app_setting_set $app special_path $path_url ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app synapse_version $upstream_version ynh_app_setting_set $app synapse_db_pwd $synapse_db_pwd ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app synapse_port $port ynh_app_setting_set $app synapse_tls_port $synapse_tls_port ynh_app_setting_set $app turnserver_tls_port $turnserver_tls_port ynh_app_setting_set $app turnserver_alt_tls_port $turnserver_alt_tls_port ynh_app_setting_set $app turnserver_pwd $turnserver_pwd ynh_app_setting_set $app cli_port $cli_port # Make dh cert for synapse if it not exist test ! -e /etc/matrix-$app/dh.pem && \ mkdir -p /etc/matrix-$app && \ openssl dhparam -out /etc/matrix-$app/dh.pem 2048 > /dev/null # Install all dependances install_dependances # Create user ynh_system_user_create $synapse_user /var/lib/matrix-$app adduser $synapse_user ssl-cert adduser turnserver ssl-cert # Create postgresql database ynh_psql_test_if_first_run 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 directory and Install synapse in virtualenv setup_dir install_source # 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 # Create systemd service for synapse and turnserver cp ../conf/default_matrix-synapse /etc/default/matrix-$app ynh_add_systemd_config matrix-$app matrix-synapse.service cp ../conf/default_coturn /etc/default/coturn-$app ynh_add_systemd_config coturn-$app coturn-synapse.service # Config nginx ynh_add_nginx_config # Configure Synapse config_synapse # Configure Coturn config_coturn # Configuration de logrotate ynh_use_logrotate /var/log/matrix-$app # Set Permission for all directory set_permission # register yunohost service yunohost service add matrix-$app # Reload service systemctl restart coturn-$app.service ynh_check_starting "Synapse now listening on port 8448" "/var/log/matrix-$app/homeserver.log" 300 "matrix-$app"