diff --git a/.gitignore b/.gitignore index 4c3f96c..9d6d968 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ auto_update_config.sh auto_update/Synapse_build_*.log auto_update/synapse_build_temp.log +*~ +*.sw[op] +.DS_Store diff --git a/conf/extra_php-fpm.conf b/conf/extra_php-fpm.conf deleted file mode 100644 index f796032..0000000 --- a/conf/extra_php-fpm.conf +++ /dev/null @@ -1,4 +0,0 @@ -; Additional php.ini defines, specific to this pool of workers. - -php_admin_value[upload_max_filesize] = 100M -php_admin_value[post_max_size] = 100M diff --git a/conf/log.yaml b/conf/log.yaml index 447f584..5a726b0 100644 --- a/conf/log.yaml +++ b/conf/log.yaml @@ -1,3 +1,4 @@ +# WARNING: Don't edit this file. All change will be removed after each app upgrade version: 1 diff --git a/conf/nginx.conf b/conf/nginx.conf index a2e70d2..f78532d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -17,7 +17,7 @@ location /_matrix/ { location /_matrix/cas_server.php/ { alias /var/www/__APP__/; fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + fastcgi_pass unix:/run/php/php__PHP_VERSION__-fpm-__APP__.sock; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; diff --git a/conf/turnserver.conf b/conf/turnserver.conf index 9575f9e..75f8599 100644 --- a/conf/turnserver.conf +++ b/conf/turnserver.conf @@ -1,3 +1,5 @@ +# WARNING: Don't edit this file. All change will be removed after each app upgrade + use-auth-secret static-auth-secret={{ turnserver_pwd }} cli-password={{ turnserver_cli_pwd }} diff --git a/manifest.toml b/manifest.toml index 1c12810..2916b77 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,8 @@ cpe = "cpe:2.3:a:matrix:synapse" fund = "https://matrix.org/support/#" [integration] -yunohost = ">= 11.2.13" +yunohost = ">= 11.2.30" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = true @@ -78,7 +79,7 @@ ram.runtime = "1G" [resources.install_dir] dir = "/var/www/__APP__" owner = "__APP__:rwX" - group = "__APP__:rX" + group = "www-data:r-x" [resources.data_dir] dir = "/home/yunohost.app/__APP__" diff --git a/scripts/_common.sh b/scripts/_common.sh index 397e1f4..dfc0611 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,12 +7,12 @@ install_sources() { # Clean venv is it was on python2.7 or python3 with old version in case major upgrade of debian if [ ! -e "$code_dir"/bin/python3 ] || [ ! -e "$code_dir/lib/python$python_version" ]; then - ynh_secure_remove --file="$code_dir"/bin - ynh_secure_remove --file="$code_dir"/lib - ynh_secure_remove --file="$code_dir"/lib64 - ynh_secure_remove --file="$code_dir"/include - ynh_secure_remove --file="$code_dir"/share - ynh_secure_remove --file="$code_dir"/pyvenv.cfg + ynh_safe_rm "$code_dir"/bin + ynh_safe_rm "$code_dir"/lib + ynh_safe_rm "$code_dir"/lib64 + ynh_safe_rm "$code_dir"/include + ynh_safe_rm "$code_dir"/share + ynh_safe_rm "$code_dir"/pyvenv.cfg fi mkdir -p "$code_dir" @@ -21,17 +21,17 @@ install_sources() { if [ -n "$(uname -m | grep arm)" ] then # Clean old file, sometimes it could make some big issues if we don't do this!! - ynh_secure_remove --file="$code_dir"/bin - ynh_secure_remove --file="$code_dir"/lib - ynh_secure_remove --file="$code_dir"/include - ynh_secure_remove --file="$code_dir"/share + ynh_safe_rm "$code_dir"/bin + ynh_safe_rm "$code_dir"/lib + ynh_safe_rm "$code_dir"/include + ynh_safe_rm "$code_dir"/share ynh_setup_source --dest_dir="$code_dir"/ --source_id="synapse_prebuilt_armv7_$(lsb_release --codename --short)" # Fix multi-instance support for f in "$code_dir"/bin/*; do if ! [[ $f =~ "__" ]]; then - ynh_replace_special_string --match_string='#!/opt/yunohost/matrix-synapse' --replace_string='#!'"$code_dir" --target_file="$f" + ynh_replace_regex --match='#!/opt/yunohost/matrix-synapse' --replace='#!'"$code_dir" --file="$f" fi done else @@ -64,15 +64,15 @@ configure_coturn() { public_ip6="$(curl -s ipv6.yunohost.org)" || true local turn_external_ip="" - if [ -n "$public_ip4" ] && ynh_validate_ip4 --ip_address="$public_ip4" + if [ -n "$public_ip4" ] && ynh_validate_ip --family=4 --ip_address="$public_ip4" then turn_external_ip+="$public_ip4," fi - if [ -n "$public_ip6" ] && ynh_validate_ip6 --ip_address="$public_ip6" + if [ -n "$public_ip6" ] && ynh_validate_ip --family=6 --ip_address="$public_ip6" then turn_external_ip+="$public_ip6" fi - ynh_add_config --jinja --template="turnserver.conf" --destination="/etc/matrix-$app/coturn.conf" + ynh_config_add --jinja --template="turnserver.conf" --destination="/etc/matrix-$app/coturn.conf" } configure_nginx() { @@ -87,11 +87,11 @@ configure_nginx() { else e2e_enabled_by_default_client_config=true fi - ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" + ynh_config_add --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" fi # Create a dedicated NGINX config - ynh_add_nginx_config + ynh_config_add_nginx } ensure_vars_set() { @@ -110,7 +110,7 @@ ensure_vars_set() { element_path=$(ynh_app_setting_get --app=$element_instance --key=path) web_client_location="https://""$element_domain""$element_path" fi - ynh_app_setting_set --app="$app" --key=web_client_location --value="$web_client_location" + ynh_app_setting_set --key=web_client_location --value="$web_client_location" fi ynh_app_setting_set_default --app="$app" --key=client_base_url --value="$web_client_location" @@ -139,14 +139,18 @@ ensure_vars_set() { } set_permissions() { - chown $app:$app -R "$code_dir" - chmod o= -R "$code_dir" + chown -R "$app:$app" "$install_dir" + chmod -R u+rwX,g+rX-w,o= "$install_dir" - chmod 770 "$code_dir"/Coturn_config_rotate.sh + chown -R "$app":"$app" "$code_dir" + chmod -R u+rwX,g+rX-w,o= "$code_dir" + + chmod 750 "$code_dir"/Coturn_config_rotate.sh chmod 700 "$code_dir"/update_synapse_for_appservice.sh chmod 700 "$code_dir"/set_admin_user.sh if [ "${1:-}" == data ]; then + chmod 750 "$data_dir" find "$data_dir" \( \! -perm -o= \ -o \! -user "$app" \ -o \! -group "$app" \) \ diff --git a/scripts/backup b/scripts/backup index 087774c..38e7a0c 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source ../settings/scripts/experimental_helper.sh source /usr/share/yunohost/helpers @@ -15,13 +9,10 @@ source /usr/share/yunohost/helpers #================================================= if systemctl is-active "$app".service --quiet; then - ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service with this command before to run the backup 'systemctl stop $app.service'" + ynh_print_warn "It's hightly recommended to make your backup when the service is stopped. Please stop $app service with this command before to run the backup 'systemctl stop $app.service'" fi -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # STANDARD BACKUP STEPS @@ -29,34 +20,34 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$code_dir" -ynh_backup --src_path="$install_dir" +ynh_backup "$code_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= # BACKUP THE PHP-FPM CONFIGURATION -ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf" -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" if yunohost --output-as plain domain list | grep -q "^$server_name$" then - ynh_backup --src_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" + ynh_backup "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" fi #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_psql_dump_db --database="$db_name" > ${YNH_CWD}/dump.sql +ynh_psql_dump_db > ${YNH_CWD}/dump.sql #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +ynh_backup "/etc/fail2ban/jail.d/$app.conf" +ynh_backup "/etc/fail2ban/filter.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -64,36 +55,36 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" # BACKUP SYNAPSE CONFIG #================================================= -ynh_backup --src_path="/etc/matrix-$app" +ynh_backup "/etc/matrix-$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" -ynh_backup --src_path="/etc/systemd/system/$app-coturn.service" +ynh_backup "/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app-coturn.service" #================================================= # BACKUP SYNAPSE DATA #================================================= -ynh_backup --src_path="$data_dir" --is_big=1 +ynh_backup "$data_dir" #================================================= # BACKUP SYNAPSE LOG #================================================= -ynh_backup --src_path="/var/log/matrix-$app" --is_big=1 +ynh_backup "/var/log/matrix-$app" #================================================= # BACKUP HOOKS #================================================= # Copy hook -ynh_backup --src_path="/etc/yunohost/hooks.d/post_cert_update/50-$app" +ynh_backup "/etc/yunohost/hooks.d/post_cert_update/50-$app" #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 6363135..f4fc360 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -10,44 +10,42 @@ source ./_common.sh source /usr/share/yunohost/helpers # We stop the service -ynh_systemd_action --service_name="$app".service --action=stop +ynh_systemctl --service="$app".service --action=stop -#================================================= -# STANDARD MODIFICATIONS #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Updating NGINX configuration..." +ynh_script_progression "Updating NGINX configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx configure_nginx #================================================= # UPDATE SYNAPSE CONFIG #================================================= -ynh_script_progression --message="Updating Synapse config..." --weight=2 -ynh_add_config --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" -ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" +ynh_script_progression "Updating Synapse config..." +ynh_config_add --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" +ynh_config_add --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Protecting directories..." --weight=3 +ynh_script_progression "Protecting directories..." set_permissions #================================================= # RELOAD SERVICES #================================================= -ynh_script_progression --message="Restarting Synapse services..." --weight=5 +ynh_script_progression "Restarting Synapse services..." -ynh_systemd_action --service_name="$app"-coturn.service --action=restart -ynh_systemd_action --service_name="$app".service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 +ynh_systemctl --service="$app"-coturn.service --action=restart +ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 if ! yunohost --output-as plain domain list | grep -q "^$server_name"'$'; then ynh_print_warn "Note yunohost won't be able to manage the required config for $server_name. So please add the needed DNS config as described on the documentation" fi -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/config b/scripts/config index d9d23ea..7a9284a 100644 --- a/scripts/config +++ b/scripts/config @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ./experimental_helper.sh source ./_common.sh source /usr/share/yunohost/helpers @@ -27,13 +21,11 @@ ynh_app_config_validate() { ynh_app_config_apply() { _ynh_app_config_apply configure_nginx - ynh_add_config --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" - ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" + ynh_config_add --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" + ynh_config_add --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" set_permissions } -#================================================= -# GENERIC FINALIZATION #================================================= # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT #================================================= diff --git a/scripts/install b/scripts/install index ed99130..3c14a3a 100644 --- a/scripts/install +++ b/scripts/install @@ -8,20 +8,22 @@ source _common.sh source experimental_helper.sh source /usr/share/yunohost/helpers +ynh_app_setting_set --key=php_upload_max_filesize --value=100M + #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= if [ "$server_name" == "Same than the domain" ]; then server_name="$domain" - ynh_app_setting_set --app="$app" --key=server_name --value="$server_name" + ynh_app_setting_set --key=server_name --value="$server_name" fi #================================================= ## SET STANDARD SETTINGS FROM DEFAULT CONFIG #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 +ynh_script_progression "Storing installation settings..." ensure_vars_set @@ -34,11 +36,9 @@ else password_enabled=true fi -ynh_app_setting_set --app="$app" --key=password_enabled --value="$password_enabled" -ynh_app_setting_set --app="$app" --key=enable_registration --value="$enable_registration" +ynh_app_setting_set --key=password_enabled --value="$password_enabled" +ynh_app_setting_set --key=enable_registration --value="$enable_registration" -#================================================= -# STANDARD MODIFICATIONS #================================================= # Check datadir empty #================================================= @@ -53,7 +53,7 @@ fi #================================================= # CREATE A DH FILE #================================================= -ynh_script_progression --message="Creating a dh file..." --weight=3 +ynh_script_progression "Creating a dh file..." # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files @@ -61,7 +61,7 @@ ynh_script_progression --message="Creating a dh file..." --weight=3 # Make dh cert for synapse if it doesn't exist if [ ! -e /etc/ssl/private/dh2048.pem ] then - ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 + ynh_hide_warnings openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi @@ -69,7 +69,7 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message='Configuring system groups' +ynh_script_progression 'Configuring system groups' adduser "$app" ssl-cert adduser turnserver ssl-cert @@ -77,15 +77,15 @@ adduser turnserver ssl-cert #================================================= # FIX DB CONFIG #================================================= -ynh_script_progression --message="Fixing database type..." --weight=1 +ynh_script_progression "Fixing database type..." -ynh_psql_execute_as_root \ - --sql="update pg_database set datcollate='C', datctype='C' where datname='$db_name';" +ynh_psql_db_shell \ + <<< "update pg_database set datcollate='C', datctype='C' where datname='$db_name';" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=50 +ynh_script_progression "Setting up source files..." # Create empty dir for synapse @@ -106,17 +106,16 @@ install_sources # For any update do it in all files cp ../sources/cas_server.php "$install_dir"/ -chmod u=rwX,g=rX,o= -R "$install_dir" -chown "$app:$app" -R "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod u=rwX,g=rX,o= -R "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" -R "$install_dir" #================================================= # CREATE SYNAPSE CONFIG #================================================= -ynh_script_progression --message="Creating Synapse config..." --weight=3 +ynh_script_progression "Creating Synapse config..." # Generate config -$code_dir/bin/python -m synapse.app.homeserver --keys-directory /etc/matrix-"$app"/ --generate-config --server-name "$server_name" --report-stats=no -c homeserver.yml +"$code_dir"/bin/python -m synapse.app.homeserver --keys-directory /etc/matrix-"$app"/ --generate-config --server-name "$server_name" --report-stats=no -c homeserver.yml # Get random values from config registration_shared_secret="$(grep -E "^registration_shared_secret:" homeserver.yml | cut -d'"' -f2)" @@ -124,54 +123,54 @@ form_secret="$(grep -E "^form_secret:" homeserver.yml | cut -d'"' -f2)" macaroon_secret_key="$(grep -E "^macaroon_secret_key:" homeserver.yml | cut -d'"' -f2)" # store in yunohost settings -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" +ynh_app_setting_set --key=registration_shared_secret --value="$registration_shared_secret" +ynh_app_setting_set --key=form_secret --value="$form_secret" +ynh_app_setting_set --key=macaroon_secret_key --value="$macaroon_secret_key" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=2 +ynh_script_progression "Configuring $app's systemd service..." # Create systemd service for synapse and turnserver -ynh_add_systemd_config --service="$app" --template=synapse.service +ynh_config_add_systemd --template=synapse.service cp ../conf/default_coturn /etc/matrix-"$app"/coturn_env -ynh_add_systemd_config --service="$app"-coturn --template=synapse-coturn.service +ynh_config_add_systemd --service="$app"-coturn --template=synapse-coturn.service #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=2 +ynh_script_progression "Configuring NGINX web server..." # Create a dedicated php-fpm config -ynh_script_progression --message="Configuring application..." +ynh_script_progression "Configuring application..." -ynh_add_fpm_config --usage=low --footprint=low +ynh_config_add_phpfpm configure_nginx #================================================= # SET SYNAPSE CONFIG #================================================= -ynh_script_progression --message="Configuring Synapse..." --weight=2 +ynh_script_progression "Configuring Synapse..." -ynh_add_config --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" -ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" +ynh_config_add --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" +ynh_config_add --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" #================================================= # SET COTURN CONFIG #================================================= -ynh_script_progression --message="Configuring Coturn..." --weight=1 +ynh_script_progression "Configuring Coturn..." configure_coturn #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=2 +ynh_script_progression "Configuring log rotation..." -ynh_use_logrotate --logfile="/var/log/matrix-$app" +ynh_config_add_logrotate "/var/log/matrix-$app" #================================================= # ADD SCRIPT FOR COTURN CRON AND APP SERVICE @@ -180,17 +179,15 @@ ynh_use_logrotate --logfile="/var/log/matrix-$app" # WARNING : theses command are used in INSTALL, UPGRADE # For any update do it in all files -ynh_add_config --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" -ynh_add_config --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" -ynh_add_config --template=../sources/set_admin_user.sh --destination="$code_dir"/set_admin_user.sh +ynh_config_add --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" +ynh_config_add --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" +ynh_config_add --template=../sources/set_admin_user.sh --destination="$code_dir"/set_admin_user.sh -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP PERMISSIONS #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +ynh_script_progression "Configuring permissions..." if yunohost --output-as plain domain list | grep -q "^$server_name$"; then ynh_""permission_create --permission=server_client_infos --url="$server_name"/.well-known/matrix \ @@ -206,14 +203,14 @@ fi # 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 +ynh_replace --match=__APP__ --replace="$app" --file=../hooks/post_cert_update +ynh_replace --match=__DOMAIN__ --replace="$domain" --file=../hooks/post_cert_update #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Protecting directories..." --weight=3 +ynh_script_progression "Protecting directories..." set_permissions data #================================================= @@ -226,20 +223,20 @@ yunohost service add "$app"-coturn --needs_exposed_ports "$port_turnserver_tls" #================================================= # RELOAD SERVICES #================================================= -ynh_script_progression --message="Restarting Synapse services..." --weight=11 +ynh_script_progression "Restarting Synapse services..." -ynh_systemd_action --service_name="$app"-coturn.service --action=restart -ynh_systemd_action --service_name="$app".service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 +ynh_systemctl --service="$app"-coturn.service --action=restart +ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 #================================================= # SETUP FAIL2BAN #================================================= -ynh_script_progression --message="Configuring Fail2Ban..." --weight=10 +ynh_script_progression "Configuring Fail2Ban..." -ynh_add_fail2ban_config --use_template +ynh_config_add_fail2ban #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index e22e9a5..c9d1953 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source experimental_helper.sh source /usr/share/yunohost/helpers @@ -23,50 +17,50 @@ yunohost service remove "$app"-coturn #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service" --weight=2 +ynh_script_progression "Stopping and removing the systemd service" -ynh_remove_systemd_config --service="$app" -ynh_remove_systemd_config --service="$app"-coturn +ynh_config_remove_systemd + +ynh_config_remove_systemd "$app"-coturn #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory" --weight=2 +ynh_script_progression "Removing app main directory" -ynh_secure_remove --file="$code_dir" -ynh_secure_remove --file=/etc/matrix-"$app" -ynh_secure_remove --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +ynh_safe_rm "$code_dir" +ynh_safe_rm /etc/matrix-"$app" +ynh_safe_rm "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing NGINX web server configuration" --weight=2 +ynh_script_progression "Removing NGINX web server configuration" # Remove the dedicated nginx config -ynh_remove_nginx_config +ynh_config_remove_nginx # Remove the dedicated php-fpm config -ynh_remove_fpm_config +ynh_config_remove_phpfpm #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration" --weight=1 +ynh_script_progression "Removing logrotate configuration" # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=8 +ynh_script_progression "Removing Fail2Ban configuration..." # Remove the dedicated fail2ban config -ynh_remove_fail2ban_config +ynh_config_remove_fail2ban -#================================================= -# GENERIC FINALIZATION #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" + sleep 1 diff --git a/scripts/restore b/scripts/restore index 5e6f5ed..cf20764 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source ../settings/scripts/experimental_helper.sh @@ -14,72 +8,72 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression "Loading settings..." #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message='Configuring system groups' +ynh_script_progression 'Configuring system groups' # Create the dedicated user (if not existing) -adduser $app ssl-cert +adduser "$app" ssl-cert adduser turnserver ssl-cert #================================================= # FIX DB CONFIG #================================================= -ynh_script_progression --message="Fixing database type..." --weight=1 +ynh_script_progression "Fixing database type..." -ynh_psql_execute_as_root \ - --sql="update pg_database set datcollate='C', datctype='C' where datname='$db_name';" +ynh_psql_db_shell \ + <<< "update pg_database set datcollate='C', datctype='C' where datname='$db_name';" #================================================= # RESTORE ALL CONFIG AND DATA #================================================= -ynh_script_progression --message="Restoring directory and configuration..." --weight=10 -ynh_restore -mkdir -p /etc/matrix-$app/app-service +ynh_script_progression "Restoring directory and configuration..." +ynh_restore_everything +mkdir -p /etc/matrix-"$app"/app-service # Check that the good python version is installed # If not upgrade the source -ynh_script_progression --message="Check for source up to date..." --weight=5 +ynh_script_progression "Check for source up to date..." install_sources #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Reload Fail2Ban..." --weight=6 +ynh_script_progression "Reload Fail2Ban..." -ynh_systemd_action --action=restart --service_name=fail2ban +ynh_systemctl --action=restart --service=fail2ban #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=13 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$db_name" +ynh_psql_db_shell < "${YNH_CWD}/dump.sql" #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Enable systemd services" --weight=2 +ynh_script_progression "Enable systemd services" # systemctl daemon-reload -systemctl enable $app.service --quiet -systemctl enable $app-coturn.service --quiet +systemctl enable "$app".service --quiet +systemctl enable "$app"-coturn.service --quiet #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls --description 'Main matrix server service.' -yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls --description 'Turn server for matrix server. Used for audio and video call.' +yunohost service add "$app" --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls --description 'Main matrix server service.' +yunohost service add "$app-coturn" --needs_exposed_ports "$port_turnserver_tls" --description 'Turn server for matrix server. Used for audio and video call.' #================================================= # CREATE A DH FILE #================================================= -ynh_script_progression --message="Creating a dh file..." --weight=40 +ynh_script_progression "Creating a dh file..." # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files @@ -87,7 +81,7 @@ ynh_script_progression --message="Creating a dh file..." --weight=40 # Make dh cert for synapse if it doesn't exist if [ ! -e /etc/ssl/private/dh2048.pem ] then - ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 + ynh_hide_warnings openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi @@ -95,46 +89,42 @@ fi #================================================= # RECONFIGURE THE TURNSERVER #================================================= -ynh_script_progression --message="Reconfiguring Coturn..." --weight=23 +ynh_script_progression "Reconfiguring Coturn..." configure_coturn #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." +ynh_script_progression "Configuring log rotation..." -ynh_use_logrotate --logfile=/var/log/matrix-$app +ynh_config_add_logrotate /var/log/matrix-"$app" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Protecting directories..." --weight=3 +ynh_script_progression "Protecting directories..." set_permissions data #================================================= # RELOAD NGINX, SYNAPSE AND COTURN #================================================= -ynh_script_progression --message="Restarting Synapse services..." --weight=7 +ynh_script_progression "Restarting Synapse services..." -ynh_systemd_action --service_name=$app-coturn.service --action=restart -ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 +ynh_systemctl --service="$app"-coturn.service --action=restart +ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression "Reloading NGINX web server..." -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=php"$php_version"-fpm --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 5ed6a2a..13fde26 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,36 +1,28 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source experimental_helper.sh source /usr/share/yunohost/helpers +ynh_app_setting_set_default --key=php_upload_max_filesize --value=100M + #================================================= # SET ALL CONSTANT #================================================= -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # MIGRATION 5 : Manage old settings #================================================= # Migrate from settings 'special_domain' to 'domain' and 'special_path' to 'path' if [ -z "${domain:-}" ]; then - domain=$(ynh_app_setting_get --app=$app --key=special_domain) - path=$(ynh_app_setting_get --app=$app --key=special_path) - ynh_app_setting_set --app=$app --key=domain --value=$domain - ynh_app_setting_set --app=$app --key=path --value=$path - ynh_app_setting_delete --app=$app --key=special_domain - ynh_app_setting_delete --app=$app --key=special_path - ynh_app_setting_set --app=$app --key=no_sso --value=true + domain=$(ynh_app_setting_get --key=special_domain) + path=$(ynh_app_setting_get --key=special_path) + ynh_app_setting_set --key=domain --value=$domain + ynh_app_setting_set --key=path --value=$path + ynh_app_setting_delete --key=special_domain + ynh_app_setting_delete --key=special_path + ynh_app_setting_set --key=no_sso --value=true fi ensure_vars_set @@ -43,33 +35,33 @@ ynh_app_setting_set_default --app="$app" --key=jitsi_server --value='jitsi.riot. if [ "$e2e_enabled_by_default" = "true" ] ; then e2e_enabled_by_default="all" - ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default + ynh_app_setting_set --key=e2e_enabled_by_default --value=$e2e_enabled_by_default fi if [ "$e2e_enabled_by_default" = "false" ]; then e2e_enabled_by_default="off" - ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default + ynh_app_setting_set --key=e2e_enabled_by_default --value=$e2e_enabled_by_default fi if [ "${registrations_require_3pid}" == none ] then registrations_require_3pid=email - ynh_app_setting_set --app=$app --key=registrations_require_3pid --value=$registrations_require_3pid + ynh_app_setting_set --key=registrations_require_3pid --value=$registrations_require_3pid fi if [[ "${allowed_local_3pids_email}" =~ \'.*\' ]] # Also remove shit value from previous config panel then allowed_local_3pids_email='' - ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value=$allowed_local_3pids_email + ynh_app_setting_set --key=allowed_local_3pids_email --value=$allowed_local_3pids_email fi if [[ "${allowed_local_3pids_msisdn}" =~ \'.*\' ]] # Also remove shit value from previous config panel then allowed_local_3pids_msisdn='' - ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn + ynh_app_setting_set --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn fi if [ -z "${enable_registration:-}" ] then if [ -z "${is_free_registration:-}" ]; then - is_free_registration=$(ynh_app_setting_get --app=$app --key=is_""public) + is_free_registration=$(ynh_app_setting_get --key=is_""public) fi if [ "$is_free_registration" -eq "0" ] @@ -81,12 +73,12 @@ then enable_registration="true" password_enabled="true" fi - ynh_app_setting_set --app=$app --key=enable_registration --value=$enable_registration - ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled + ynh_app_setting_set --key=enable_registration --value=$enable_registration + ynh_app_setting_set --key=password_enabled --value=$password_enabled fi # remove legacy env file into /etc/default -ynh_secure_remove --file=/etc/default/coturn-$app +ynh_safe_rm /etc/default/coturn-$app #================================================= # MIGRATION 7 : STANDARDIZE SYSTEMD UNIT @@ -94,7 +86,7 @@ ynh_secure_remove --file=/etc/default/coturn-$app if [ -e /etc/systemd/system/matrix-$app.service ] then - ynh_script_progression --message='Migrating systemd unit to standard name...' + ynh_script_progression 'Migrating systemd unit to standard name...' systemctl stop matrix-$app.service || true systemctl stop coturn-$app.service || true @@ -102,8 +94,8 @@ then yunohost service remove matrix-$app || true yunohost service remove coturn-$app || true - ynh_secure_remove --file=/etc/systemd/system/matrix-$app.service - ynh_secure_remove --file=/etc/systemd/system/coturn-$app.service + ynh_safe_rm /etc/systemd/system/matrix-$app.service + ynh_safe_rm /etc/systemd/system/coturn-$app.service touch /etc/systemd/system/$app.service systemctl daemon-reload || true @@ -114,16 +106,16 @@ fi #================================================= # We stop the service -ynh_systemd_action --service_name=$app.service --action=stop +ynh_systemctl --service=$app.service --action=stop -ynh_script_progression --message='Managing migrations...' +ynh_script_progression 'Managing migrations...' #================================================= # MIGRATION 6 : Migrate data directory #================================================= if [ -e "/var/lib/matrix-$app" ]; then - ynh_script_progression --message="Moving data directory to $data_dir..." --weight=1 + ynh_script_progression "Moving data directory to $data_dir..." if [ -e "$data_dir" ]; then old_data_dir_path="$data_dir$(date '+%Y%m%d.%H%M%S')" ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path" @@ -139,7 +131,7 @@ fi # Fix issue about certificates access if [ ! $(grep "ssl-cert:x:[0-9]*:.*$app" /etc/group) ] then - ynh_script_progression --message="Use standard access for certificate..." --weight=1 + ynh_script_progression "Use standard access for certificate..." adduser $app ssl-cert adduser turnserver ssl-cert @@ -155,9 +147,9 @@ fi # Make dh cert for synapse if it doesn't exist if [ ! -e /etc/ssl/private/dh2048.pem ] then - ynh_script_progression --message="Creating a dh file..." --weight=1 + ynh_script_progression "Creating a dh file..." - ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 + ynh_hide_warnings openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -dsaparam 2048 chown root:ssl-cert /etc/ssl/private/dh2048.pem chmod 640 /etc/ssl/private/dh2048.pem fi @@ -168,7 +160,7 @@ fi if [ ! -e /etc/matrix-$app/coturn.conf ] then - ynh_script_progression --message="Creating an independant service for coturn..." --weight=1 + ynh_script_progression "Creating an independant service for coturn..." #================================================= # CREATE AN INDEPENDANT SERVICE FOR COTURN @@ -181,21 +173,21 @@ then # MAKE A CLEAN LOGROTATE CONFIG #================================================= - ynh_use_logrotate --logfile=/var/log/matrix-$app --nonappend + ynh_config_add_logrotate /var/log/matrix-$app fi #================================================= # MIGRATION 8 : Migrate database to managed database (Migrate db name from matrix_$app to $app) #================================================= -if ynh_psql_execute_as_root --sql='\list' | grep matrix_$app; then +if ynh_psql_db_shell <<< '\list' | grep matrix_$app; then ynh_''psql_remove_db --db_user="user_wich_must_dont_exist_and_keep_current_user" --db_name=$db_name - ynh_psql_execute_as_root --sql="ALTER DATABASE matrix_$app RENAME TO $db_name;" - ynh_psql_execute_as_root --database=$db_name --sql="REASSIGN OWNED BY matrix_$app TO $db_user;" - ynh_psql_execute_as_root --sql="UPDATE pg_database SET datcollate='C', datctype='C' WHERE datname='$db_name';" - ynh_psql_execute_as_root --sql="DROP USER matrix_$app;" + ynh_psql_db_shell <<< "ALTER DATABASE matrix_$app RENAME TO $db_name;" + ynh_psql_db_shell <<< "REASSIGN OWNED BY matrix_$app TO $db_user;" + ynh_psql_db_shell <<< "UPDATE pg_database SET datcollate='C', datctype='C' WHERE datname='$db_name';" + ynh_psql_db_shell <<< "DROP USER matrix_$app;" # for unknown reason we need to set again the password for synapse user. Without this synapse can't authenticate to postgresql - ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH ENCRYPTED PASSWORD '$db_pwd';" + ynh_psql_db_shell <<< "ALTER USER $db_user WITH ENCRYPTED PASSWORD '$db_pwd';" fi #================================================= @@ -204,14 +196,14 @@ fi if [ -e /home/yunohost.app/matrix-$app ]; then mv -t $data_dir /home/yunohost.app/matrix-$app/* - ynh_secure_remove --file=/home/yunohost.app/matrix-$app + ynh_safe_rm /home/yunohost.app/matrix-$app fi #================================================= # MIGRATION 11 : make this app using full domain #================================================= -ynh_app_setting_set --app=$app --key=path --value=/ +ynh_app_setting_set --key=path --value=/ if yunohost app map -r --output-as json | jq -r '."'$domain'" | select( . != null ) | .[] | .id' | grep -v "$app" -q; then ynh_print_warn 'An other app is installed on this domain. Now synapse require to be alone on the domain.' @@ -239,11 +231,8 @@ fi # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] || [ ! -e $code_dir/bin/python3 ] || [ ! -e $code_dir/lib/python$python_version ] -then - ynh_script_progression --message="Upgrading source files..." --weight=6 - install_sources -fi +ynh_script_progression "Upgrading source files..." +install_sources #================================================= # MIGRATION 1 : GENERATE SYNAPSE SECRET @@ -251,30 +240,28 @@ fi if [ -z "${registration_shared_secret:-}" ] || [ "$form_secret" == "form_secret: " ] then - ynh_script_progression --message="Generating synapse secret..." --weight=1 + ynh_script_progression "Generating synapse secret..." # Generate config and keys - $code_dir/bin/python -m synapse.app.homeserver --keys-directory /etc/matrix-$app/ --generate-config --generate-keys --server-name $server_name --report-stats=no -c homeserver.yml + "$code_dir"/bin/python -m synapse.app.homeserver --keys-directory /etc/matrix-"$app"/ --generate-config --generate-keys --server-name "$server_name" --report-stats=no -c homeserver.yml # Get random values from config registration_shared_secret=$(egrep "^registration_shared_secret:" homeserver.yml | cut -d'"' -f2) form_secret=$(egrep "^form_secret:" homeserver.yml | cut -d'"' -f2) # store in yunohost settings - 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 --key=registration_shared_secret --value="$registration_shared_secret" + ynh_app_setting_set --key=form_secret --value="$form_secret" fi -#================================================= -# STANDARD UPGRADE STEPS #================================================= #================================================= # UPDATE SYNAPSE CONFIG #================================================= -ynh_script_progression --message="Updating synapse config..." --weight=2 -ynh_add_config --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" -ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" +ynh_script_progression "Updating synapse config..." +ynh_config_add --jinja --template="homeserver.yaml" --destination="/etc/matrix-$app/homeserver.yaml" +ynh_config_add --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" #================================================= # CREATE SMALL CAS SERVER @@ -282,30 +269,27 @@ ynh_add_config --template="log.yaml" --destination="/etc/matrix-$app/log.yaml" # WARNING : theses command are used in INSTALL, UPGRADE # For any update do it in all files -mkdir -p $install_dir -cp ../sources/cas_server.php $install_dir/ -chmod u=rwX,g=rX,o= -R $install_dir -chown $app:root -R $install_dir - +mkdir -p "$install_dir" +cp ../sources/cas_server.php "$install_dir"/ +chmod u=rwX,g=rX,o= -R "$install_dir" +chown "$app":root -R "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 +ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated php-fpm config -ynh_script_progression --message="Configuring application..." +ynh_script_progression "Configuring application..." -ynh_add_fpm_config --usage=low --footprint=low +ynh_config_add_phpfpm configure_nginx -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE COTURN CONFIG #================================================= -ynh_script_progression --message="Updating Coturn config..." --weight=1 +ynh_script_progression "Updating Coturn config..." configure_coturn @@ -316,9 +300,9 @@ configure_coturn # WARNING : theses command are used in INSTALL, UPGRADE # For any update do it in all files -ynh_add_config --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" -ynh_add_config --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" -ynh_add_config --template=../sources/set_admin_user.sh --destination=$code_dir/set_admin_user.sh +ynh_config_add --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" +ynh_config_add --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" +ynh_config_add --template=../sources/set_admin_user.sh --destination=$code_dir/set_admin_user.sh # Ensure app-service folder has exists and the config file exit (Migration) mkdir -p /etc/matrix-$app/app-service @@ -335,42 +319,40 @@ fi # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls --description 'Main matrix server service.' -yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls --description 'Turn server for matrix server. Used for audio and video call.' +yunohost service add "$app" --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports "$port_synapse_tls" --description 'Main matrix server service.' +yunohost service add "$app"-coturn --needs_exposed_ports "$port_turnserver_tls" --description 'Turn server for matrix server. Used for audio and video call.' #================================================= # UPDATE SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=3 +ynh_script_progression "Upgrading systemd configuration..." # Create systemd service for synapse and turnserver -ynh_add_systemd_config --service=$app --template=synapse.service +ynh_config_add_systemd --template=synapse.service -cp ../conf/default_coturn /etc/matrix-$app/coturn_env -ynh_add_systemd_config --service=$app-coturn --template=synapse-coturn.service +cp ../conf/default_coturn /etc/matrix-"$app"/coturn_env +ynh_config_add_systemd --service="$app"-coturn --template=synapse-coturn.service #================================================= # UPGRADE FAIL2BAN #================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8 +ynh_script_progression "Reconfiguring Fail2Ban..." -ynh_add_fail2ban_config --use_template +ynh_config_add_fail2ban -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP PERMISSIONS #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +ynh_script_progression "Configuring permissions..." if yunohost --output-as plain domain list | grep -q "^$server_name"'$'; then if ! ynh_""permission_exists --permission=server_client_infos; then - ynh_""permission_create --permission=server_client_infos --url=$server_name/.well-known/matrix \ + ynh_""permission_create --permission=server_client_infos --url="$server_name"/.well-known/matrix \ --label="Server info for clients. (well-known)" --show_tile=false --allowed=visitors \ --auth_header=false --protected=true else yunohost --output-as plain domain list | grep -q "^$server_name"'$' - ynh_""permission_url --permission=server_client_infos --url=$server_name/.well-known/matrix \ + ynh_""permission_url --permission=server_client_infos --url="$server_name"/.well-known/matrix \ --auth_header=false ynh_""permission_update --permission=server_client_infos --label="Server info for clients. (well-known)" --show_tile=false \ --protected=true @@ -381,7 +363,7 @@ fi # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Protecting directories... (note that it could take a long time depending of your install size)" --weight=3 +ynh_script_progression "Protecting directories... (note that it could take a long time depending of your install size)" set_permissions data #================================================= @@ -390,19 +372,19 @@ set_permissions data # 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 +ynh_replace --match=__APP__ --replace="$app" --file=../hooks/post_cert_update +ynh_replace --match=__DOMAIN__ --replace="$domain" --file=../hooks/post_cert_update #================================================= # RELOAD SERVICES #================================================= -ynh_script_progression --message="Restarting Synapse services..." --weight=5 +ynh_script_progression "Restarting Synapse services..." -ynh_systemd_action --service_name=$app-coturn.service --action=restart -ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 +ynh_systemctl --service="$app"-coturn.service --action=restart +ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" diff --git a/sources/set_admin_user.sh b/sources/set_admin_user.sh index 2bbee3a..8a33acb 100644 --- a/sources/set_admin_user.sh +++ b/sources/set_admin_user.sh @@ -5,17 +5,19 @@ set -eu source /usr/share/yunohost/helpers app=__APP__ +YNH_APP_BASEDIR=/etc/yunohost/apps/"$app" +YNH_HELPERS_VERSION=2.1 -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) -server_name=$(ynh_app_setting_get --app=$app --key=server_name) +db_name=$(ynh_app_setting_get --key=db_name) +db_user=$(ynh_app_setting_get --key=db_user) +db_pwd=$(ynh_app_setting_get --key=db_pwd) +server_name=$(ynh_app_setting_get --key=server_name) if [ -z ${1:-} ]; then echo "Usage: set_admin_user.sh user_to_set_as_admin" exit 1 fi -ynh_psql_execute_as_root --database=$db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$1:$server_name'" +ynh_psql_db_shell --database=$db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$1:$server_name'" exit 0 diff --git a/tests.toml b/tests.toml index 66f2d88..ca89ae3 100644 --- a/tests.toml +++ b/tests.toml @@ -4,6 +4,6 @@ test_format = 1.0 [default] - test_upgrade_from.9f273cac72baad192f046620dae33a97cd0ec749.name = "Post app user creation (branch old_version_for_CI_7)" - test_upgrade_from.3b5a58e5d8b83f292c6160e8908ac662360aa03e.name = "Before packaging v2 (branch old_version_for_CI_6)" + test_upgrade_from.9f273cac72baad192f046620dae33a97cd0ec749.name = "Post app user creation (branch old_version_for_CI_7)" + test_upgrade_from.8ab6186bede11c5856886a8978428a0f09b6d08d.name = "Before helper 2.1"