2017-02-13 20:43:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Stop script if errors
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-02-13 20:43:41 +01:00
|
|
|
# Import common cmd
|
2018-01-25 19:33:20 +01:00
|
|
|
source ./psql.sh
|
|
|
|
source ./experimental_helper.sh
|
2017-02-13 20:43:41 +01:00
|
|
|
source ./_common.sh
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2018-01-19 22:05:39 +01:00
|
|
|
path_url="/_matrix"
|
|
|
|
final_path="/opt/yunohost/matrix-$app"
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Check domain/path availability
|
2018-01-25 19:33:20 +01:00
|
|
|
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
|
2018-01-19 22:05:39 +01:00
|
|
|
test ! -e "/etc/nginx/conf.d/$domain.d/synapse*.conf" || ynh_die "$domain is not available as domain, please use an other domain."
|
2017-07-21 22:28:49 +02:00
|
|
|
|
|
|
|
# Check Final Path availability
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2017-02-13 20:43:41 +01:00
|
|
|
|
|
|
|
# Ouvre le port dans le firewall
|
2017-03-07 15:46:05 +01:00
|
|
|
synapse_tls_port=$(ynh_find_port 8448)
|
2018-01-19 22:05:39 +01:00
|
|
|
port=$(ynh_find_port 8008)
|
2017-03-07 15:46:05 +01:00
|
|
|
turnserver_tls_port=$(ynh_find_port 5349)
|
2018-01-19 22:05:39 +01:00
|
|
|
turnserver_alt_tls_port=$(ynh_find_port $((turnserver_tls_port+1)))
|
|
|
|
cli_port=$(ynh_find_port 5766)
|
2017-03-07 15:46:05 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
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
|
2018-01-19 22:05:39 +01:00
|
|
|
yunohost firewall allow --no-upnp Both $turnserver_alt_tls_port > /dev/null 2>&1
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Find password for turnserver and database
|
2017-02-13 20:43:41 +01:00
|
|
|
turnserver_pwd=$(ynh_string_random 30)
|
2017-07-21 22:28:49 +02:00
|
|
|
synapse_db_pwd=$(ynh_string_random 30)
|
2017-02-13 20:43:41 +01:00
|
|
|
|
|
|
|
# Enregistre les infos dans la config YunoHost
|
2017-07-21 22:28:49 +02:00
|
|
|
ynh_app_setting_set $app special_domain $domain
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_app_setting_set $app special_path $path_url
|
2017-07-21 22:28:49 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
2018-01-25 19:33:20 +01:00
|
|
|
ynh_app_setting_set $app synapse_version $upstream_version
|
2017-07-21 22:28:49 +02:00
|
|
|
ynh_app_setting_set $app synapse_db_pwd $synapse_db_pwd
|
2017-02-13 20:43:41 +01:00
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_app_setting_set $app synapse_port $port
|
2017-02-13 20:43:41 +01:00
|
|
|
ynh_app_setting_set $app synapse_tls_port $synapse_tls_port
|
|
|
|
ynh_app_setting_set $app turnserver_tls_port $turnserver_tls_port
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_app_setting_set $app turnserver_alt_tls_port $turnserver_alt_tls_port
|
2017-02-13 20:43:41 +01:00
|
|
|
ynh_app_setting_set $app turnserver_pwd $turnserver_pwd
|
2018-01-19 22:05:39 +01:00
|
|
|
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
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Install all dependances
|
|
|
|
install_dependances
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Create user
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_system_user_create $synapse_user /var/lib/matrix-$app
|
2017-12-30 15:59:05 +01:00
|
|
|
adduser $synapse_user ssl-cert
|
|
|
|
adduser turnserver ssl-cert
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Create postgresql database
|
2017-11-11 13:17:49 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2017-07-21 22:28:49 +02:00
|
|
|
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;"
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-10-22 21:33:18 +02:00
|
|
|
# Create directory and Install synapse in virtualenv
|
|
|
|
setup_dir
|
|
|
|
install_source
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# 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
|
2017-02-16 22:54:57 +01:00
|
|
|
|
2018-01-19 22:05:39 +01:00
|
|
|
# Create systemd service for synapse and turnserver
|
|
|
|
cp ../conf/default_matrix-synapse /etc/default/matrix-$app
|
2018-01-25 19:33:20 +01:00
|
|
|
ynh_add_systemd_config matrix-$app matrix-synapse.service
|
2018-01-19 22:05:39 +01:00
|
|
|
|
|
|
|
cp ../conf/default_coturn /etc/default/coturn-$app
|
2018-01-25 19:33:20 +01:00
|
|
|
ynh_add_systemd_config coturn-$app coturn-synapse.service
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2017-07-21 22:28:49 +02:00
|
|
|
# Config nginx
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_add_nginx_config
|
2017-02-13 20:43:41 +01:00
|
|
|
|
|
|
|
# Configure Synapse
|
2017-07-21 22:28:49 +02:00
|
|
|
config_synapse
|
2017-02-13 20:43:41 +01:00
|
|
|
|
|
|
|
# Configure Coturn
|
2017-07-21 22:28:49 +02:00
|
|
|
config_coturn
|
2017-02-13 20:43:41 +01:00
|
|
|
|
|
|
|
# Configuration de logrotate
|
2018-01-19 22:05:39 +01:00
|
|
|
ynh_use_logrotate /var/log/matrix-$app
|
2017-02-13 20:43:41 +01:00
|
|
|
|
2018-01-13 01:07:17 +01:00
|
|
|
# Set Permission for all directory
|
|
|
|
set_permission
|
|
|
|
|
2017-05-26 15:29:12 +02:00
|
|
|
# register yunohost service
|
2018-01-19 22:05:39 +01:00
|
|
|
yunohost service add matrix-$app
|
2017-05-26 15:29:12 +02:00
|
|
|
|
2018-01-19 22:05:39 +01:00
|
|
|
# Reload service
|
|
|
|
systemctl restart coturn-$app.service
|
2018-01-25 19:33:20 +01:00
|
|
|
ynh_check_starting "Synapse now listening on port 8448" "/var/log/matrix-$app/homeserver.log" 300 "matrix-$app"
|