From 5d047d83b66a220ea641210f88e9ab5dbda68b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 17 May 2024 12:06:48 +0200 Subject: [PATCH] cleanup --- scripts/backup | 16 +------ scripts/install | 2 +- scripts/remove | 21 --------- scripts/restore | 41 +++-------------- scripts/upgrade | 116 ++++++++++++++++++------------------------------ 5 files changed, 51 insertions(+), 145 deletions(-) diff --git a/scripts/backup b/scripts/backup index 4cd0f6d..2f4ae95 100644 --- a/scripts/backup +++ b/scripts/backup @@ -22,29 +22,15 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - ynh_backup --src_path="/etc/logrotate.d/$app" -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP VARIOUS FILES -#================================================= - 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" diff --git a/scripts/install b/scripts/install index d921150..c4554bd 100644 --- a/scripts/install +++ b/scripts/install @@ -123,7 +123,7 @@ ynh_app_setting_set --app=$app --key=enable_registration_captcha --value=$enable ynh_script_progression --message="Adding a configuration file..." # Copy and modify the config file -ynh_add_config --template="../conf/dendrite.yaml" --destination="$install_dir/dendrite.yaml" +ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" chmod 400 "$install_dir/dendrite.yaml" chown $app:$app "$install_dir/dendrite.yaml" diff --git a/scripts/remove b/scripts/remove index 2850c89..6bd0c4f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -22,39 +22,18 @@ then yunohost service remove $app fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - # Remove the well-known location ynh_secure_remove --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= - # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index 6e481b5..b5a544d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -26,13 +26,6 @@ ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:root "$install_dir" -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= @@ -41,53 +34,33 @@ ynh_script_progression --message="Restoring the PostgreSQL database..." --weight ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= -# RESTORE VARIOUS FILES +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring various files..." --weight=1 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/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" fi -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 - ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 +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" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -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 --message="Reloading NGINX web server and $app's service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external listener" --log_path="systemd" -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 5b5ca55..d46ea00 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,12 +10,6 @@ source _common.sh source ynh_install_go source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -53,7 +47,6 @@ enable_registration_captcha=$(ynh_app_setting_get --app=$app --key=enable_regist # MIGRATION : Manage old settings #================================================= - # Define $server_name if not already defined if [ -z ${server_name:-} ]; then server_name=$domain @@ -108,23 +101,55 @@ fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=3 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=3 - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir/build" --keep="dendrite.yaml" --full_replace -fi +# 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" #================================================= -# NGINX CONFIGURATION +# SPECIFIC UPGRADE #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 +# BUILDING SOURCES AND SETTING UP THE SERVER +#================================================= +ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 + +ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION + +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 +popd + +ynh_secure_remove --file="$install_dir/build" +ynh_remove_go + +chown -R $app:root "$install_dir" + +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +ynh_add_config --template="dendrite.yaml" --destination="$install_dir/dendrite.yaml" + +chmod 400 "$install_dir/dendrite.yaml" +chown $app:$app "$install_dir/dendrite.yaml" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config @@ -135,60 +160,10 @@ then ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" fi -#================================================= -# SPECIFIC UPGRADE -#================================================= -# BUILDING SOURCES AND SETTING UP THE SERVER -#================================================= - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 - - ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION - - 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 - popd - - ynh_secure_remove --file="$install_dir/build" - ynh_remove_go -fi - -chown -R $app:root "$install_dir" - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -ynh_add_config --template="../conf/dendrite.yaml" --destination="$install_dir/dendrite.yaml" - -chmod 400 "$install_dir/dendrite.yaml" -chown $app:$app "$install_dir/dendrite.yaml" - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 - # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +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 @@ -196,13 +171,6 @@ chown -R $app:root /var/log/$app # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_tls" - #================================================= # START SYSTEMD SERVICE #=================================================