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/install

462 lines
20 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
#=================================================
2019-04-30 19:15:33 +02:00
source _common.sh
source experimental_helper.sh
source /usr/share/yunohost/helpers
2019-04-30 19:15:33 +02:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2019-04-30 19:15:33 +02:00
ynh_clean_setup () {
# Clean installation remainings that are not handled by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-01-30 23:44:49 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-04-30 19:15:33 +02:00
#=================================================
# SET CONSTANTS
#=================================================
2018-01-30 23:44:49 +01:00
synapse_user="matrix-$app"
synapse_db_name="matrix_$app"
synapse_db_user="matrix_$app"
upstream_version=$(ynh_app_upstream_version)
2019-11-11 21:43:19 +01:00
report_stats="false"
allow_public_rooms="false"
2019-08-24 15:59:03 +02:00
default_domain_value="Same than the domain"
2018-01-30 23:44:49 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-02-13 20:43:41 +01:00
domain=$YNH_APP_ARG_DOMAIN
2019-08-24 15:49:44 +02:00
server_name=$YNH_APP_ARG_SERVER_NAME
2017-02-13 20:43:41 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
path_url="/_matrix"
final_path="/opt/yunohost/matrix-$app"
2017-02-13 20:43:41 +01:00
if [[ "$server_name" == "$default_domain_value" ]]; then
server_name=$domain
fi
2018-01-30 23:44:49 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=2
2018-01-30 23:44:49 +01:00
2019-06-09 22:38:21 +02:00
[ $(ynh_webpath_available --domain=$domain --path_url=$path_url) == "True" ] || ynh_die --message="$domain is not available as domain, please use an other domain."
2019-04-30 19:15:33 +02:00
test ! -e "/etc/nginx/conf.d/$domain.d/synapse*.conf" || ynh_die --message="$domain is not available as domain, please use an other domain."
# Check Final Path availability
2019-04-30 19:15:33 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=1
2018-01-30 23:44:49 +01:00
# For the domain and the path we can't use the standard keys "domain" and "path" with the standard function ynh_webpath_register because it create automatically a button on the user pannel.
# The idea is to create a custom key (specia_domain and special_path instead of domain and key).
# By this the ssowatconf fonction don't create a button on the pannel.
# This hack solve the issue : https://github.com/YunoHost-Apps/synapse_ynh/issues/14
2019-04-30 19:15:33 +02:00
ynh_app_setting_set --app=$app --key=special_domain --value=$domain
ynh_app_setting_set --app=$app --key=special_path --value=$path_url
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
2019-04-30 19:15:33 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_app_setting_set --app=$app --key=synapse_version --value=$upstream_version
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=report_stats --value=$report_stats
2019-11-11 21:43:19 +01:00
ynh_app_setting_set --app=$app --key=allow_public_rooms --value=$allow_public_rooms
2018-01-30 23:44:49 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring firewall..." --weight=19
2018-01-30 23:44:49 +01:00
# Find a free port
2019-04-30 19:15:33 +02:00
synapse_tls_port=$(ynh_find_port --port=8448)
port=$(ynh_find_port --port=8008)
turnserver_tls_port=$(ynh_find_port --port=5349)
turnserver_alt_tls_port=$(ynh_find_port --port=$((turnserver_tls_port+1)))
cli_port=$(ynh_find_port --port=5766)
2017-03-07 15:46:05 +01:00
2018-01-30 23:44:49 +01:00
# Open this port
2019-04-30 19:15:33 +02:00
ynh_exec_warn_less yunohost firewall allow TCP $synapse_tls_port
ynh_exec_warn_less yunohost firewall allow Both $turnserver_tls_port
ynh_exec_warn_less yunohost firewall allow Both $turnserver_alt_tls_port
2018-01-30 23:44:49 +01:00
# Store opened ports
2019-04-30 19:15:33 +02:00
ynh_app_setting_set --app=$app --key=synapse_port --value=$port
ynh_app_setting_set --app=$app --key=synapse_tls_port --value=$synapse_tls_port
ynh_app_setting_set --app=$app --key=turnserver_tls_port --value=$turnserver_tls_port
ynh_app_setting_set --app=$app --key=turnserver_alt_tls_port --value=$turnserver_alt_tls_port
ynh_app_setting_set --app=$app --key=cli_port --value=$cli_port
2019-02-08 11:24:08 +01:00
#=================================================
# CREATE A DH FILE
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Creating a dh file..." --weight=3
2019-02-08 11:24:08 +01:00
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
2019-04-30 19:15:33 +02:00
# Make dh cert for synapse if it doesn't exist
if [ ! -e /etc/ssl/private/dh2048.pem ]
2019-02-08 11:24:08 +01:00
then
2019-04-30 19:15:33 +02:00
ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam
2019-02-08 11:24:08 +01:00
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
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=80
2018-01-30 23:44:49 +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
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring system user..." --weight=3
2017-02-13 20:43:41 +01:00
2019-04-30 19:15:33 +02:00
ynh_system_user_create --username=$synapse_user --home_dir=/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
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=4
2018-01-30 23:44:49 +01:00
2019-06-02 00:09:14 +02:00
ynh_print_OFF
2019-04-30 19:15:33 +02:00
synapse_db_pwd=$(ynh_string_random --length=30)
ynh_app_setting_set --app=$app --key=synapse_db_pwd --value=$synapse_db_pwd
2019-06-02 00:09:14 +02:00
ynh_print_ON
2018-01-30 23:44:49 +01:00
# Create postgresql database
2017-11-11 13:17:49 +01:00
ynh_psql_test_if_first_run
2019-06-02 00:09:14 +02:00
ynh_print_OFF
ynh_psql_create_user $synapse_db_user $synapse_db_pwd
2019-06-02 00:09:14 +02:00
ynh_print_ON
ynh_psql_execute_as_root \
2019-04-30 19:15:33 +02:00
--sql="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
2018-01-30 23:44:49 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Setting up source files..." --weight=50
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
# Create empty dir for synapse
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE
2018-01-30 23:44:49 +01:00
# For any update do it in all files
mkdir -p /var/lib/matrix-$app
mkdir -p /var/log/matrix-$app
mkdir -p /etc/matrix-$app/conf.d
mkdir -p $final_path
# Install synapse in virtualenv
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE (2 times)
2018-01-30 23:44:49 +01:00
# For any update do it in all files
if [ -n "$(uname -m | grep arm)" ]
then
2019-04-30 19:15:33 +02:00
ynh_setup_source --dest_dir=$final_path/ --source_id="armv7_$(lsb_release --codename --short)"
2018-01-30 23:44:49 +01:00
else
# Install virtualenv if it don't exist
2018-12-21 08:51:45 +01:00
test -e $final_path/bin/python3 || python3 -m venv $final_path
2018-01-30 23:44:49 +01:00
# Install synapse in virtualenv
cp ../conf/virtualenv_activate $final_path/bin/activate
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__FINAL_PATH__ --replace_string=$final_path --target_file=$final_path/bin/activate
2018-07-05 21:46:24 +02:00
# We set all necessary environement variable to create a python virtualenvironnement.
2018-01-30 23:44:49 +01:00
source $final_path/bin/activate
2018-12-21 08:51:45 +01:00
pip3 install --upgrade pip
2019-01-19 23:19:14 +01:00
pip3 install --upgrade setuptools wheel
2019-07-05 08:25:18 +02:00
pip3 install --upgrade cffi ndg-httpsclient psycopg2 lxml jinja2
2019-02-08 14:53:18 +01:00
pip3 install --upgrade matrix-synapse==$upstream_version matrix-synapse-ldap3
2018-07-05 21:46:24 +02:00
2018-08-21 07:27:01 +02:00
# This function was defined when we called "source $final_path/bin/activate". With this function we undo what "$final_path/bin/activate" does
2018-01-30 23:44:49 +01:00
deactivate
fi
#=================================================
2019-02-08 11:24:08 +01:00
# CREATE SYNAPSE CONFIG
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Creating synapse config..." --weight=3
# Go in virtualenvironnement
PS1=${PS1:-}
source $final_path/bin/activate
2019-02-08 11:24:08 +01:00
# Generate config
2019-05-11 14:45:00 +02:00
python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $server_name --report-stats=no -c homeserver.yml
2018-08-21 07:27:01 +02:00
# This function was defined when we called "source $final_path/bin/activate". With this function we undo what "$final_path/bin/activate" does
deactivate
2018-08-21 07:27:01 +02:00
# Get random values from config
2019-06-02 00:09:14 +02:00
ynh_print_OFF
2019-11-19 20:29:11 +01:00
registration_shared_secret=$(egrep "^registration_shared_secret:" homeserver.yml | cut -d'"' -f2)
form_secret=$(egrep "^form_secret:" homeserver.yml | cut -d'"' -f2)
macaroon_secret_key=$(egrep "^macaroon_secret_key:" homeserver.yml | cut -d'"' -f2)
# store in yunohost settings
2019-04-30 19:15:33 +02:00
ynh_app_setting_set --app=$app --key=registration_shared_secret --value="$registration_shared_secret"
ynh_app_setting_set --app=$app --key=form_secret --value="$form_secret"
ynh_app_setting_set --app=$app --key=macaroon_secret_key --value="$macaroon_secret_key"
2019-06-02 00:09:14 +02:00
ynh_print_ON
2018-01-30 23:44:49 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring a systemd service..." --weight=2
# Create systemd service for synapse and turnserver
cp ../conf/default_matrix-synapse /etc/default/matrix-$app
2019-04-30 19:15:33 +02:00
ynh_add_systemd_config --service=matrix-$app --template=matrix-synapse.service
cp ../conf/default_coturn /etc/default/coturn-$app
2019-04-30 19:15:33 +02:00
ynh_add_systemd_config --service=coturn-$app --template=coturn-synapse.service
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring nginx web server..." --weight=2
2018-01-30 23:44:49 +01:00
ynh_add_nginx_config
2017-02-13 20:43:41 +01:00
2018-01-30 23:44:49 +01:00
#=================================================
# SET SYNAPSE CONFIG
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring synapse..." --weight=2
2018-01-30 23:44:49 +01:00
# Find password for turnserver and database
2019-06-02 00:09:14 +02:00
ynh_print_OFF
2019-04-30 19:15:33 +02:00
turnserver_pwd=$(ynh_string_random --length=30)
ynh_app_setting_set --app=$app --key=turnserver_pwd --value=$turnserver_pwd
2019-06-02 00:09:14 +02:00
ynh_print_ON
2018-01-30 23:44:49 +01:00
2017-02-13 20:43:41 +01:00
# Configure Synapse
2019-02-08 20:01:35 +01:00
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG (3 times)
2018-01-30 23:44:49 +01:00
# For any update do it in all files
homeserver_config_path="/etc/matrix-$app/homeserver.yaml"
cp ../conf/homeserver.yaml "$homeserver_config_path"
2018-01-30 23:44:49 +01:00
cp ../conf/log.yaml /etc/matrix-$app/log.yaml
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$homeserver_config_path"
ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$homeserver_config_path"
ynh_replace_string --match_string=__SERVER_NAME__ --replace_string=$server_name --target_file="$homeserver_config_path"
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__SYNAPSE_DB_USER__ --replace_string=$synapse_db_user --target_file="$homeserver_config_path"
ynh_replace_string --match_string=__PORT__ --replace_string=$port --target_file="$homeserver_config_path"
ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$synapse_tls_port --target_file="$homeserver_config_path"
ynh_replace_string --match_string=__TURNSERVER_TLS_PORT__ --replace_string=$turnserver_tls_port --target_file="$homeserver_config_path"
2019-06-02 00:09:14 +02:00
ynh_replace_string --match_string=__REPORT_STATS__ --replace_string="$report_stats" --target_file="$homeserver_config_path"
2019-11-11 21:43:19 +01:00
ynh_replace_string --match_string=__ALLOW_PUBLIC_ROOMS__ --replace_string="$allow_public_rooms" --target_file="$homeserver_config_path"
2019-06-02 00:09:14 +02:00
ynh_print_OFF
ynh_replace_special_string --match_string=__SYNAPSE_DB_PWD__ --replace_string=$synapse_db_pwd --target_file="$homeserver_config_path"
2019-04-30 19:15:33 +02:00
ynh_replace_special_string --match_string=__TURNPWD__ --replace_string=$turnserver_pwd --target_file="$homeserver_config_path"
ynh_replace_special_string --match_string=__REGISTRATION_SECRET__ --replace_string="$registration_shared_secret" --target_file="$homeserver_config_path"
ynh_replace_special_string --match_string=__FORM_SECRET__ --replace_string="$form_secret" --target_file="$homeserver_config_path"
ynh_replace_special_string --match_string=__MACAROON_SECRET_KEY__ --replace_string="$macaroon_secret_key" --target_file="$homeserver_config_path"
2019-06-02 00:09:14 +02:00
ynh_print_ON
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="/etc/matrix-$app/log.yaml"
if [ $is_public -eq 0 ]
2018-01-30 23:44:49 +01:00
then
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__ALLOWED_ACCESS__ --replace_string=False --target_file="$homeserver_config_path"
2018-01-30 23:44:49 +01:00
else
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__ALLOWED_ACCESS__ --replace_string=True --target_file="$homeserver_config_path"
2018-01-30 23:44:49 +01:00
fi
2019-04-30 19:15:33 +02:00
ynh_store_file_checksum --file="$homeserver_config_path"
ynh_store_file_checksum --file="/etc/matrix-$app/log.yaml"
2018-01-30 23:44:49 +01:00
well-known support (#136) * Update README.md * Update manifest.json * a * Delete a * avoid boolean for public but ask a clear choice Yes/No * Update check_process Add server_name="domain2.tld" (DOMAIN) * .well-known DNS conf become optionnal with .well-known edition * .well-known redirection for access by federation Create .well-known redirection for access by federation * .well-known redirection for access by federation If not existing, create .well-known redirection for access by federation * Update README.md back to 0.99.5.2 * back to 0.99.5.2 * back to 0.99.5.2 * back to 0.99.5.2 * Update install * Update upgrade * Update install * Update upgrade * Update install * Update upgrade * Update .well-known redirection for access by federation and applications like Riot.im * Update .well-known redirection for access by federation and applications like Riot.im * update to 1.1.0 * update to 1.1.0 * update to 1.1.0 * update to 1.1.0 * update to 1.1.0 * update to 1.1.0 * Update install * Update upgrade * Update to 1.2.1 * Update to 1.2.1 * Update to 1.2.1 * Back to v1.1.0 * Back to v1.1.0 * Back to v1.1.0 * Update to v1.2.1 * Update to v1.2.1 * Update to v1.2.1 * Important update of upgrade script ynh_replace_string __SERVER_NAME__ $server_name "$homeserver_config_path" was missing * Back to v1.1.0 * Back to v1.1.0 * Back to v1.1.0 * Fix typo for ipv6 validation * Upgrade to v1.2.1 * Upgrade to v1.2.1 * Upgrade to v1.2.1 * remove server_name's nginx conf remove /etc/nginx/conf.d/${server_name}.d/server_name.conf * Create server_name.conf To allow the automatic well-known system for server-name detection instead of DNS record * Update install In # Create .well-known redirection for access by federation change cat > /etc/nginx/conf.d/${server_name}.d/server_name.conf <<EOF location /.well-known/matrix/ { return 200 '{"m.server": "$domain", "m.homeserver": "https://$domain"}'; add_header Content-Type application/json; add_header Access-Control-Allow-Origin '*'; } EOF to cp ../conf/server_name.conf /etc/nginx/conf.d/${server_name}.d/server_name.conf after creation of ../conf/server_name.conf file. * Update upgrade In # Create .well-known redirection for access by federation if it doesn't exist change cat > /etc/nginx/conf.d/${server_name}.d/server_name.conf <<EOF location /.well-known/matrix/ { return 200 '{"m.server": "$domain", "m.homeserver": "https://$domain"}'; add_header Content-Type application/json; add_header Access-Control-Allow-Origin '*'; } EOF to cp ../conf/server_name.conf /etc/nginx/conf.d/${server_name}.d/server_name.conf * backup well.known server_name nginx cond add ynh_backup "/etc/nginx/conf.d/${server_name}.d/server_name.conf" * Backup well.known server-name nging conf add server_name=$(ynh_app_setting_get $app server_name) to make ynh_backup "/etc/nginx/conf.d/${server_name}.d/server_name.conf" understood * Update backup * Update scripts/install Co-Authored-By: Josue-T <josue@tille.ch> * Update install * Update README.md Co-Authored-By: Josue-T <josue@tille.ch> * Update scripts/upgrade Co-Authored-By: Josue-T <josue@tille.ch> * Update conf/server_name.conf Co-Authored-By: Josue-T <josue@tille.ch> * move .well-known redirection to config section move #Create .well-known redirection for access by federation to end of config section * move .well-known redirection to config section move #Create .well-known redirection to the end of config section and Indentation * add checksum management for server_name.conf add checksum management for server_name.conf with the helper ynh_store_file_checksum * add checksum management for server_name.conf add checksum management for server_name.conf with the helper ynh_store_file_checksum * replace __SERVER_NAME__ * replace __SERVER_NAME__ * delete a blank line * Update upgrade * Update install * Update check_process Co-Authored-By: Josue-T <josue@tille.ch> * Update conf/server_name.conf Co-Authored-By: Josue-T <josue@tille.ch> * remove blank line * ynh_store_file_checksum after cp inside if block * change order checksum and cp change order to ynh_backup_if_checksum_is_different then cp then ynh_store_file_checksum * Update install * Update upgrade * Update backup * Update backup * Update scripts/backup Co-Authored-By: Josue-T <josue@tille.ch> * Update scripts/install Co-Authored-By: Josue-T <josue@tille.ch> * Update scripts/install Co-Authored-By: Josue-T <josue@tille.ch> * Update scripts/install Co-Authored-By: Josue-T <josue@tille.ch> * Update install * Update remove * Update upgrade
2019-12-01 22:18:56 +01:00
# Create .well-known redirection for access by federation
if yunohost --output-as plain domain list | grep -q "^$server_name$"
then
cp ../conf/server_name.conf /etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf
ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
ynh_replace_string --match_string=__PORT__ --replace_string=$synapse_tls_port --target_file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
ynh_store_file_checksum --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf"
fi
2018-01-30 23:44:49 +01:00
#=================================================
# SET COTURN CONFIG
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring coturn..." --weight=1
2018-01-30 23:44:49 +01:00
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE
2018-01-30 23:44:49 +01:00
# For any update do it in all files
coturn_config_path="/etc/matrix-$app/coturn.conf"
cp ../conf/turnserver.conf "$coturn_config_path"
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$coturn_config_path"
ynh_replace_string --match_string=__DOMAIN__ --replace_string=$domain --target_file="$coturn_config_path"
ynh_replace_string --match_string=__TLS_PORT__ --replace_string=$turnserver_tls_port --target_file="$coturn_config_path"
ynh_replace_string --match_string=__TLS_ALT_PORT__ --replace_string=$turnserver_alt_tls_port --target_file="$coturn_config_path"
ynh_replace_string --match_string=__CLI_PORT__ --replace_string=$cli_port --target_file="$coturn_config_path"
2019-06-02 00:09:14 +02:00
ynh_print_OFF
ynh_replace_string --match_string=__TURNPWD__ --replace_string=$turnserver_pwd --target_file="$coturn_config_path"
ynh_print_ON
2018-01-30 23:44:49 +01:00
# Get public IP and set as external IP for coturn
2018-05-10 14:23:26 +02:00
# 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
2019-04-30 19:15:33 +02:00
if [ -n "$public_ip4" ] && ynh_validate_ip4 --ip_address="$public_ip4"
then
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string='__IPV4__' --replace_string="$public_ip4" --target_file="$coturn_config_path"
else
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string='__IPV4__,' --replace_string="" --target_file="$coturn_config_path"
fi
2019-04-30 19:15:33 +02:00
if [ -n "$public_ip6" ] && ynh_validate_ip6 --ip_address="$public_ip6"
then
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string='__IPV6__' --replace_string="$public_ip6" --target_file="$coturn_config_path"
else
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=',__IPV6__' --replace_string="" --target_file="$coturn_config_path"
fi
2019-04-30 19:15:33 +02:00
ynh_store_file_checksum --file="$coturn_config_path"
2018-01-30 23:44:49 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring log rotation..." --weight=2
2017-02-13 20:43:41 +01:00
2019-09-30 10:37:22 +02:00
ynh_use_logrotate --logfile "/var/log/matrix-$app"
2017-02-13 20:43:41 +01:00
#=================================================
# ADD SCRIPT FOR COTURN CRON
#=================================================
2018-08-03 15:58:40 +02:00
# WARNING : theses command are used in INSTALL, UPGRADE
# For any update do it in all files
cp ../sources/Coturn_config_rotate.sh $final_path/
2019-04-30 19:15:33 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$final_path/Coturn_config_rotate.sh"
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring SSOwat..." --weight=1
2018-01-30 23:44:49 +01: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 ../conf/add_sso_conf.py || ynh_die --message="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"
2018-01-30 23:44:49 +01:00
#=================================================
# UPDATE HOOKS
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE
# For any update do it in all files
ynh_replace_string __APP__ $app ../hooks/post_cert_update
ynh_replace_string __DOMAIN__ $domain ../hooks/post_cert_update
2018-01-30 23:44:49 +01:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# 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
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-05-11 15:01:17 +02:00
chmod 600 /etc/matrix-$app/$server_name.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
2019-04-30 19:15:33 +02:00
yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log"
yunohost service add coturn-$app
2017-05-26 15:29:12 +02:00
2018-01-30 23:44:49 +01:00
#=================================================
# RELOAD SERVICES
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Restarting synapse services..." --weight=11
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_systemd_action --service_name=coturn-$app.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $synapse_tls_port" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
2018-03-13 16:50:27 +01:00
#=================================================
2019-02-12 21:24:25 +01:00
# SETUP FAIL2BAN
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring fail2ban..." --weight=10
2019-02-12 21:24:25 +01:00
# WARNING : theses command are used in INSTALL, UPGRADE
# For any update do it in all files
2019-04-30 19:15:33 +02:00
ynh_add_fail2ban_config --use_template
2019-02-12 21:24:25 +01:00
#=================================================
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
2019-04-30 19:15:33 +02:00
echo "If your server name is identical to the domain on which synapse is installed, and the default port 8448 is used, your server is normally already accessible by the federation.
2019-02-08 15:27:41 +01:00
If not, you may need to put the following line in the dns configuration:
2018-03-13 16:50:27 +01:00
_matrix._tcp.$domain. 3600 IN SRV 10 0 $synapse_tls_port $domain.
2019-02-08 15:27:41 +01:00
For more details, see : https://github.com/matrix-org/synapse#setting-up-federation
2018-03-13 16:50:27 +01:00
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
2019-02-08 11:24:08 +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
2019-04-30 19:15:33 +02:00
You also need a valid TLS certificate for the domain used by synapse. To do that you can refer to the documentation here : https://yunohost.org/#/certificate_en" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --type="install"
#=================================================
# END OF SCRIPT
#=================================================
2018-03-13 16:50:27 +01:00
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Installation of $app completed" --last