From 8d9a419a27005d2d09048d994ee195bedafc4611 Mon Sep 17 00:00:00 2001 From: anmol Date: Sun, 14 Apr 2019 20:42:38 +0530 Subject: [PATCH 01/18] Fix source zip url --- scripts/install | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index f27be8f..20f5853 100644 --- a/scripts/install +++ b/scripts/install @@ -100,7 +100,7 @@ ynh_mysql_setup_db $db_name $db_name ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src tmpdir="$(mktemp -d)" -sudo wget -O "$tmpdir/ghost.zip" "https://ghost.org/zip/ghost-latest.zip" +sudo wget -O "$tmpdir/ghost.zip" "https://github.com/TryGhost/Ghost/archive/master.zip" unzip "$tmpdir/ghost.zip" -d "$final_path" sudo rm -R "$tmpdir/ghost.zip" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 153d8a3..b8b1cd6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -82,7 +82,7 @@ if [ -z $final_path ]; then ynh_app_setting_set $app final_path $final_path fi tmpdir1="$(mktemp -d)" -sudo wget -O "$tmpdir1/ghost.zip" "https://ghost.org/zip/ghost-latest.zip" +sudo wget -O "$tmpdir1/ghost.zip" "https://github.com/TryGhost/Ghost/archive/master.zip" unzip "$tmpdir1/ghost.zip" -d "$final_path" sudo rm -R "$tmpdir1/ghost.zip" From 7b2b8bb540201834655f45b39aa9de4d361c38fa Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Jun 2020 04:04:12 +0200 Subject: [PATCH 02/18] Update to 3.19.2 --- README.md | 54 +++++-- conf/app.src | 6 +- conf/config.production.json | 6 +- conf/message | 9 ++ conf/systemd.service | 5 +- issue_template.md | 46 ++++++ manifest.json | 10 +- pull_request_template.md | 18 +++ scripts/_common.sh | 30 ++-- scripts/backup | 44 ++++-- scripts/install | 183 +++++++++++---------- scripts/remove | 55 ++++--- scripts/restore | 93 +++++++---- scripts/upgrade | 236 +++++++++++++++++----------- scripts/ynh_add_config | 127 +++++++++++++++ scripts/ynh_send_readme_to_admin__2 | 140 +++++++++++++++++ 16 files changed, 767 insertions(+), 295 deletions(-) create mode 100644 conf/message create mode 100644 issue_template.md create mode 100644 pull_request_template.md create mode 100644 scripts/ynh_add_config create mode 100644 scripts/ynh_send_readme_to_admin__2 diff --git a/README.md b/README.md index bba781b..7dbab93 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # Ghost blogging app for YunoHost -[![Integration level](https://dash.yunohost.org/integration/ghost.svg)](https://ci-apps.yunohost.org/jenkins/job/ghost%20%28Community%29/lastBuild/consoleFull) -[![Install Ghost with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=ghost)

