From 451a8d9233335eb3b58e4ee25fd9f7c1c9e87cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sun, 4 Feb 2024 20:58:21 +0100 Subject: [PATCH] Cleanup packagingv2 --- scripts/backup | 14 +++++--------- scripts/change_url | 2 +- scripts/install | 9 ++++----- scripts/remove | 9 ++------- scripts/restore | 14 ++++++++------ scripts/upgrade | 29 +++++++++-------------------- 6 files changed, 29 insertions(+), 48 deletions(-) diff --git a/scripts/backup b/scripts/backup index 737146f..e009d5a 100755 --- a/scripts/backup +++ b/scripts/backup @@ -22,24 +22,20 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE 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" +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= -# BACKUP SYSTEMD +# BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="/var/log/$app/" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index d4704ec..9ea02e0 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -39,7 +39,7 @@ ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 0c5954e..c6854e8 100755 --- a/scripts/install +++ b/scripts/install @@ -18,7 +18,7 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # SPECIFIC SETUP @@ -53,7 +53,7 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" chmod 400 "$install_dir/config.yaml" -chown $app:$app "$install_dir/config.yaml" +chown "$app:$app" "$install_dir/config.yaml" #================================================= # SETUP SYSTEMD @@ -64,19 +64,18 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_add_nginx_config ynh_add_systemd_config +yunohost service add "$app" --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" # Use logrotate to manage application logfile(s) ynh_use_logrotate -yunohost service add $app --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index d3596d1..f9eda87 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,10 +16,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi # Remove the dedicated systemd config @@ -31,9 +29,6 @@ ynh_remove_logrotate # Remove the dedicated NGINX config ynh_remove_nginx_config -# Remove a directory securely -ynh_secure_remove --file="/etc/$app" - # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index 6f37885..7564ded 100755 --- a/scripts/restore +++ b/scripts/restore @@ -28,21 +28,23 @@ ynh_script_progression --message="Restoring system configurations related to $ap ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -mkdir -p /var/log/$app -chown -R $app:root /var/log/$app +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" ynh_restore_file --origin_path="/etc/logrotate.d/$app" -yunohost service add $app --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" +#================================================= +# RESTORE VARIOUS FILES +#================================================= + +ynh_restore_file --origin_path="/var/log/$app/" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 210f5db..5064a1e 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 #================================================= @@ -23,27 +17,23 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --keep="config.yaml" -fi +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="config.yaml" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" #================================================= # SPECIFIC UPGRADE @@ -78,7 +68,7 @@ ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" chmod 400 "$install_dir/config.yaml" -chown $app:$app "$install_dir/config.yaml" +chown "$app:$app" "$install_dir/config.yaml" #================================================= # SETUP SYSTEMD @@ -90,18 +80,17 @@ ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config +yunohost service add "$app" --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -yunohost service add $app --description="OpenID Connect Provider" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT