diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/README.md b/README.md index 0da433f..9be75ac 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It shall NOT be edited by hand. # Dendrite for YunoHost -[![Integration level](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![Working status](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![Working status](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![Install Dendrite with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/README_es.md b/README_es.md index d42f36d..7c66dcc 100644 --- a/README_es.md +++ b/README_es.md @@ -5,7 +5,7 @@ No se debe editar a mano. # Dendrite para Yunohost -[![Nivel de integración](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![Estado funcional](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Estado En Mantención](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![Nivel de integración](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![Estado funcional](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Estado En Mantención](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![Instalar Dendrite con Yunhost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/README_eu.md b/README_eu.md index 85e1aaf..873b15c 100644 --- a/README_eu.md +++ b/README_eu.md @@ -5,7 +5,7 @@ EZ editatu eskuz. # Dendrite YunoHost-erako -[![Integrazio maila](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![Funtzionamendu egoera](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Mantentze egoera](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![Integrazio maila](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![Funtzionamendu egoera](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Mantentze egoera](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![Instalatu Dendrite YunoHost-ekin](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/README_fr.md b/README_fr.md index 713b740..9bdbe09 100644 --- a/README_fr.md +++ b/README_fr.md @@ -5,7 +5,7 @@ Il NE doit PAS être modifié à la main. # Dendrite pour YunoHost -[![Niveau d’intégration](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![Niveau d’intégration](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![Installer Dendrite avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/README_gl.md b/README_gl.md index 368f495..c1743e3 100644 --- a/README_gl.md +++ b/README_gl.md @@ -5,7 +5,7 @@ NON debe editarse manualmente. # Dendrite para YunoHost -[![Nivel de integración](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![Estado de funcionamento](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Estado de mantemento](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![Nivel de integración](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![Estado de funcionamento](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![Estado de mantemento](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![Instalar Dendrite con YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/README_zh_Hans.md b/README_zh_Hans.md index 8af4201..06e1c31 100644 --- a/README_zh_Hans.md +++ b/README_zh_Hans.md @@ -5,7 +5,7 @@ # YunoHost 上的 Dendrite -[![集成程度](https://dash.yunohost.org/integration/dendrite.svg)](https://dash.yunohost.org/appci/app/dendrite) ![工作状态](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![维护状态](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) +[![集成程度](https://dash.yunohost.org/integration/dendrite.svg)](https://ci-apps.yunohost.org/ci/apps/dendrite/) ![工作状态](https://ci-apps.yunohost.org/ci/badges/dendrite.status.svg) ![维护状态](https://ci-apps.yunohost.org/ci/badges/dendrite.maintain.svg) [![使用 YunoHost 安装 Dendrite](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=dendrite) diff --git a/manifest.toml b/manifest.toml index 5295780..1108728 100644 --- a/manifest.toml +++ b/manifest.toml @@ -16,7 +16,8 @@ admindoc = "https://github.com/matrix-org/dendrite/tree/master/docs" code = "https://github.com/matrix-org/dendrite" [integration] -yunohost = ">= 11.2.12" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false diff --git a/scripts/_common.sh b/scripts/_common.sh index 6de87c6..b826b88 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,20 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= - -GO_VERSION="1.21" +go_version="1.21" psql_version=$PSQL_VERSION - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 2f4ae95..d841e67 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,50 +1,41 @@ #!/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 /usr/share/yunohost/helpers -#================================================= -# 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..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" 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_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # 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 9e36543..d420e73 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -26,44 +20,40 @@ else really_enable_open_registration="" fi -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --line_match="Dendrite is exiting now" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --wait_until="Dendrite is exiting now" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Updating systemd configuration..." --weight=1 +ynh_script_progression "Updating systemd configuration..." # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --line_match="Cleaning old notifications" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --wait_until="Cleaning old notifications" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -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 46a5252..c8aaf38 100644 --- a/scripts/config +++ b/scripts/config @@ -1,23 +1,18 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers # Stop script if errors -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors get_registration_disabled() { - registration_disabled=$(ynh_app_setting_get --app $app --key registration_disabled) + registration_disabled=$(ynh_app_setting_get --key registration_disabled) echo "${registration_disabled}" } -set__registration_disabled() { +set__registration_disabled() { + if [ "$registration_disabled" -eq "1" ] then really_enable_open_registration="" @@ -25,17 +20,16 @@ set__registration_disabled() { really_enable_open_registration="--really-enable-open-registration" fi - ynh_write_var_in_file --file=$install_dir/dendrite.yaml --key=registration_disabled --value="${registration_disabled}" - domain=$(ynh_app_setting_get --app $app --key domain) - port_tls=$(ynh_app_setting_get --app $app --key port_tls) - port=$(ynh_app_setting_get --app $app --key port) - psql_version=$(ynh_app_setting_get --app $app --key psql_version) - ynh_add_systemd_config - ynh_systemd_action --service_name=$app --action="restart" --line_match="Starting external listener" --log_path="systemd" - ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled + ynh_write_var_in_file --file=$install_dir/dendrite.yaml --key=registration_disabled --value="${registration_disabled}" + + domain=$(ynh_app_setting_get --key domain) + port_tls=$(ynh_app_setting_get --key port_tls) + port=$(ynh_app_setting_get --key port) + psql_version=$(ynh_app_setting_get --key psql_version) + ynh_config_add_systemd + ynh_systemctl --service=$app --action="restart" --wait_until="Starting external listener" --log_path="systemd" + ynh_app_setting_set --key=registration_disabled --value=$registration_disabled } #================================================= -# GENERIC FINALIZATION -#================================================= ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index 334179c..5b8a4bc 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -29,8 +23,8 @@ fi # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set --app=$app --key=server_name --value=$server_name -ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --key=server_name --value=$server_name +ynh_app_setting_set --key=domain --value=$domain #================================================= # ADD USER TO THE SSL-CERT GROUP @@ -41,33 +35,32 @@ usermod -a -G ssl-cert $app #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 +ynh_script_progression "Creating a PostgreSQL database..." -ynh_psql_execute_as_root --sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" +ynh_psql_db_shell <<< "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=2 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" -chmod -R o-rwx "$install_dir" -chown -R $app:root "$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 -R o-rwx "$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 -R $app:root "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 +ynh_script_progression "Configuring NGINX web server..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create .well-known redirection for access by federation if yunohost --output-as plain domain list | grep -q "^$server_name$" then - 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 #================================================= @@ -75,13 +68,13 @@ fi #================================================= # BUILDING SOURCES AND SETTING UP THE SERVER #================================================= -ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 +ynh_script_progression "Building the sources (it will take some time)..." -ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION +ynh_go_install pushd "$install_dir/build" # Build the sources - ynh_use_go + export GOPATH="$install_dir/build/go" export GOCACHE="$install_dir/build/.cache" CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/dendrite > /dev/null 2>&1 @@ -89,10 +82,10 @@ pushd "$install_dir/build" CGO_ENABLED=1 go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys > /dev/null 2>&1 popd -ynh_secure_remove --file="$install_dir/build" -ynh_remove_go +ynh_safe_rm "$install_dir/build" +ynh_go_remove -ynh_script_progression --message="Generating the keys..." --weight=1 +ynh_script_progression "Generating the keys..." pushd "$install_dir" # Generate a Matrix signing key for federation @@ -102,27 +95,26 @@ pushd "$install_dir" popd # Set permissions to app files -chown -R $app:root "$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 -R $app:root "$install_dir" #================================================= ## SET STANDARD SETTINGS FROM DEFAULT CONFIG #================================================= guests_disabled="true" registration_shared_secret="" enable_registration_captcha="false" -ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled -ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation -ynh_app_setting_set --app=$app --key=guests_disabled --value=$guests_disabled -ynh_app_setting_set --app=$app --key=registration_shared_secret --value=$registration_shared_secret -ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable_registration_captcha +ynh_app_setting_set --key=registration_disabled --value=$registration_disabled +ynh_app_setting_set --key=disable_federation --value=$disable_federation +ynh_app_setting_set --key=guests_disabled --value=$guests_disabled +ynh_app_setting_set --key=registration_shared_secret --value=$registration_shared_secret +ynh_app_setting_set --key=enable_registration_captcha --value=$enable_registration_captcha #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression "Adding $app's configuration..." # Copy and modify the config file -ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" +ynh_config_add --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" chmod 400 "$install_dir/dendrite.yaml" chown $app:$app "$install_dir/dendrite.yaml" @@ -130,44 +122,42 @@ chown $app:$app "$install_dir/dendrite.yaml" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 +ynh_script_progression "Configuring $app's systemd service..." # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +ynh_script_progression "Configuring log rotation..." mkdir -p /var/log/$app -chown -R $app:root /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root /var/log/$app # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate # HACKY: Match the weirdly renamed rotated logs. # Looking at you, matrix-org/dugong library -ynh_replace_string --match_string="/var/log/$app/*.log" --replace_string="/var/log/$app/*.log.????-??-??" --target_file="/etc/logrotate.d/$app" +ynh_replace --match="/var/log/$app/*.log" --replace="/var/log/$app/*.log.????-??-??" --file="/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --wait_until="Starting external listener" --log_path="systemd" #================================================= # 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 6bd0c4f..3526e2c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -16,29 +10,26 @@ source /usr/share/yunohost/helpers #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=1 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove the well-known location -ynh_secure_remove --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +ynh_safe_rm "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" # Remove the dedicated NGINX config -ynh_remove_nginx_config - -# Remove the log files -ynh_secure_remove --file="/var/log/$app" +ynh_config_remove_nginx #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index b5a544d..2cbcc23 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 /usr/share/yunohost/helpers @@ -19,52 +13,51 @@ usermod -a -G ssl-cert $app #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:root "$install_dir" +ynh_restore "$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 -R o-rwx "$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 -R $app:root "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=3 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_db_shell < "./db.sql"" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" if yunohost --output-as plain domain list | grep -q "^$server_name$" then - ynh_restore_file --origin_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" + ynh_restore "/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" fi -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" mkdir -p /var/log/$app -chown -R $app:root /var/log/$app -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root /var/log/$app +ynh_restore "/etc/logrotate.d/$app" #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --wait_until="Starting external listener" --log_path="systemd" -ynh_systemd_action --service_name=nginx --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 16269c7..de2e1c4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,27 +1,19 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --line_match="Dendrite is exiting now" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --wait_until="Dendrite is exiting now" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." if ! groups $app | grep -q 'ssl-cert'; then adduser $app ssl-cert @@ -31,47 +23,49 @@ fi # GET CONFIG PANEL SETTINGS #================================================= -server_name=$(ynh_app_setting_get --app=$app --key=server_name) -domain=$(ynh_app_setting_get --app=$app --key=domain) +server_name=$(ynh_app_setting_get --key=server_name) +domain=$(ynh_app_setting_get --key=domain) -registration_disabled=$(ynh_app_setting_get --app=$app --key=registration_disabled) -disable_federation=$(ynh_app_setting_get --app=$app --key=disable_federation) -guests_disabled=$(ynh_app_setting_get --app=$app --key=guests_disabled) -registration_shared_secret=$(ynh_app_setting_get --app=$app --key=registration_shared_secret) -enable_registration_captcha=$(ynh_app_setting_get --app=$app --key=enable_registration_captcha) +registration_disabled=$(ynh_app_setting_get --key=registration_disabled) +disable_federation=$(ynh_app_setting_get --key=disable_federation) +guests_disabled=$(ynh_app_setting_get --key=guests_disabled) +registration_shared_secret=$(ynh_app_setting_get --key=registration_shared_secret) +enable_registration_captcha=$(ynh_app_setting_get --key=enable_registration_captcha) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # MIGRATION : Manage old settings #================================================= # Define $server_name if not already defined +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=server_name --value=$domain if [ -z ${server_name:-} ]; then server_name=$domain - ynh_app_setting_set --app=$app --key=server_name --value=$domain + ynh_app_setting_set --key=server_name --value=$domain fi # Define $disable_federation if not already defined +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=enable_registration_captcha --value="false" if [ -z ${enable_registration_captcha:-} ]; then enable_registration_captcha="false" - ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable_registration_captcha + ynh_app_setting_set --key=enable_registration_captcha --value=$enable_registration_captcha fi # Define $guests_disabled if not already defined +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=guests_disabled --value="true" if [ -z ${guests_disabled:-} ]; then guests_disabled="true" - ynh_app_setting_set --app=$app --key=guests_disabled --value=$guests_disabled + ynh_app_setting_set --key=guests_disabled --value=$guests_disabled fi # Define $registration_shared_secret if not already defined +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=registration_shared_secret --value="" if [ -z ${registration_shared_secret:-} ]; then registration_shared_secret="" - ynh_app_setting_set --app=$app --key=registration_shared_secret --value=$registration_shared_secret + ynh_app_setting_set --key=registration_shared_secret --value=$registration_shared_secret fi # Load up registration variables -registration=$(ynh_app_setting_get --app=$app --key=registration) +registration=$(ynh_app_setting_get --key=registration) if [ -z ${registration:-} ]; then if [[ $registration_disabled = *"alse" ]] then @@ -80,67 +74,63 @@ if [ -z ${registration:-} ]; then really_enable_open_registration="" fi else - ynh_app_setting_delete --app=$app --key=registration + ynh_app_setting_delete --key=registration if [[ $registration == *"rue" || $registration -eq 1 ]] then registration_disabled="false" really_enable_open_registration="--really-enable-open-registration" disable_federation="true" - ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled - ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation + ynh_app_setting_set --key=registration_disabled --value=$registration_disabled + ynh_app_setting_set --key=disable_federation --value=$disable_federation else registration_disabled="true" really_enable_open_registration="" disable_federation="false" - ynh_app_setting_set --app=$app --key=registration_disabled --value=$registration_disabled - ynh_app_setting_set --app=$app --key=disable_federation --value=$disable_federation + ynh_app_setting_set --key=registration_disabled --value=$registration_disabled + ynh_app_setting_set --key=disable_federation --value=$disable_federation fi fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=3 +ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" --keep="dendrite.yaml" --full_replace -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:root "$install_dir" - -#================================================= -# SPECIFIC UPGRADE +#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 750 "$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 -R o-rwx "$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 -R $app:root "$install_dir" #================================================= # BUILDING SOURCES AND SETTING UP THE SERVER #================================================= -ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 +ynh_script_progression "Building the sources (it will take some time)..." -ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION +ynh_go_install pushd "$install_dir/build" # Build the sources - ynh_use_go + export PATH="$PATH" export GOPATH="$install_dir/build/go" export GOCACHE="$install_dir/build/.cache" export CGO_ENABLED=1 - ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/dendrite - ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/create-account - ynh_exec_warn_less go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys + ynh_hide_warnings go build -trimpath -v -o "$install_dir/bin/" ./cmd/dendrite + ynh_hide_warnings go build -trimpath -v -o "$install_dir/bin/" ./cmd/create-account + ynh_hide_warnings go build -trimpath -v -o "$install_dir/bin/" ./cmd/generate-keys popd -ynh_secure_remove --file="$install_dir/build" -ynh_remove_go - -chown -R $app:root "$install_dir" +ynh_safe_rm "$install_dir/build" +ynh_go_remove +#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 -R $app:root "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression "Updating configuration..." -ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" +ynh_config_add --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" chmod 400 "$install_dir/dendrite.yaml" chown $app:$app "$install_dir/dendrite.yaml" @@ -148,37 +138,37 @@ chown $app:$app "$install_dir/dendrite.yaml" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create .well-known redirection for access by federation if yunohost --output-as plain domain list | grep -q "^$server_name$" then - 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 systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" mkdir -p /var/log/$app -chown -R $app:root /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:root /var/log/$app # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" +ynh_systemctl --service=$app --action="start" --wait_until="Starting external listener" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"