2017-02-13 20:43:41 +01:00
#!/bin/bash
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-07-21 22:28:49 +02:00
source /usr/share/yunohost/helpers
2017-02-13 20:43:41 +01:00
2017-07-21 22:28:49 +02:00
# Stop script if errors
ynh_abort_if_errors
2017-02-13 20:43:41 +01:00
2017-07-21 22:28:49 +02:00
# Import common cmd
source ../settings/scripts/psql.sh
2018-01-25 19:33:20 +01:00
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# SET ALL CONSTANT
#=================================================
app=$YNH_APP_INSTANCE_NAME
synapse_user="matrix-$app"
synapse_db_name="matrix_$app"
synapse_db_user="matrix_$app"
upstream_version=$(ynh_app_upstream_version)
#=================================================
# LOAD SETTINGS
#=================================================
2017-07-21 22:28:49 +02:00
domain=$(ynh_app_setting_get $app special_domain)
2018-01-19 22:05:39 +01:00
path_url=$(ynh_app_setting_get $app special_path)
2017-07-21 22:28:49 +02:00
final_path=$(ynh_app_setting_get $app final_path)
synapse_db_pwd=$(ynh_app_setting_get $app synapse_db_pwd)
2017-02-13 20:43:41 +01:00
synapse_tls_port=$(ynh_app_setting_get $app synapse_tls_port)
turnserver_tls_port=$(ynh_app_setting_get $app turnserver_tls_port)
2018-01-19 22:05:39 +01:00
turnserver_alt_tls_port=$(ynh_app_setting_get $app turnserver_alt_tls_port)
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2018-01-19 22:05:39 +01:00
ynh_webpath_available $domain $path_url || ynh_die "$domain/$path_url is not available, please use an other domain."
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE ALL FILES
#=================================================
# Restore all config and data
ynh_restore
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
# WARRNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
ynh_install_app_dependencies coturn build-essential python2.7-dev libffi-dev python-pip python-setuptools sqlite3 libssl-dev python-virtualenv libxml2-dev libxslt1-dev python-lxml libjpeg-dev libpq-dev postgresql acl
pip install --upgrade pip
pip install --upgrade virtualenv
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2017-02-13 20:43:41 +01:00
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
2018-01-30 23:44:49 +01:00
#=================================================
# SPECIFIC RESTORATION
#=================================================
# OPEN THE PORT
#=================================================
# Ouvre le port dans le firewall
2018-02-12 20:31:05 +01:00
yunohost firewall allow TCP $synapse_tls_port > /dev/null 2>&1
yunohost firewall allow Both $turnserver_tls_port > /dev/null 2>&1
yunohost firewall allow Both $turnserver_alt_tls_port > /dev/null 2>&1
2018-01-30 23:44:49 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2017-02-13 20:43:41 +01:00
2017-10-21 01:31:04 +02:00
# Open access to server without a button the home
2018-02-03 11:32:59 +01:00
# The script "add_sso_conf.py" will just add en entry for the path "/_matrix" in the sso conf.json.persistent file in the cathegory "skipped_urls".
2018-02-06 16:31:03 +01:00
python $final_path/add_sso_conf.py || ynh_die "Your file /etc/ssowat/conf.json.persistent don't respect the json synaxe. Please fix the synaxe to install this app. For more information see here : https://github.com/YunoHost-Apps/synapse_ynh/issues/32"
2017-10-21 01:31:04 +02:00
2018-01-30 23:44:49 +01:00
#=================================================
# RESTORE THE 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;"
2018-02-12 10:49:11 +01:00
ynh_psql_execute_file_as_root "${YNH_CWD}/dump.sql" "$synapse_db_name"
2017-07-21 22:28:49 +02:00
2018-01-30 23:44:49 +01:00
#=================================================
# RESTORE SYSTEMD
#=================================================
2017-07-21 22:28:49 +02:00
systemctl daemon-reload
2018-01-19 22:05:39 +01:00
systemctl enable matrix-$app.service
2017-07-21 22:28:49 +02:00
2018-01-30 23:44:49 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2018-01-19 22:05:39 +01:00
ynh_use_logrotate /var/log/matrix-$app
2017-12-08 21:57:33 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# WARRNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
chown $synapse_user:root -R $final_path
chown $synapse_user:root -R /var/lib/matrix-$app
chown $synapse_user:root -R /var/log/matrix-$app
chown $synapse_user:root -R /etc/matrix-$app
chmod u=rwX,g=rX,o= -R /etc/matrix-$app
chmod 600 /etc/matrix-$app/dh.pem
setfacl -R -m user:turnserver:rX /etc/matrix-$app
setfacl -R -m user:turnserver:rwX /var/log/matrix-$app
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2018-01-13 01:07:17 +01:00
2018-02-03 11:32:59 +01:00
yunohost service add matrix-$app -l "/var/log/matrix-$app/homeserver.log"
yunohost service add coturn-$app
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# RELOAD NGINX, SYNAPSE AND COTURN
#=================================================
2017-07-21 22:28:49 +02:00
systemctl reload nginx.service
2018-01-19 22:05:39 +01:00
systemctl restart coturn-$app.service
2018-02-12 10:24:47 +01:00
ynh_check_starting "Synapse now listening on port $synapse_tls_port" "/var/log/matrix-$app/homeserver.log" 300 "matrix-$app"