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-
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
-[](https://ci-apps.yunohost.org/jenkins/job/ghost%20%28Community%29/lastBuild/consoleFull)
-[](https://install-app.yunohost.org/?app=ghost)
-=======
+[](https://dash.yunohost.org/appci/app/ghost)  
+[](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
+
+
## 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 - [](https://ci-apps.yunohost.org/ci/apps/ghost/)
+* ARMv8-A - [](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/check_process b/check_process
index 8de351d..7b42117 100644
--- a/check_process
+++ b/check_process
@@ -17,24 +17,21 @@
setup_private=1
setup_public=1
upgrade=1
+ # 2.1.1
+ upgrade=1 from_commit=d82ce7f51218a4ec32acedbe643b1168721786d0
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
- 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
+;;; Upgrade options
+ ; commit=d82ce7f51218a4ec32acedbe643b1168721786d0
+ name=2.1.1
+
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/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/conf/systemd.service b/conf/systemd.service
index 5f61256..42265a6 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..7dc0b54 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,26 +6,26 @@
"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": {
+ "maintainer": {
"name": "Julien Malik",
"email": "julien.malik@paraiso.me"
},
"requirements": {
- "yunohost": ">= 2.7.2"
+ "yunohost": ">= 3.8.1"
},
"multi_instance": true,
"services": [
"nginx",
- "nodjs",
"mysql"
],
"arguments": {
"install" : [
{
"name": "domain",
+ "type": "domain",
"ask": {
"en": "Choose a domain for Ghost",
"fr": "Choisissez un domaine pour Ghost"
@@ -34,9 +34,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 +54,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*
+
+[/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..0cfd71a 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -1,63 +1,22 @@
#!/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"
-ynh_send_readme_to_admin() {
- local app_message="${1:-...No specific information...}"
- local recipients="${2:-root}"
+NODEJS_VERSION=10
- # 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")
+#=================================================
+# PERSONAL HELPERS
+#=================================================
- local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
+#=================================================
+# EXPERIMENTAL HELPERS
+#=================================================
- 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"
-}
+#=================================================
+# FUTURE OFFICIAL HELPERS
+#=================================================
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 f27be8f..eeab2b0 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://ghost.org/zip/ghost-latest.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 --template="../conf/config.production.json" --destination="$final_path/config.production.json"
-# 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="Ghost boot"
#=================================================
# 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..6b68a77 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 integration..."
+ 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..b8fb7a5 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..."
-# 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="Ghost boot"
#=================================================
# 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 153d8a3..b7f63a5 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -7,49 +7,72 @@
#=================================================
source _common.sh
+source ynh_add_config
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
+#=================================================
+# CLOSE A PORT
+#=================================================
+
+if yunohost firewall list | grep -q "\- $port$"
+then
+ ynh_script_progression --message="Closing port $port..."
+ ynh_exec_warn_less yunohost firewall disallow TCP $port
+fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
+ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# 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
@@ -60,83 +83,54 @@ ynh_abort_if_errors
#=================================================
# Normalize the URL path syntax
-path_url=$(ynh_normalize_url_path $path_url)
+path_url=$(ynh_normalize_url_path --path_url=$path_url)
#=================================================
# 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
#=================================================
-# 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://ghost.org/zip/ghost-latest.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
-#=================================================
-
-if yunohost firewall list | grep -q "\- $port$"
+if [ "$upgrade_type" == "UPGRADE_APP" ]
then
- echo "Close port $port"
- yunohost firewall disallow TCP $port 2>&1
+ ynh_script_progression --message="Upgrading source files..." --weight=160
+
+ # 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/content"
+
+ # 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 -ar "$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
-#=================================================
-# 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_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"
-
-# Migrate tables in database
-(
- cd "$final_path"
-NODE_ENV=production knex-migrator init
-
-)
-
-
#=================================================
# NGINX CONFIGURATION
#=================================================
+ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
@@ -146,42 +140,90 @@ 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 --template="../conf/config.production.json" --destination="$final_path/config.production.json"
+
+#==============================================
+# 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
+#=================================================
+# 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
#=================================================
+ynh_script_progression --message="Upgrading SSOwat configuration..."
if [ $is_public -eq 0 ]
then # Remove the public access
@@ -190,13 +232,18 @@ 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
-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..e92e46f
--- /dev/null
+++ b/scripts/ynh_add_config
@@ -0,0 +1,137 @@
+#!/bin/bash
+
+# Create a dedicated config file from a template
+#
+# 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"
+#
+# 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
+# __NAME__ by $app
+# __NAMETOCHANGE__ by $app
+# __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
+# __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 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=tdv
+ local -A args_array=( [t]=template= [d]=destination= )
+ local template
+ local destination
+ # Manage arguments with getopts
+ ynh_handle_getopts_args "$@"
+ 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 "$template_path" "$destination"
+
+ ynh_replace_vars --file="$destination"
+
+ ynh_store_file_checksum --file="$destination"
+}
+
+# Replace variables in a file
+#
+# usage: ynh_replace_vars --file="file"
+# | arg: -f, --file= - File where to replace variables
+#
+# 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
+# __NAMETOCHANGE__ by $app
+# __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
+# __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=f
+ local -A args_array=( [f]=file= )
+ local file
+ # Manage arguments with getopts
+ ynh_handle_getopts_args "$@"
+
+ # 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 '/'
+ 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 "${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"
+ 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
+
+ # 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" ))
+
+ # Do the replacement
+ local delimit=@
+ for one_var in "${uniques_vars[@]}"
+ do
+ # 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
+}
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
" 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" +}