-======= +[![Integration level](https://dash.yunohost.org/integration/ghost.svg)](https://dash.yunohost.org/appci/app/ghost) ![](https://ci-apps.yunohost.org/ci/badges/ghost.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/ghost.maintain.svg) +[![Install Ghost with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=ghost) -Shipped version: **2.1.1**

+> *This package allows you to install Ghost quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* -- [Yunohost project](https://yunohost.org) -- [Ghost](https://ghost.org/) -- [Ghost source code at Github](https://github.com/TryGhost/Ghost) -- [Ghost forum](https://forum.ghost.org/) - -## What is Ghost ? +## Overview Ghost is a fully open source, adaptable platform for building and running a modern online publication. +**Shipped version:** 3.19.2 + +## Screenshots + +![](https://ghost.org/static/ghost-admin-home-header-0c20f780aac8e98af7a56076ae8228b8.png) ## Installation @@ -33,7 +33,7 @@ Ghost is a fully open source, adaptable platform for building and running a mode 1. **App can be installed by YunoHost admin interface or by the following command:** $ sudo yunohost app install https://github.com/YunoHost-Apps/ghost_ynh - 1. After installation create an **admin account** by visiting https://domain.tld/admin + 1. After installation create an **admin account** by visiting https://domain.tld/ghost ### Updating the Ghost app 1. Updatation of the app works, but it need more testing to check eveything works after upgrade. So its advised to backup before updating. @@ -41,10 +41,34 @@ Ghost is a fully open source, adaptable platform for building and running a mode $ sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/ghost_ynh ghost +## Documentation -### Dependencies + * Official documentation: https://ghost.org/docs/ - * NodeJS - * MySql - * Yarn +## YunoHost specific features +#### Supported architectures + +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/ghost%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/ghost/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/ghost%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/ghost/) + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/ghost_ynh/issues + * App website: https://ghost.org/ + * Upstream app repository: https://github.com/TryGhost/Ghost + * YunoHost website: https://yunohost.org/ + +--- + +Developer info +---------------- + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/ghost_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/ghost_ynh/tree/testing --debug +or +sudo yunohost app upgrade ghost -u https://github.com/YunoHost-Apps/ghost_ynh/tree/testing --debug +``` diff --git a/conf/app.src b/conf/app.src index fd3ce40..4b8f54c 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,6 +1,6 @@ -SOURCE_URL=https://github.com/TryGhost/Ghost/releases/download/2.1.1/Ghost-2.1.1.zip -SOURCE_SUM=d1b2d61aea05d92b6bfcfe1bdfa547e314aa0915e5518984bed4737e87031fa6 +SOURCE_URL=https://github.com/TryGhost/Ghost/releases/download/3.19.2/Ghost-3.19.2.zip +SOURCE_SUM=b60875ff763305f3cc9db21610a82c14f03e08bf35838d089b9313c0eca1ee59 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip -SOURCE_IN_SUBDIR=true +SOURCE_IN_SUBDIR=false SOURCE_FILENAME= diff --git a/conf/config.production.json b/conf/config.production.json index b1d8452..57ed83c 100644 --- a/conf/config.production.json +++ b/conf/config.production.json @@ -8,9 +8,9 @@ "client": "mysql", "connection": { "host" : "127.0.0.1", - "user" : "__DBNAME__", - "password" : "__DBPWD__", - "database" : "__DBNAME__" + "user" : "__DB_USER__", + "password" : "__DB_PWD__", + "database" : "__DB_NAME__" } }, "auth": { diff --git a/conf/message b/conf/message new file mode 100644 index 0000000..d438dff --- /dev/null +++ b/conf/message @@ -0,0 +1,9 @@ +Ghost was successfully installed :) + +Next step: + +Create admin account at https://__DOMAIN____PATH_URL__/ghost + +Happy Blogging! + +If you are facing any problem, please open an issue here: https://github.com/YunoHost-Apps/ghost_ynh/issues \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index 5f61256..c63e73f 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -4,11 +4,12 @@ Documentation=https://docs.ghost.org [Service] Type=simple -WorkingDirectory=__FINALPATH__ User=__APP__ Group=__APP__ +WorkingDirectory=__FINALPATH__ +Environment="YNH_NODE_LOAD_PATH" Environment="NODE_ENV=production" -ExecStart=/usr/bin/node index.js run +ExecStart=__YNH_NODE__ index.js run Restart=always [Install] diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 0000000..20f770f --- /dev/null +++ b/issue_template.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* + - *Otherwise, the issue may be due to Ghost itself. Refer to its documentation or repository for help.* + - *If you have a doubt, post here, we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +**Describe the bug** +*A clear and concise description of what the bug is.* + +**Versions** +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +**To Reproduce** +*Steps to reproduce the behavior.* +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install ghost + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '....'* + 3. *Scroll down to '....'* + 4. *See error* + +**Expected behavior** +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +**Logs** +*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 5d48c63..842e436 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Just a blogging platform", "fr": "Plateforme de blogging" }, - "version": "2.1.1", + "version": "3.19.2~ynh1", "url": "https://ghost.org/", "license": "free", "developer": { @@ -14,7 +14,7 @@ "email": "julien.malik@paraiso.me" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.5" }, "multi_instance": true, "services": [ @@ -26,6 +26,7 @@ "install" : [ { "name": "domain", + "type": "domain", "ask": { "en": "Choose a domain for Ghost", "fr": "Choisissez un domaine pour Ghost" @@ -34,9 +35,10 @@ }, { "name": "path", + "type": "path", "ask": { "en": "Choose a path for Ghost", - "fr": "Choisissez un path pour Ghost" + "fr": "Choisissez un chemin pour Ghost" }, "example": "/blog", "default": "/blog" @@ -53,5 +55,3 @@ ] } } - - diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..0c45f32 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,18 @@ +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/ghost_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/ghost_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5ca9fb0..5346274 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,25 @@ #!/bin/bash -# ============= FUTURE YUNOHOST HELPER ============= -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} +#================================================= +# COMMON VARIABLES +#================================================= +# dependencies used by the app +pkg_dependencies="mailutils" + +NODEJS_VERSION=10 + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= ynh_send_readme_to_admin() { local app_message="${1:-...No specific information...}" diff --git a/scripts/backup b/scripts/backup index b245aba..63ac358 100755 --- 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 @@ -13,46 +14,57 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" - - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= - -ynh_mysql_dump_db "$db_name" > db.sql +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP -#================================================= - #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup "/etc/systemd/system/$app.service" +ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= +ynh_print_info --message="Backing up the MySQL database..." + +ynh_mysql_dump_db --database="$db_name" > db.sql + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 20f5853..9229336 100644 --- a/scripts/install +++ b/scripts/install @@ -7,105 +7,98 @@ #================================================= source _common.sh +source ynh_add_config +source ynh_send_readme_to_admin__2 source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= + domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Configuring firewall..." -# Find a free port -port=$(ynh_find_port 4010) -ynh_app_setting_set $app port $port +# Find an available port +port=$(ynh_find_port --port=4010) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." -# install nodejs -ynh_install_nodejs 8 +ynh_install_app_dependencies $pkg_dependencies -# add yarn repo for Debian -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -ynh_package_update - -ynh_install_app_dependencies mailutils yarn +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # CREATE A MYSQL DATABASE #================================================= -# If your app uses a MySQL database, you can use these lines to bootstrap -# a database, an associated user and save the password in app settings +ynh_script_progression --message="Creating a MySQL database..." -db_name=$(ynh_sanitize_dbid $app) -ynh_app_setting_set $app db_name $db_name -ynh_mysql_setup_db $db_name $db_name +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -tmpdir="$(mktemp -d)" -sudo wget -O "$tmpdir/ghost.zip" "https://github.com/TryGhost/Ghost/archive/master.zip" -unzip "$tmpdir/ghost.zip" -d "$final_path" -sudo rm -R "$tmpdir/ghost.zip" +ynh_setup_source --dest_dir="$final_path" + #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config @@ -118,68 +111,74 @@ ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Configuring system user..." # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # SPECIFIC SETUP -#================================================= - -# Copy configuration file -cp ../conf/config.production.json "$final_path/config.production.json" - -# Install the dependencies with yarn -( - cd "$final_path" - yarn install - yarn global add knex-migrator - - -) - #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_script_progression --message="Modifying a config file..." -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.production.json" -ynh_replace_string "__PATH__" "$path_url" "$final_path/config.production.json" -ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.production.json" -ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.production.json" -ynh_replace_string "__PORT__" "$port" "$final_path/config.production.json" +ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd" -# Create tables in database -( - cd "$final_path" -NODE_ENV=production knex-migrator init +#============================================== +# BUILD GHOST +#============================================== +ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=240 -) +pushd "$final_path" || ynh_die -#================================================= -# STORE THE CHECKSUM OF THE CONFIG FILE -#================================================= + ynh_use_nodejs + yarn install + yarn global add knex-migrator + NODE_ENV=production knex-migrator init + yarn global add grunt + NODE_ENV=production grunt symlink + NODE_ENV=production grunt init --force -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/config.production.json" - -#================================================= -# SET WRITE PERMISSION -#================================================= - -# Set right permissions for curl install -chown -R $app: $final_path +popd || ynh_die #================================================= # SETUP SYSTEMD #================================================= +ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config -ynh_add_systemd_config -systemctl start "$app" +ynh_add_systemd_config --others_var="ynh_node_load_PATH ynh_node" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_script_progression --message="Securing files and directories..." + +# Set permissions to app files +chown -R $app: $final_path + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "$app daemon for Ghost" --log_type "systemd" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." if [ $is_public -eq 0 ] then # Remove the public access @@ -188,30 +187,28 @@ fi # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=skipped_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # SEND A README FOR THE ADMIN #================================================= +ynh_print_info --message="Sending a readme for the admin..." -message=" $app was successfully installed :) +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" -Next step: - -Create admin account at https://$domain{$path_url}admin - -Happy Blogging! - -If you are facing any problem, please open an issue here: https://github.com/YunoHost-Apps/ghost_ynh/issues" - -ynh_send_readme_to_admin "$message" +ynh_send_readme_to_admin --app_message="../conf/message" +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 21a5b29..7a4734d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,58 +12,67 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name -final_path=$(ynh_app_setting_get $app final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= + +# 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..." + yunohost service remove $app +fi + #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE THE MYSQL DATABASE #================================================= +ynh_script_progression --message="Removing the MySQL database..." -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -74,8 +83,8 @@ ynh_remove_nginx_config if yunohost firewall list | grep -q "\- $port$" then - echo "Close port $port" - yunohost firewall disallow TCP $port 2>&1 + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= @@ -83,7 +92,13 @@ fi #================================================= # REMOVE DEDICATED USER #================================================= +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 9943548..1f913ff 100755 --- 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 @@ -13,63 +14,64 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) -port=$(ynh_app_setting_get "$app" port) - +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +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 +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file "$final_path" - -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= - -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS #================================================= +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R $app: $final_path @@ -79,30 +81,59 @@ chown -R $app: $final_path #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=7 -# install nodejs -ynh_install_nodejs 8 +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies -# add yarn repo for Debian -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -ynh_package_update +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies mailutils yarn +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE SYSTEMD #================================================= +ynh_script_progression --message="Restoring the systemd configuration..." -ynh_restore_file "/etc/systemd/system/$app.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service -systemctl start "$app" + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "$app daemon for Ghost" --log_type "systemd" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT #================================================= -systemctl reload nginx +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index b8b1cd6..4ad2741 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,84 +12,47 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + +#================================================= +# 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..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # If db_name doesn't exist, create it -if [ -z $db_name ]; then - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) - -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -# Create a temporary directory -tmpdir="$(mktemp -d)" -# Backup the content folder to the temp dir -cp -ar "$final_path/content" "$tmpdir" - - -# Download, uncompress and patch the source -sudo rm -R "$final_path" -# If final_path doesn't exist, create it -if [ -z $final_path ]; then - final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path -fi -tmpdir1="$(mktemp -d)" -sudo wget -O "$tmpdir1/ghost.zip" "https://github.com/TryGhost/Ghost/archive/master.zip" -unzip "$tmpdir1/ghost.zip" -d "$final_path" -sudo rm -R "$tmpdir1/ghost.zip" - -# copy content folder back to the final_path -sudo cp -ar "$tmpdir/content" "${final_path}" -sudo rm -R "$tmpdir" - #================================================= # CLOSE A PORT #================================================= @@ -101,42 +64,70 @@ then fi #================================================= -# SPECIFIC SETUP +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." -# Copy configuration file -cp ../conf/config.production.json "$final_path/config.production.json" - -# Install the dependencies with yarn -( - cd "$final_path" - yarn install - yarn global add knex-migrator - - -) +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_clean_check_starting + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= -# MODIFY A CONFIG FILE +# CHECK THE PATH #================================================= -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config.production.json" -ynh_replace_string "__PATH__" "$path_url" "$final_path/config.production.json" -ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.production.json" -ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.production.json" -ynh_replace_string "__PORT__" "$port" "$final_path/config.production.json" +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path --path_url=$path_url) -# Migrate tables in database -( - cd "$final_path" -NODE_ENV=production knex-migrator init +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." -) +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=160 + + # Create a temporary directory + tmpdir="$(mktemp -d)" + + # Backup the content folder to the temp dir + cp -ar "$final_path/content" "$tmpdir" + + # Remove the app directory securely + ynh_secure_remove --file=$final_path + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir=$final_path + + #Copy the admin saved settings from tmp directory to final path + cp -a "$tmpdir/config.production.json" "$final_path/config.production.json" + + # copy content folder back to the final_path + cp -ar "$tmpdir/content" "${final_path}" + + # Remove the tmp directory securely + ynh_secure_remove --file="$tmpdir" +fi #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -146,42 +137,76 @@ then fi ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +ynh_install_app_dependencies $pkg_dependencies + +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION + +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." -# Create a system user -ynh_system_user_create $app +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # SPECIFIC UPGRADE #================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." -# Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "$final_path/config.production.json" -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/config.production.json" +ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd" + +#============================================== +# BUILD GHOST +#============================================== +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=160 + + pushd "$final_path" || ynh_die + yarn install + yarn global add knex-migrator + NODE_ENV=production knex-migrator init + yarn global add grunt + NODE_ENV=production grunt symlink + NODE_ENV=production grunt init --force + + popd || ynh_die +fi #================================================= # SETUP SYSTEMD #================================================= +ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_add_systemd_config -systemctl start "$app" +ynh_add_systemd_config --others_var="ynh_node_load_PATH ynh_node" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." -# Set right permissions for curl installation +# Set permissions on app files chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." if [ $is_public -eq 0 ] then # Remove the public access @@ -190,13 +215,32 @@ fi # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set --app=$app --key=skipped_uris --value="/" fi +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "$app daemon for Ghost" --log_type "systemd" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service" + #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx -service "$app" restart +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config new file mode 100644 index 0000000..0e9a440 --- /dev/null +++ b/scripts/ynh_add_config @@ -0,0 +1,127 @@ +#!/bin/bash + +# Create a dedicated config file +# +# usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"] +# | arg: -o, --origin= - Template config file to use (optionnal, ../conf/.env by default) +# | arg: -d, --destination= - Destination of the config file (optionnal, $final_path/.env) +# | arg: -v, --vars= - List of variables to replace separated by a space. For example: 'var_1 var_2 ...' +# +# This will use the template $origin or ../conf/.env by default +# to generate a config file $destination or $final_path/.env by default, +# by replacing the following keywords with global variables +# that should be defined before calling this helper : +# __PATH__ by $path_url +# __DOMAIN__ by $domain +# __PORT__ by $port +# __NAME__ by $app +# __NAMETOCHANGE__ by $app +# __USER__ by $app +# __APP__ by $app +# __FINALPATH__ by $final_path +# __PHPVERSION__ by $YNH_PHP_VERSION +# __YNH_NPM__ by $ynh_npm +# __YNH_NODE__ by $ynh_node +# __YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH +# __NODEJS_PATH__ by $nodejs_path +# __NODEJS_VERSION__ by $nodejs_version +# +# And dynamic variables (from the last example) : +# __VAR_1__ by $var_1 +# __VAR_2__ by $var_2 +# +# +ynh_add_config () { + # Declare an array to define the options of this helper. + local legacy_args=odv + local -A args_array=( [o]=origin= [d]=destination= [v]=vars= ) + local origin + local destination + local vars + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local origin="${origin:-"../conf/.env"}" + local destination="${destination:-"$final_path/.env"}" + local vars="${vars:-}" + + ynh_backup_if_checksum_is_different --file="$destination" + cp "$origin" "$destination" + + #Replace usual YunoHost variables + if test -n "${path_url:-}" + then + # path_url_slash_less is path_url, or a blank value if path_url is only '/' + local path_url_slash_less=${path_url%/} + ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$destination" + ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$destination" + fi + if test -n "${domain:-}"; then + ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$destination" + fi + if test -n "${port:-}"; then + ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$destination" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$destination" + ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$destination" + fi + if test -n "${final_path:-}"; then + ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$destination" + fi + if test -n "${YNH_PHP_VERSION:-}"; then + ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$destination" + fi + if test -n "${ynh_npm:-}"; then + ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$destination" + fi + if test -n "${ynh_node:-}"; then + ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$destination" + fi + if test -n "${ynh_node_load_PATH:-}"; then + ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$destination" + fi + if test -n "${nodejs_path:-}"; then + ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$destination" + fi + if test -n "${nodejs_version:-}"; then + ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$destination" + fi + + # Replace all other variables given as arguments + for var_to_replace in $vars + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$destination" + done + + ynh_store_file_checksum --file="$destination" +} + +# Remove the dedicated config +# +# usage: ynh_remove_config [--file=file] +# | arg: -f, --file= - Config file to remove (optionnal, $final_path/.env) +# +# +ynh_remove_config () { + # Declare an array to define the options of this helper. + local legacy_args=f + local -A args_array=( [f]=file= ) + local file + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local service="${file:-}" + + # The default behaviour is to use .env file. + if [ -n "$file" ]; then + file="final_path/.env" + fi + + if [ -e "$file" ] + then + ynh_secure_remove --file="$file" + fi +} diff --git a/scripts/ynh_send_readme_to_admin__2 b/scripts/ynh_send_readme_to_admin__2 new file mode 100644 index 0000000..06cff8c --- /dev/null +++ b/scripts/ynh_send_readme_to_admin__2 @@ -0,0 +1,140 @@ +#!/bin/bash + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] +# | arg: -m --app_message= - The file with the content to send to the administrator. +# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade' +ynh_send_readme_to_admin() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= ) + local app_message + local recipients + local type + # Manage arguments with getopts + + ynh_handle_getopts_args "$@" + app_message="${app_message:-}" + recipients="${recipients:-root}" + type="${type:-install}" + + # Get the value of admin_mail_html + admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) + admin_mail_html="${admin_mail_html:-0}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + # Subject base + local mail_subject="☁️🆈🅽🅷☁️: \`$app\`" + + # Adapt the subject according to the type of mail required. + if [ "$type" = "backup" ]; then + mail_subject="$mail_subject has just been backup." + elif [ "$type" = "change_url" ]; then + mail_subject="$mail_subject has just been moved to a new URL!" + elif [ "$type" = "remove" ]; then + mail_subject="$mail_subject has just been removed!" + elif [ "$type" = "restore" ]; then + mail_subject="$mail_subject has just been restored!" + elif [ "$type" = "upgrade" ]; then + mail_subject="$mail_subject has just been upgraded!" + else # install + mail_subject="$mail_subject has just been installed!" + fi + + local mail_message="This is an automated message from your beloved YunoHost server. + +Specific information for the application $app. + +$(if [ -n "$app_message" ] +then + cat "$app_message" +else + echo "...No specific information..." +fi) + +--- +Automatic diagnosis data from YunoHost + +__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__" + + # Store the message into a file for further modifications. + echo "$mail_message" > mail_to_send + + # If a html email is required. Apply html tags to the message. + if [ "$admin_mail_html" -eq 1 ] + then + # Insert 'br' tags at each ending of lines. + ynh_replace_string "$" "
" mail_to_send + + # Insert starting HTML tags + sed --in-place '1s@^@\n\n\n\n@' mail_to_send + + # Keep tabulations + ynh_replace_string " " "\ \ " mail_to_send + ynh_replace_string "\t" "\ \ " mail_to_send + + # Insert url links tags + ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "\1" mail_to_send + + # Insert pre tags + ynh_replace_string "__PRE_TAG1__" "
" mail_to_send
+		ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
+
+		# Insert finishing HTML tags
+		echo -e "\n\n" >> mail_to_send
+
+	# Otherwise, remove tags to keep a plain text.
+	else
+		# Remove URL tags
+		ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
+		ynh_replace_string "__URL_TAG2__" ": " mail_to_send
+
+		# Remove PRE tags
+		ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
+	fi
+
+	# Define binary to use for mail command
+	if [ -e /usr/bin/bsd-mailx ]
+	then
+		local mail_bin=/usr/bin/bsd-mailx
+	else
+		local mail_bin=/usr/bin/mail.mailutils
+	fi
+
+	if [ "$admin_mail_html" -eq 1 ]
+	then
+		content_type="text/html"
+	else
+		content_type="text/plain"
+	fi
+
+	# Send the email to the recipients
+	cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
+}

From 3598757fa4678cfb1367bc8f727265ec29187a74 Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:16:33 +0200
Subject: [PATCH 03/18] [YEP-2.1] "maintainer" field is missing

---
 manifest.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index 842e436..33715cd 100644
--- a/manifest.json
+++ b/manifest.json
@@ -9,7 +9,7 @@
     "version": "3.19.2~ynh1",
     "url": "https://ghost.org/",
     "license": "free",
-    "developer": {
+    "maintainer": {
         "name": "Julien Malik",
         "email": "julien.malik@paraiso.me"
     },

From c50fb847443ec0fc1705db814dbb4c119142b6bd Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:16:53 +0200
Subject: [PATCH 04/18] replace by ynh_send_readme_to_admin__2

---
 scripts/_common.sh | 49 ----------------------------------------------
 1 file changed, 49 deletions(-)

diff --git a/scripts/_common.sh b/scripts/_common.sh
index 5346274..0cfd71a 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -20,52 +20,3 @@ NODEJS_VERSION=10
 #=================================================
 # FUTURE OFFICIAL HELPERS
 #=================================================
-
-ynh_send_readme_to_admin() {
-	local app_message="${1:-...No specific information...}"
-	local recipients="${2:-root}"
-
-	# Retrieve the email of users
-	find_mails () {
-		local list_mails="$1"
-		local mail
-		local recipients=" "
-		# Read each mail in argument
-		for mail in $list_mails
-		do
-			# Keep root or a real email address as it is
-			if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
-			then
-				recipients="$recipients $mail"
-			else
-				# But replace an user name without a domain after by its email
-				if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
-				then
-					recipients="$recipients $mail"
-				fi
-			fi
-		done
-		echo "$recipients"
-	}
-	recipients=$(find_mails "$recipients")
-
-	local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
-
-	local mail_message="This is an automated message from your beloved YunoHost server.
-Specific information for the application $app.
-$app_message
----
-Automatic diagnosis data from YunoHost
-$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
-	
-	# Define binary to use for mail command
-	if [ -e /usr/bin/bsd-mailx ]
-	then
-		local mail_bin=/usr/bin/bsd-mailx
-	else
-		local mail_bin=/usr/bin/mail.mailutils
-	fi
-
-	# Send the email to the recipients
-	echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
-}

From 599cad55a502c5f0f1e06c38b65b8dda8a40393d Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:21:55 +0200
Subject: [PATCH 05/18] [YEP-2.1?] nodjs service not installed by the install
 file but present in the manifest

---
 manifest.json | 1 -
 1 file changed, 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index 33715cd..02613fb 100644
--- a/manifest.json
+++ b/manifest.json
@@ -19,7 +19,6 @@
     "multi_instance": true,
     "services": [
         "nginx",
-        "nodjs",
         "mysql"
     ],
     "arguments": {

From 2bcc86be90219f2f57574adeb97580982cd0634f Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:22:53 +0200
Subject: [PATCH 06/18] Providing a LICENSE is mandatory

---
 LICENSE | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 LICENSE

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f3cff84
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,4 @@
+File containing the license of your package.
+
+More information here:
+https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines_fr.md#yep-13---indiquer-la-licence-associ%C3%A9e-au-paquet---brouillon--auto--working-

From 084d3a5ca5ae104f2058da1642d2508a514b3b4a Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:23:24 +0200
Subject: [PATCH 07/18] Update manifest.json

---
 manifest.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index 02613fb..7dc0b54 100644
--- a/manifest.json
+++ b/manifest.json
@@ -14,7 +14,7 @@
         "email": "julien.malik@paraiso.me"
     },
    "requirements": {
-        "yunohost": ">= 3.5"
+        "yunohost": ">= 3.8.1"
     },
     "multi_instance": true,
     "services": [

From 24618fc4912f6951e2a86de86e20e44aa0857202 Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sun, 14 Jun 2020 17:36:38 +0200
Subject: [PATCH 08/18] Switching start line_match

---
 scripts/install | 2 +-
 scripts/restore | 2 +-
 scripts/upgrade | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/install b/scripts/install
index 9229336..6cec36b 100644
--- a/scripts/install
+++ b/scripts/install
@@ -173,7 +173,7 @@ yunohost service add $app --description "$app daemon for Ghost" --log_type "syst
 ynh_script_progression --message="Starting a systemd service..."
 
 # Start a systemd service
-ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service"
+ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
 
 #=================================================
 # SETUP SSOWAT
diff --git a/scripts/restore b/scripts/restore
index 1f913ff..b631be9 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -121,7 +121,7 @@ yunohost service add $app --description "$app daemon for Ghost" --log_type "syst
 #=================================================
 ynh_script_progression --message="Starting a systemd service..."
 
-ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service"
+ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
 
 #=================================================
 # GENERIC FINALIZATION
diff --git a/scripts/upgrade b/scripts/upgrade
index 4ad2741..26f6bc5 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -230,7 +230,7 @@ yunohost service add $app --description "$app daemon for Ghost" --log_type "syst
 #=================================================
 ynh_script_progression --message="Starting a systemd service..."
 
-ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started ghost systemd service"
+ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
 
 #=================================================
 # RELOAD NGINX

From d044923af7b40aae4d18fabfab5696d72ea8480f Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Mon, 15 Jun 2020 00:14:51 +0200
Subject: [PATCH 09/18] cp: cannot stat
 '/tmp/tmp.g65lOMQ9Cq/config.production.json': No such file or directory

---
 scripts/upgrade | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/scripts/upgrade b/scripts/upgrade
index 26f6bc5..310339d 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -105,8 +105,11 @@ then
 	# Create a temporary directory
 	tmpdir="$(mktemp -d)"
 	
+		# Copy the admin saved settings from tmp directory to final path	
+	cp -ar "$final_path/config.production.json" "$tmpdir/config.production.json"	
+
 	# Backup the content folder to the temp dir
-	cp -ar "$final_path/content" "$tmpdir"
+	cp -ar "$final_path/content" "$tmpdir/content"
 
 	# Remove the app directory securely
 	ynh_secure_remove --file=$final_path
@@ -114,10 +117,10 @@ then
 	# Download, check integrity, uncompress and patch the source from app.src
 	ynh_setup_source --dest_dir=$final_path
 	
-	#Copy the admin saved settings from tmp directory to final path	
-	cp -a  "$tmpdir/config.production.json" "$final_path/config.production.json"	
+	# Copy the admin saved settings from tmp directory to final path	
+	cp -ar "$tmpdir/config.production.json" "$final_path/config.production.json"	
 
-	# copy content folder back to the final_path
+	# Copy content folder back to the final_path
 	cp -ar "$tmpdir/content" "${final_path}"
 
 	# Remove the tmp directory securely

From 1016a9e2aaa6b600a6c99f4a7576da91a991c708 Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Mon, 15 Jun 2020 01:16:03 +0200
Subject: [PATCH 10/18] Fix upgrade: missing helper

---
 scripts/upgrade | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/upgrade b/scripts/upgrade
index 310339d..2079697 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -7,6 +7,7 @@
 #=================================================
 
 source _common.sh
+source ynh_add_config
 source /usr/share/yunohost/helpers
 
 #=================================================
@@ -105,7 +106,7 @@ then
 	# Create a temporary directory
 	tmpdir="$(mktemp -d)"
 	
-		# Copy the admin saved settings from tmp directory to final path	
+	# Copy the admin saved settings from tmp directory to final path	
 	cp -ar "$final_path/config.production.json" "$tmpdir/config.production.json"	
 
 	# Backup the content folder to the temp dir

From ca3034b49899dfe7991ff962f4bf2b628206907f Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Mon, 15 Jun 2020 06:15:33 +0200
Subject: [PATCH 11/18] fix YNH_NODE_LOAD_PATH

---
 conf/systemd.service | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/conf/systemd.service b/conf/systemd.service
index c63e73f..42265a6 100644
--- a/conf/systemd.service
+++ b/conf/systemd.service
@@ -7,7 +7,7 @@ Type=simple
 User=__APP__
 Group=__APP__
 WorkingDirectory=__FINALPATH__
-Environment="YNH_NODE_LOAD_PATH"
+Environment="__YNH_NODE_LOAD_PATH__"
 Environment="NODE_ENV=production"
 ExecStart=__YNH_NODE__ index.js run
 Restart=always

From 5f616d766d61a5da3682fa6a32e05e925a53c17b Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Mon, 15 Jun 2020 06:18:02 +0200
Subject: [PATCH 12/18] Update check_process

---
 check_process | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/check_process b/check_process
index 8de351d..a7a503d 100644
--- a/check_process
+++ b/check_process
@@ -19,8 +19,9 @@
 		upgrade=1
 		backup_restore=1
 		multi_instance=1
-		incorrect_path=1
-		port_already_use=1
+		# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
+		# incorrect_path=1
+		port_already_use=0
 		change_url=0
 ;;; Levels
 	Level 1=auto

From 1388694e53f8994e1c5dd285b12156b05b1086de Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Tue, 16 Jun 2020 06:12:50 +0200
Subject: [PATCH 13/18] Update ynh_add_config

---
 scripts/ynh_add_config | 162 ++++++++++++++++++++++++++++-------------
 1 file changed, 112 insertions(+), 50 deletions(-)

diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config
index 0e9a440..2fa451c 100644
--- a/scripts/ynh_add_config
+++ b/scripts/ynh_add_config
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Create a dedicated  config file
+# Create a dedicated config file
 #
 # usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"]
 # | arg: -o, --origin=     - Template config file to use (optionnal, ../conf/.env by default)
@@ -25,11 +25,18 @@
 #   __YNH_NODE_LOAD_PATH__    by $ynh_node_load_PATH
 #   __NODEJS_PATH__    by $nodejs_path
 #   __NODEJS_VERSION__    by $nodejs_version
+#   __DB_NAME__    by $db_name
+#   __DB_USER__    by $db_user
+#   __DB_PWD__    by $db_pwd
 #
 # And dynamic variables (from the last example) :
 #   __VAR_1__    by $var_1
 #   __VAR_2__    by $var_2
 #
+# The helper will verify the checksum and backup the destination file
+# if it's different before applying the new origin file.
+# And it will calculate and store a destination file checksum
+# into the app settings when configuraation is done.
 #
 ynh_add_config () {
     # Declare an array to define the options of this helper.
@@ -47,55 +54,7 @@ ynh_add_config () {
     ynh_backup_if_checksum_is_different --file="$destination"
     cp "$origin" "$destination"
 
-    #Replace usual YunoHost variables
-    if test -n "${path_url:-}"
-    then
-        # path_url_slash_less is path_url, or a blank value if path_url is only '/'
-        local path_url_slash_less=${path_url%/}
-        ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$destination"
-        ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$destination"
-    fi
-    if test -n "${domain:-}"; then
-        ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$destination"
-    fi
-    if test -n "${port:-}"; then
-        ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$destination"
-    fi
-    if test -n "${app:-}"; then
-        ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$destination"
-        ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$destination"
-        ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$destination"
-        ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$destination"
-    fi
-    if test -n "${final_path:-}"; then
-        ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$destination"
-    fi
-    if test -n "${YNH_PHP_VERSION:-}"; then
-        ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$destination"
-    fi
-    if test -n "${ynh_npm:-}"; then
-        ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$destination"
-    fi
-    if test -n "${ynh_node:-}"; then
-        ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$destination"
-    fi
-    if test -n "${ynh_node_load_PATH:-}"; then
-        ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$destination"
-    fi
-    if test -n "${nodejs_path:-}"; then
-        ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$destination"
-    fi
-    if test -n "${nodejs_version:-}"; then
-        ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$destination"
-    fi
-
-    # Replace all other variables given as arguments
-    for var_to_replace in $vars
-    do
-        # ${var_to_replace^^} make the content of the variable on upper-cases
-        # ${!var_to_replace} get the content of the variable named $var_to_replace 
-        ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$destination"
-    done
+    ynh_replace_vars --file="$destination" --vars="$vars"
 
     ynh_store_file_checksum --file="$destination"
 }
@@ -125,3 +84,106 @@ ynh_remove_config () {
         ynh_secure_remove --file="$file"
     fi
 }
+
+# Replace variables in a file
+#
+# usage: ynh_replace_vars --file="file" [--vars="vars to replace"]
+# | arg: -o, --file=     - Template config file to use
+# | arg: -v, --vars=  - List of variables to replace separated by a space. For example: 'var_1 var_2 ...'
+#
+# This will replace in the the following keywords with global variables
+# that should be defined before calling this helper :
+#   __PATH__      by  $path_url
+#   __DOMAIN__    by $domain
+#   __PORT__    by $port
+#   __NAME__    by $app
+#   __NAMETOCHANGE__    by $app
+#   __USER__    by $app
+#   __APP__    by $app
+#   __FINALPATH__    by $final_path
+#   __PHPVERSION__    by $YNH_PHP_VERSION
+#   __YNH_NPM__    by $ynh_npm
+#   __YNH_NODE__    by $ynh_node
+#   __YNH_NODE_LOAD_PATH__    by $ynh_node_load_PATH
+#   __NODEJS_PATH__    by $nodejs_path
+#   __NODEJS_VERSION__    by $nodejs_version
+#   __DB_NAME__    by $db_name
+#   __DB_USER__    by $db_user
+#   __DB_PWD__    by $db_pwd
+#
+# And dynamic variables (from the last example) :
+#   __VAR_1__    by $var_1
+#   __VAR_2__    by $var_2
+#
+#
+ynh_replace_vars () {
+    # Declare an array to define the options of this helper.
+    local legacy_args=fv
+    local -A args_array=( [f]=file= [v]=vars= )
+    local file
+    local vars
+    # Manage arguments with getopts
+    ynh_handle_getopts_args "$@"
+    local file="${file:-}"
+    local vars="${vars:-}"
+
+
+    #Replace usual YunoHost variables
+    if test -n "${path_url:-}"
+    then
+        # path_url_slash_less is path_url, or a blank value if path_url is only '/'
+        local path_url_slash_less=${path_url%/}
+        ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$file"
+        ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$file"
+    fi
+    if test -n "${domain:-}"; then
+        ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$file"
+    fi
+    if test -n "${port:-}"; then
+        ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$file"
+    fi
+    if test -n "${app:-}"; then
+        ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$file"
+        ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$file"
+        ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$file"
+        ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$file"
+    fi
+    if test -n "${final_path:-}"; then
+        ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$file"
+    fi
+    if test -n "${YNH_PHP_VERSION:-}"; then
+        ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file"
+    fi
+    if test -n "${ynh_npm:-}"; then
+        ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$file"
+    fi
+    if test -n "${ynh_node:-}"; then
+        ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$file"
+    fi
+    if test -n "${ynh_node_load_PATH:-}"; then
+        ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file"
+    fi
+    if test -n "${nodejs_path:-}"; then
+        ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$file"
+    fi
+    if test -n "${nodejs_version:-}"; then
+        ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$file"
+    fi
+    if test -n "${db_name:-}"; then
+        ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$file"
+    fi
+    if test -n "${db_user:-}"; then
+        ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$file"
+    fi
+    if test -n "${db_pwd:-}"; then
+        ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$file"
+    fi
+
+    # Replace all other variables given as arguments
+    for var_to_replace in $vars
+    do
+        # ${var_to_replace^^} make the content of the variable on upper-cases
+        # ${!var_to_replace} get the content of the variable named $var_to_replace 
+        ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$file"
+    done
+}
\ No newline at end of file

From bceae5e35b22706cb8afc700c05f8afdb828f30e Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Wed, 17 Jun 2020 00:45:02 +0200
Subject: [PATCH 14/18] Apply last example_ynh

---
 check_process   | 12 +-----------
 conf/nginx.conf | 24 ++++++++++++++++--------
 scripts/remove  |  2 +-
 scripts/restore |  2 +-
 scripts/upgrade | 33 ++++++++++++++++-----------------
 5 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/check_process b/check_process
index a7a503d..bb75880 100644
--- a/check_process
+++ b/check_process
@@ -24,18 +24,8 @@
 		port_already_use=0
 		change_url=0
 ;;; Levels
-	Level 1=auto
-	Level 2=auto
-	Level 3=auto
-# Level 4: 
-	Level 4=0
-# Level 5: 
+	# If the level 5 (Package linter) is forced to 1. Please add justifications here.
 	Level 5=auto
-	Level 6=auto
-	Level 7=auto
-	Level 8=0
-	Level 9=0
-	Level 10=0
 ;;; Options
 Email=
 Notification=none
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 693515a..1fdf0f5 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -1,10 +1,18 @@
-
+#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
 location  __PATH__/ {
-        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-        proxy_set_header X-Forwarded-Proto $scheme;
-        proxy_set_header X-Real-IP $remote_addr;
-        proxy_set_header Host $http_host;
-        proxy_pass http://127.0.0.1:__PORT__;
-        client_max_body_size 100M;
 
-    }
+  # Force usage of https
+  if ($scheme = http) {
+    rewrite ^ https://$server_name$request_uri? permanent;
+  }
+
+  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+  proxy_set_header X-Forwarded-Proto $scheme;
+  proxy_set_header X-Real-IP $remote_addr;
+  proxy_set_header Host $http_host;
+  proxy_pass http://127.0.0.1:__PORT__;
+  client_max_body_size 100M;
+
+  # Include SSOWAT user panel.
+  include conf.d/yunohost_panel.conf.inc;
+}
diff --git a/scripts/remove b/scripts/remove
index 7a4734d..6b68a77 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -31,7 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 # 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..."
+	ynh_script_progression --message="Removing $app service integration..."
 	yunohost service remove $app
 fi
 
diff --git a/scripts/restore b/scripts/restore
index b631be9..b8fb7a5 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -81,7 +81,7 @@ chown -R $app: $final_path
 #=================================================
 # REINSTALL DEPENDENCIES
 #=================================================
-ynh_script_progression --message="Reinstalling dependencies..." --weight=7
+ynh_script_progression --message="Reinstalling dependencies..."
 
 # Define and install dependencies
 ynh_install_app_dependencies $pkg_dependencies
diff --git a/scripts/upgrade b/scripts/upgrade
index 2079697..1791b57 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -53,15 +53,14 @@ if [ -z "$db_name" ]; then
 	ynh_app_setting_set --app=$app --key=db_name --value=$db_name
 fi
 
-
 #=================================================
 # CLOSE A PORT
 #=================================================
 
 if yunohost firewall list | grep -q "\- $port$"
 then
-	echo "Close port $port"
-	yunohost firewall disallow TCP $port 2>&1
+	ynh_script_progression --message="Closing port $port..."
+	ynh_exec_warn_less yunohost firewall disallow TCP $port
 fi
 
 #=================================================
@@ -207,6 +206,20 @@ ynh_script_progression --message="Securing files and directories..."
 # Set permissions on app files
 chown -R $app: $final_path
 
+#=================================================
+# INTEGRATE SERVICE IN YUNOHOST
+#=================================================
+ynh_script_progression --message="Integrating service in YunoHost..."
+
+yunohost service add $app --description "$app daemon for Ghost" --log_type "systemd"
+
+#=================================================
+# START SYSTEMD SERVICE
+#=================================================
+ynh_script_progression --message="Starting a systemd service..."
+
+ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
+
 #=================================================
 # SETUP SSOWAT
 #=================================================
@@ -222,20 +235,6 @@ then
 	ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
 fi
 
-#=================================================
-# INTEGRATE SERVICE IN YUNOHOST
-#=================================================
-ynh_script_progression --message="Integrating service in YunoHost..."
-
-yunohost service add $app --description "$app daemon for Ghost" --log_type "systemd"
-
-#=================================================
-# START SYSTEMD SERVICE
-#=================================================
-ynh_script_progression --message="Starting a systemd service..."
-
-ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
-
 #=================================================
 # RELOAD NGINX
 #=================================================

From 2c10036c1ae7acbc82cf0b7671511507b6e21d8b Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Thu, 18 Jun 2020 00:20:32 +0200
Subject: [PATCH 15/18] Update ynh_add_config

---
 scripts/ynh_add_config | 180 +++++++++++++++--------------------------
 1 file changed, 63 insertions(+), 117 deletions(-)

diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config
index 2fa451c..031aadc 100644
--- a/scripts/ynh_add_config
+++ b/scripts/ynh_add_config
@@ -1,134 +1,99 @@
 #!/bin/bash
 
-# Create a dedicated config file
+# Create a dedicated config file from a template
 #
-# usage: ynh_add_config [--origin="origin file"] [--destination="destination file"] [--vars="vars to replace"]
-# | arg: -o, --origin=     - Template config file to use (optionnal, ../conf/.env by default)
-# | arg: -d, --destination=    - Destination of the config file (optionnal, $final_path/.env)
-# | arg: -v, --vars=  - List of variables to replace separated by a space. For example: 'var_1 var_2 ...'
+# examples: 
+#    ynh_add_config --template=".env" --destination="$final_path/.env"
+#    ynh_add_config --template="../conf/.env" --destination="$final_path/.env"
+#    ynh_add_config --template="/etc/nginx/sites-available/default" --destination="etc/nginx/sites-available/mydomain.conf"
 #
-# This will use the template $origin or ../conf/.env by default
-# to generate a config file $destination or $final_path/.env by default,
-# by replacing the following keywords with global variables
+# usage: ynh_add_config --template="template" --destination="destination"
+# | arg: -t, --template=     - Template config file to use
+# | arg: -d, --destination=    - Destination of the config file
+#
+# The template can be by default the name of a file in the conf directory
+# of a YunoHost Package, a relative path or an absolute path
+# The helper will use the template $template to generate a config file
+# $destination by replacing the following keywords with global variables
 # that should be defined before calling this helper :
 #   __PATH__      by  $path_url
-#   __DOMAIN__    by $domain
-#   __PORT__    by $port
 #   __NAME__    by $app
 #   __NAMETOCHANGE__    by $app
 #   __USER__    by $app
-#   __APP__    by $app
 #   __FINALPATH__    by $final_path
 #   __PHPVERSION__    by $YNH_PHP_VERSION
-#   __YNH_NPM__    by $ynh_npm
-#   __YNH_NODE__    by $ynh_node
-#   __YNH_NODE_LOAD_PATH__    by $ynh_node_load_PATH
-#   __NODEJS_PATH__    by $nodejs_path
-#   __NODEJS_VERSION__    by $nodejs_version
-#   __DB_NAME__    by $db_name
-#   __DB_USER__    by $db_user
-#   __DB_PWD__    by $db_pwd
 #
-# And dynamic variables (from the last example) :
+# And any dynamic variables that should be defined before calling this helper like:
+#   __DOMAIN__    by $domain
+#   __APP__    by $app
 #   __VAR_1__    by $var_1
 #   __VAR_2__    by $var_2
 #
 # The helper will verify the checksum and backup the destination file
-# if it's different before applying the new origin file.
-# And it will calculate and store a destination file checksum
-# into the app settings when configuraation is done.
+# if it's different before applying the new template.
+# And it will calculate and store the destination file checksum
+# into the app settings when configuration is done.
+#
 #
 ynh_add_config () {
     # Declare an array to define the options of this helper.
-    local legacy_args=odv
-    local -A args_array=( [o]=origin= [d]=destination= [v]=vars= )
-    local origin
+    local legacy_args=tdv
+    local -A args_array=( [t]=template= [d]=destination= )
+    local template
     local destination
-    local vars
     # Manage arguments with getopts
     ynh_handle_getopts_args "$@"
-    local origin="${origin:-"../conf/.env"}"
-    local destination="${destination:-"$final_path/.env"}"
-    local vars="${vars:-}"
+    local template_path
+
+    if [ -f "../conf/$template" ]; then
+        template_path="../conf/$template"
+    elif [ -f "../settings/conf/$template" ]; then
+        template_path="../settings/conf/$template"
+    elif [ -f "$template" ]; then
+        template_path=$template
+    else
+        ynh_die --message="The provided template $template doesn't exist"
+    fi
 
     ynh_backup_if_checksum_is_different --file="$destination"
-    cp "$origin" "$destination"
 
-    ynh_replace_vars --file="$destination" --vars="$vars"
+    cp "$template_path" "$destination"
+
+    ynh_replace_vars --file="$destination"
 
     ynh_store_file_checksum --file="$destination"
 }
 
-# Remove the dedicated config
-#
-# usage: ynh_remove_config [--file=file]
-# | arg: -f, --file=     - Config file to remove (optionnal, $final_path/.env)
-#
-#
-ynh_remove_config () {
-    # Declare an array to define the options of this helper.
-    local legacy_args=f
-    local -A args_array=( [f]=file= )
-    local file
-    # Manage arguments with getopts
-    ynh_handle_getopts_args "$@"
-    local service="${file:-}"
-
-    # The default behaviour is to use .env file.
-    if [ -n "$file" ]; then
-        file="final_path/.env"
-    fi
-
-    if [ -e "$file" ]
-    then
-        ynh_secure_remove --file="$file"
-    fi
-}
-
 # Replace variables in a file
 #
-# usage: ynh_replace_vars --file="file" [--vars="vars to replace"]
-# | arg: -o, --file=     - Template config file to use
-# | arg: -v, --vars=  - List of variables to replace separated by a space. For example: 'var_1 var_2 ...'
+# usage: ynh_replace_vars --file="file"
+# | arg: -f, --file=     - File where to replace variables
 #
-# This will replace in the the following keywords with global variables
+# The helper will replace the following keywords with global variables
 # that should be defined before calling this helper :
 #   __PATH__      by  $path_url
-#   __DOMAIN__    by $domain
-#   __PORT__    by $port
 #   __NAME__    by $app
 #   __NAMETOCHANGE__    by $app
 #   __USER__    by $app
-#   __APP__    by $app
 #   __FINALPATH__    by $final_path
 #   __PHPVERSION__    by $YNH_PHP_VERSION
-#   __YNH_NPM__    by $ynh_npm
-#   __YNH_NODE__    by $ynh_node
-#   __YNH_NODE_LOAD_PATH__    by $ynh_node_load_PATH
-#   __NODEJS_PATH__    by $nodejs_path
-#   __NODEJS_VERSION__    by $nodejs_version
-#   __DB_NAME__    by $db_name
-#   __DB_USER__    by $db_user
-#   __DB_PWD__    by $db_pwd
 #
-# And dynamic variables (from the last example) :
+# And any dynamic variables that should be defined before calling this helper like:
+#   __DOMAIN__    by $domain
+#   __APP__    by $app
 #   __VAR_1__    by $var_1
 #   __VAR_2__    by $var_2
 #
 #
 ynh_replace_vars () {
     # Declare an array to define the options of this helper.
-    local legacy_args=fv
-    local -A args_array=( [f]=file= [v]=vars= )
+    local legacy_args=f
+    local -A args_array=( [f]=file= )
     local file
-    local vars
     # Manage arguments with getopts
     ynh_handle_getopts_args "$@"
-    local file="${file:-}"
-    local vars="${vars:-}"
 
-
-    #Replace usual YunoHost variables
+    # Replace specific YunoHost variables
     if test -n "${path_url:-}"
     then
         # path_url_slash_less is path_url, or a blank value if path_url is only '/'
@@ -136,17 +101,10 @@ ynh_replace_vars () {
         ynh_replace_string --match_string="__PATH__/" --replace_string="$path_url_slash_less/" --target_file="$file"
         ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$file"
     fi
-    if test -n "${domain:-}"; then
-        ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$file"
-    fi
-    if test -n "${port:-}"; then
-        ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$file"
-    fi
     if test -n "${app:-}"; then
         ynh_replace_string --match_string="__NAME__" --replace_string="$app" --target_file="$file"
         ynh_replace_string --match_string="__NAMETOCHANGE__" --replace_string="$app" --target_file="$file"
         ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="$file"
-        ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$file"
     fi
     if test -n "${final_path:-}"; then
         ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$file"
@@ -154,36 +112,24 @@ ynh_replace_vars () {
     if test -n "${YNH_PHP_VERSION:-}"; then
         ynh_replace_string --match_string="__PHPVERSION__" --replace_string="$YNH_PHP_VERSION" --target_file="$file"
     fi
-    if test -n "${ynh_npm:-}"; then
-        ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="$file"
-    fi
-    if test -n "${ynh_node:-}"; then
-        ynh_replace_string --match_string="__YNH_NODE__" --replace_string="$ynh_node" --target_file="$file"
-    fi
-    if test -n "${ynh_node_load_PATH:-}"; then
-        ynh_replace_string --match_string="__YNH_NODE_LOAD_PATH__" --replace_string="$ynh_node_load_PATH" --target_file="$file"
-    fi
-    if test -n "${nodejs_path:-}"; then
-        ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$file"
-    fi
-    if test -n "${nodejs_version:-}"; then
-        ynh_replace_string --match_string="__NODEJS_VERSION__" --replace_string="$nodejs_version" --target_file="$file"
-    fi
-    if test -n "${db_name:-}"; then
-        ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$file"
-    fi
-    if test -n "${db_user:-}"; then
-        ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$file"
-    fi
-    if test -n "${db_pwd:-}"; then
-        ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$file"
-    fi
 
-    # Replace all other variables given as arguments
-    for var_to_replace in $vars
+    # Replace othes variables
+
+    # List other unique (__ __) variables in $file
+    local uniques_vars=( $(grep -o '__[^.]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
+
+    # Do the replacement
+    local delimit=@
+    for one_var in "${uniques_vars[@]}"
     do
-        # ${var_to_replace^^} make the content of the variable on upper-cases
-        # ${!var_to_replace} get the content of the variable named $var_to_replace 
-        ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$file"
+        if test -n "${!one_var:-}"; then
+            match_string="__${one_var^^}__"
+            match_string=${match_string//${delimit}/"\\${delimit}"}
+            replace_string="${!one_var}"
+            replace_string=${replace_string//${delimit}/"\\${delimit}"}
+            sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file"
+        else
+            ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
+        fi
     done
 }
\ No newline at end of file

From 06f73c81b8fcb030dc72be5b767a656443b63ecb Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Thu, 18 Jun 2020 00:58:38 +0200
Subject: [PATCH 16/18] Update ynh_add_config

---
 scripts/install        |  2 +-
 scripts/upgrade        |  2 +-
 scripts/ynh_add_config | 52 ++++++++++++++++++++++--------------------
 3 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/scripts/install b/scripts/install
index 6cec36b..eeab2b0 100644
--- a/scripts/install
+++ b/scripts/install
@@ -123,7 +123,7 @@ ynh_system_user_create --username=$app
 #=================================================
 ynh_script_progression --message="Modifying a config file..."
 
-ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd"
+ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json"
 
 #==============================================
 # BUILD GHOST
diff --git a/scripts/upgrade b/scripts/upgrade
index 1791b57..b7f63a5 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -168,7 +168,7 @@ ynh_system_user_create --username=$app
 #=================================================
 ynh_script_progression --message="Modifying a config file..."
 
-ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd"
+ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json"
 
 #==============================================
 # BUILD GHOST
diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config
index 031aadc..2c3efd2 100644
--- a/scripts/ynh_add_config
+++ b/scripts/ynh_add_config
@@ -16,16 +16,16 @@
 # The helper will use the template $template to generate a config file
 # $destination by replacing the following keywords with global variables
 # that should be defined before calling this helper :
-#   __PATH__      by  $path_url
-#   __NAME__    by $app
+#   __PATH__             by  $path_url
+#   __NAME__            by $app
 #   __NAMETOCHANGE__    by $app
-#   __USER__    by $app
-#   __FINALPATH__    by $final_path
-#   __PHPVERSION__    by $YNH_PHP_VERSION
+#   __USER__            by $app
+#   __FINALPATH__       by $final_path
+#   __PHPVERSION__      by $YNH_PHP_VERSION
 #
 # And any dynamic variables that should be defined before calling this helper like:
-#   __DOMAIN__    by $domain
-#   __APP__    by $app
+#   __DOMAIN__   by $domain
+#   __APP__      by $app
 #   __VAR_1__    by $var_1
 #   __VAR_2__    by $var_2
 #
@@ -71,16 +71,16 @@ ynh_add_config () {
 #
 # The helper will replace the following keywords with global variables
 # that should be defined before calling this helper :
-#   __PATH__      by  $path_url
-#   __NAME__    by $app
+#   __PATH__             by  $path_url
+#   __NAME__            by $app
 #   __NAMETOCHANGE__    by $app
-#   __USER__    by $app
-#   __FINALPATH__    by $final_path
-#   __PHPVERSION__    by $YNH_PHP_VERSION
+#   __USER__            by $app
+#   __FINALPATH__       by $final_path
+#   __PHPVERSION__      by $YNH_PHP_VERSION
 #
 # And any dynamic variables that should be defined before calling this helper like:
-#   __DOMAIN__    by $domain
-#   __APP__    by $app
+#   __DOMAIN__   by $domain
+#   __APP__      by $app
 #   __VAR_1__    by $var_1
 #   __VAR_2__    by $var_2
 #
@@ -116,20 +116,22 @@ ynh_replace_vars () {
     # Replace othes variables
 
     # List other unique (__ __) variables in $file
-    local uniques_vars=( $(grep -o '__[^.]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
+    local uniques_vars=( $(grep -o '__[A-Z0-9]+__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
 
     # Do the replacement
     local delimit=@
     for one_var in "${uniques_vars[@]}"
     do
-        if test -n "${!one_var:-}"; then
-            match_string="__${one_var^^}__"
-            match_string=${match_string//${delimit}/"\\${delimit}"}
-            replace_string="${!one_var}"
-            replace_string=${replace_string//${delimit}/"\\${delimit}"}
-            sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file"
-        else
-            ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
-        fi
+        # Validate that one_var is indeed defined
+        test -n "${!one_var:-}" || ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
+        
+        # Escape delimiter in match/replace string
+        match_string="__${one_var^^}__"
+        match_string=${match_string//${delimit}/"\\${delimit}"}
+        replace_string="${!one_var}"
+        replace_string=${replace_string//${delimit}/"\\${delimit}"}
+        
+        # Actually replace (sed is used instead of ynh_replace_string to avoid triggering an epic amount of debug logs)
+        sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file"
     done
-}
\ No newline at end of file
+}

From 0772ca053c04f86decb77eb911c4dc08f2160a41 Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Thu, 18 Jun 2020 01:24:24 +0200
Subject: [PATCH 17/18] Update ynh_add_config

---
 scripts/ynh_add_config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/ynh_add_config b/scripts/ynh_add_config
index 2c3efd2..e92e46f 100644
--- a/scripts/ynh_add_config
+++ b/scripts/ynh_add_config
@@ -116,7 +116,7 @@ ynh_replace_vars () {
     # Replace othes variables
 
     # List other unique (__ __) variables in $file
-    local uniques_vars=( $(grep -o '__[A-Z0-9]+__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
+    local uniques_vars=( $(grep -o '__[A-Z0-9_]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
 
     # Do the replacement
     local delimit=@

From fcf68c68c617da71aa81b32a44afc1d625061843 Mon Sep 17 00:00:00 2001
From: yalh76 
Date: Sat, 20 Jun 2020 17:56:26 +0200
Subject: [PATCH 18/18] Update check_process

---
 check_process | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/check_process b/check_process
index bb75880..7b42117 100644
--- a/check_process
+++ b/check_process
@@ -17,6 +17,8 @@
 		setup_private=1
 		setup_public=1
 		upgrade=1
+		# 2.1.1
+		upgrade=1	from_commit=d82ce7f51218a4ec32acedbe643b1168721786d0
 		backup_restore=1
 		multi_instance=1
 		# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.
@@ -29,3 +31,7 @@
 ;;; Options
 Email=
 Notification=none
+;;; Upgrade options
+	; commit=d82ce7f51218a4ec32acedbe643b1168721786d0
+		name=2.1.1
+