1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/synapse_ynh.git synced 2024-09-03 20:26:38 +02:00
synapse_ynh/scripts/restore

238 lines
8.6 KiB
Text
Raw Normal View History

2017-02-13 20:43:41 +01:00
#!/bin/bash
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
2017-02-13 20:43:41 +01:00
# Stop script if errors
ynh_abort_if_errors
2017-02-13 20:43:41 +01:00
# Import common cmd
source ../settings/scripts/psql.sh
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
#=================================================
domain=$(ynh_app_setting_get $app special_domain)
path_url=$(ynh_app_setting_get $app special_path)
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)
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
#=================================================
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
2019-02-08 11:24:08 +01:00
#=================================================
# CREATE A DH FILE
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
# Make dh cert for synapse if it doesn't exist
2019-02-08 11:24:08 +01:00
if [[ ! -e /etc/ssl/private/dh2048.pem ]]
then
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-01-30 23:44:49 +01:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2017-02-13 20:43:41 +01:00
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
2018-01-30 23:44:49 +01:00
# For any update do it in all files
2018-12-21 08:51:45 +01:00
ynh_install_app_dependencies $dependances
2018-01-30 23:44:49 +01:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2017-02-13 20:43:41 +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
#=================================================
# RECONFIGURE THE TURNSERVER
#=================================================
2018-07-05 21:46:24 +02:00
# To be sure that at the restoration the IP address in coturn config is the same as the real address we remake the coturn config
2018-07-05 21:46:24 +02:00
# Retrieve specific settings
turnserver_tls_port=$(ynh_app_setting_get $app turnserver_tls_port)
turnserver_alt_tls_port=$(ynh_app_setting_get $app turnserver_alt_tls_port)
turnserver_pwd=$(ynh_app_setting_get $app turnserver_pwd)
cli_port=$(ynh_app_setting_get $app cli_port)
2018-07-05 21:46:24 +02:00
# WARNING : these commands are used in INSTALL, UPGRADE
# For any update do it in all files
coturn_config_path="/etc/matrix-$app/coturn.conf"
cp ../settings/conf/turnserver.conf "$coturn_config_path"
ynh_replace_string __APP__ $app "$coturn_config_path"
ynh_replace_string __TURNPWD__ $turnserver_pwd "$coturn_config_path"
ynh_replace_string __DOMAIN__ $domain "$coturn_config_path"
ynh_replace_string __TLS_PORT__ $turnserver_tls_port "$coturn_config_path"
ynh_replace_string __TLS_ALT_PORT__ $turnserver_alt_tls_port "$coturn_config_path"
ynh_replace_string __CLI_PORT__ $cli_port "$coturn_config_path"
# Get public IP and set as external IP for coturn
# note : '|| true' is used to ignore the errors if we can't get the public ipv4 or ipv6
public_ip4="$(curl ip.yunohost.org)" || true
public_ip6="$(curl ipv6.yunohost.org)" || true
if [[ -n "$public_ip4" ]] && ynh_validate_ip4 "$public_ip4"
then
ynh_replace_string '__IPV4__' "$public_ip4" "$coturn_config_path"
else
ynh_replace_string '__IPV4__,' "" "$coturn_config_path"
fi
if [[ -n "$public_ip6" ]] && ynh_valide_ip6 "$public_ip6"
then
ynh_replace_string '__IPV6__' "$public_ip6" "$coturn_config_path"
else
ynh_replace_string ',__IPV6__' "" "$coturn_config_path"
fi
ynh_store_file_checksum "$coturn_config_path"
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
# 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".
python3 ../settings/conf/add_sso_conf.py || ynh_die "Your file /etc/ssowat/conf.json.persistent doesn't respect the json syntax. Please fix the syntax 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
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"
2018-01-30 23:44:49 +01:00
#=================================================
# RESTORE SYSTEMD
#=================================================
systemctl daemon-reload
systemctl enable matrix-$app.service
2018-01-30 23:44:49 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_use_logrotate /var/log/matrix-$app
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE (3 times)
2018-01-30 23:44:49 +01:00
# For any update do it in all files
chown $synapse_user:root -R $final_path
chmod 770 $final_path/Coturn_config_rotate.sh
2018-01-30 23:44:49 +01:00
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
2019-02-08 14:53:18 +01:00
chmod 600 /etc/matrix-$app/$domain.signing.key
2018-01-30 23:44:49 +01:00
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
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
#=================================================
systemctl reload nginx.service
systemctl restart coturn-$app.service
2019-02-15 11:06:07 +01:00
ynh_check_starting "Synapse now listening on TCP port $synapse_tls_port" "/var/log/matrix-$app/homeserver.log" 300 "matrix-$app"
2018-03-13 16:50:27 +01:00
2019-02-12 21:24:25 +01:00
#=================================================
# SETUP FAIL2BAN
#=================================================
systemctl try-reload-or-restart fail2ban
2018-03-13 16:50:27 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, RESTORE
2018-06-20 19:32:48 +02:00
# For any update do it in all files
2018-03-17 09:55:05 +01:00
message="To federate this app you need to add this line in your DNS configuration:
2018-03-13 16:50:27 +01:00
_matrix._tcp.$domain. 3600 IN SRV 10 0 $synapse_tls_port $domain.
You also need to open the TCP port $synapse_tls_port on your ISP box if it's not automatically done.
2018-07-05 21:46:24 +02:00
Your synapse server also implements a turnserver (for VoIP), to have this fully functional please read the 'Turnserver' section in the README available here: https://github.com/YunoHost-Apps/synapse_ynh .
2018-03-13 16:50:27 +01:00
2018-03-17 09:55:05 +01:00
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/synapse_ynh"
2018-03-13 16:50:27 +01:00
ynh_send_readme_to_admin "$message"