From ec94539d2a1f2de3b1b486f886761a3fcfb4e1fc Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 5 Feb 2022 08:22:52 +0100 Subject: [PATCH] Apply example_ynh (#72) * Apply example_ynh --- README.md | 2 +- README_fr.md | 2 +- check_process | 1 - manifest.json | 2 +- scripts/backup | 3 ++- scripts/change_url | 10 +++++----- scripts/install | 11 +++++++---- scripts/remove | 26 +++++++++++++------------- scripts/restore | 5 +++-- scripts/upgrade | 33 +++++++++++++++++---------------- 10 files changed, 50 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index b50fe7b..5a7124d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ CodiMD is the free software version of HackMD, developed and opened source by th CodiMD is perfect for open communities, while HackMD emphasizes on permission and access controls for commercial use cases. -**Shipped version:** 2.4.1~ynh4 +**Shipped version:** 2.4.1~ynh5 diff --git a/README_fr.md b/README_fr.md index 52c5409..d807d75 100644 --- a/README_fr.md +++ b/README_fr.md @@ -15,7 +15,7 @@ CodiMD est la version logicielle libre de HackMD, développée et ouverte par l' CodiMD est parfait pour les communautés ouvertes, tandis que HackMD met l'accent sur les autorisations et les contrôles d'accès pour les cas d'utilisation commerciale. -**Version incluse :** 2.4.1~ynh4 +**Version incluse :** 2.4.1~ynh5 diff --git a/check_process b/check_process index 0110e79..bc6846b 100644 --- a/check_process +++ b/check_process @@ -23,4 +23,3 @@ Notification=none ; commit=0d58e34697338049d951c8373da3d363a121d439 name=Upgrade to version 2.4.1 manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - diff --git a/manifest.json b/manifest.json index b31ae65..53fddac 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Collaborative editor to work on notes written in Markdown", "fr": "Éditeur collaboratif pour travailler sur des notes en Markdown" }, - "version": "2.4.1~ynh4", + "version": "2.4.1~ynh5", "url": "https://github.com/hackmdio/codimd", "upstream": { "license": "AGPL-3.0-only", diff --git a/scripts/backup b/scripts/backup index 20b631a..77494ff 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # 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 @@ -66,4 +67,4 @@ ynh_psql_dump_db --database="$db_name" > db.sql # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for CodiMD. (YunoHost will then actually copy those files to the archive)." +ynh_print_info --message="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 e3caab9..fdedb7c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -34,9 +34,9 @@ db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up CodiMD before changing its URL (may take a while)..." --weight=1 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -44,7 +44,7 @@ ynh_clean_setup () { # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -76,7 +76,7 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -117,4 +117,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for CodiMD" --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 857684b..343d75d 100644 --- a/scripts/install +++ b/scripts/install @@ -123,9 +123,9 @@ pushd $final_path popd #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Modifying a config file..." +ynh_script_progression --message="Adding a configuration file..." path=${path_url:1} ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config.json" @@ -140,6 +140,7 @@ chmod +x $final_path/app.js #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=1 +# Create a dedicated systemd config ynh_add_systemd_config #================================================= @@ -162,9 +163,11 @@ ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_ #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -# Make app public if necessary or protect it +# Make app public if necessary if [ $is_public -eq 1 ] then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi @@ -179,4 +182,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of CodiMD completed" --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index fa4182c..52d4f14 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,9 +17,9 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE @@ -27,7 +27,7 @@ db_user=$db_name # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +# 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 then ynh_script_progression --message="Removing $app service..." --weight=1 @@ -50,19 +50,10 @@ ynh_script_progression --message="Removing the PostgreSQL database..." --weight= # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies -ynh_remove_nodejs - #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing CodiMD main directory..." --weight=6 +ynh_script_progression --message="Removing app main directory..." --weight=6 # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -75,6 +66,15 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=1 + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +ynh_remove_nodejs + #================================================= # GENERIC FINALIZATION #================================================= @@ -89,4 +89,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of CodiMD completed" --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 7051136..81ce72d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # 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 @@ -61,7 +62,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring CodiMD main directory..." --weight=60 +ynh_script_progression --message="Restoring the app main directory..." --weight=60 ynh_restore_file --origin_path="$final_path" @@ -126,4 +127,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for CodiMD" --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index beaa315..fc0480c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,30 +27,19 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up CodiMD before upgrading (may take a while)..." --weight=20 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=20 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -65,6 +54,18 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -143,7 +144,7 @@ fi #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=2 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=2 # Create a dedicated systemd config ynh_add_systemd_config @@ -173,4 +174,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of CodiMD completed" --last +ynh_script_progression --message="Upgrade of $app completed" --last