1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ghost_ynh.git synced 2024-09-03 19:16:02 +02:00

Merge pull request #40 from YunoHost-Apps/testing

Testing
This commit is contained in:
Éric Gaspar 2021-06-04 14:15:03 +02:00 committed by GitHub
commit d990989c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 211 additions and 241 deletions

View file

@ -1,6 +1,6 @@
---
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.
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
@ -8,15 +8,17 @@ about: Create a report to help us debug, it would be nice to fill the template a
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.*
- *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
**Describe the bug**
### Describe the bug
*A clear and concise description of what the bug is.*
**Versions**
### Context
- 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 | ...*
@ -25,11 +27,11 @@ about: Create a report to help us debug, it would be nice to fill the template a
- 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.*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install ghost
sudo yunohost app install the_app
```
- *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:*
@ -38,9 +40,16 @@ about: Create a report to help us debug, it would be nice to fill the template a
3. *Scroll down to '...'*
4. *See error*
**Expected behavior**
### 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.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

View file

@ -1,60 +1,62 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# Ghost for YunoHost
[![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.svg)](https://install-app.yunohost.org/?app=ghost)
*[Lire ce readme en français.](./README_fr.md)*
> *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.*
## Overview
Ghost is a fully open source, adaptable platform for building and running a modern online publication.
**Shipped version:** 3.41.8
Just a blogging platform
**Shipped version:** 4.3.3~ynh1
**Demo:** https://dispatch.khlieng.com/connect
## Screenshots
![](https://ghost.org/images/home/home-screenshot_hu41cb56656a4d54646913b3f720de164d_129780_2000x0_resize_box_2.png)
![](./doc/screenshots/screenshot.png)
## Disclaimers / important information
## Installation
### Guidelines
1. No LDAP support.
1. You need more then **1GB** of ram. If you don't have it, please create a **swap memory**.
$ dd if=/dev/zero of=/swapfile bs=1024 count=1048576
$ mkswap /swapfile
$ swapon /swapfile
$ echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
1. This app is multi-instance (you can have more then one Ghost blogging websites on a single YunoHost server)
### Installing the Ghost app
0. Note - When making the install public, your Ghost domain link must be accessed WHILE NOT signed into your YunoHost session. It is recommended to use a incognito mode to sign into your Ghost admin account. If you make your install public, and try to login your Ghost admin account while signed into your YunoHost session, you will get a an authorized header error. The reason for this is because Ghost has a feature that allows for a subscription based access for content. This means Ghost allows for the admin user to setup other users (either other staff or paid/unpaid subscribers) to have the abilility to login outside of YunoHost.
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/ghost
`sudo yunohost app install https://github.com/YunoHost-Apps/ghost_ynh`
## Documentation
2. After installation create an **admin account** by visiting `https://domain.tld/ghost/ghost`. If you choose to name your Ghost instance "blog" during YunoHost setup process, then it would be `https://domain.tld/blog/ghost`. This will allow you to continue to setup your admin account and configure your settings.
* Official documentation: https://ghost.org/docs/
## Documentation and resources
## 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/
---
* Official app website: https://example.com
* Official user documentation: https://yunohost.org/apps
* Official admin documentation: https://yunohost.org/packaging_apps
* Upstream app code repository: https://some.forge.com/example/example
* YunoHost documentation for this app: https://yunohost.org/app_ghost
* Report a bug: https://github.com/YunoHost-Apps/ghost_ynh/issues
## Developer info
@ -66,3 +68,5 @@ sudo yunohost app install https://github.com/YunoHost-Apps/ghost_ynh/tree/testin
or
sudo yunohost app upgrade ghost -u https://github.com/YunoHost-Apps/ghost_ynh/tree/testing --debug
```
**More info regarding app packaging:** https://yunohost.org/packaging_apps

67
README_fr.md Normal file
View file

@ -0,0 +1,67 @@
# Ghost pour YunoHost
[![Niveau d'intégration](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)
[![Installer Ghost avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=ghost)
*[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer Ghost rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
## Vue d'ensemble
Plateforme de blogging
**Version incluse :** 4.3.3~ynh1
**Démo :** https://dispatch.khlieng.com/connect
## Captures d'écran
![](./doc/screenshots/screenshot.png)
## Avertissements / informations importantes
## Installation
1. Pas de prise en charge LDAP.
1. Vous avez besoin de plus de **1 Go** de RAM. Si vous ne l'avez pas, veuillez créer une **mémoire d'échange**.
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /fichier d'échange
swapon / fichier d'échange
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
1. Cette application est multi-instance (vous pouvez avoir plusieurs sites Web de blogs Ghost sur un seul serveur YunoHost)
### Installation de l'application Ghost
0. Remarque - Lorsque vous rendez l'installation publique, vous devez accéder à votre lien de domaine Ghost SANS vous connecter à votre session YunoHost. Il est recommandé d'utiliser un mode incognito pour vous connecter à votre compte administrateur Ghost. Si vous rendez votre installation publique et essayez de vous connecter à votre compte administrateur Ghost tout en étant connecté à votre session YunoHost, vous obtiendrez une erreur d'en-tête autorisée. La raison en est que Ghost a une fonctionnalité qui permet un accès au contenu basé sur un abonnement. Cela signifie que Ghost permet à l'utilisateur administrateur de configurer d'autres utilisateurs (soit d'autres membres du personnel, soit des abonnés payés/non payés) pour avoir la possibilité de se connecter en dehors de YunoHost.
1. ** L'application peut être installée par l'interface d'administration YunoHost ou par la commande suivante : **
`sudo yunohost installer l'application https://github.com/YunoHost-Apps/ghost_ynh`
2. Après l'installation, créez un **compte administrateur** en visitant `https://domain.tld/ghost/ghost`. Si vous choisissez de nommer votre instance Ghost "blog" pendant le processus d'installation de YunoHost, alors ce sera "https://domain.tld/blog/ghost". Cela vous permettra de continuer à configurer votre compte administrateur et à configurer vos paramètres.
## Documentations et ressources
* Site officiel de l'app : https://example.com
* Documentation officielle utilisateur : https://yunohost.org/apps
* Documentation officielle de l'admin : https://yunohost.org/packaging_apps
* Dépôt de code officiel de l'app : https://some.forge.com/example/example
* Documentation YunoHost pour cette app : https://yunohost.org/app_ghost
* Signaler un bug : https://github.com/YunoHost-Apps/ghost_ynh/issues
## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/ghost_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
```
sudo yunohost app install https://github.com/YunoHost-Apps/ghost_ynh/tree/testing --debug
ou
sudo yunohost app upgrade ghost -u https://github.com/YunoHost-Apps/ghost_ynh/tree/testing --debug
```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps

View file

@ -1,13 +1,8 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
domain="domain.tld"
path="/path"
is_public=1
; Checks
pkg_linter=1
@ -23,7 +18,6 @@
upgrade=1 from_commit=6e4b84cabe351f9c62678089f236f1b3bb21d543
backup_restore=1
multi_instance=1
port_already_use=0
change_url=0
;;; Options
Email=

View file

@ -1,6 +1,7 @@
SOURCE_URL=https://github.com/TryGhost/Admin/archive/3.41.8.zip
SOURCE_SUM=252080e8b4fdc558300b2d33701735a3e2a6d7d82ef66a5eeb9b651a488c67e0
SOURCE_URL=https://github.com/TryGhost/Admin/archive/v4.3.3.zip
SOURCE_SUM=b5f6a125ec9c9bf26a5035a39b947f1d520621d5c7994aab6f6bcf54a3bc8e1e
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=false
SOURCE_FILENAME=

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/TryGhost/Ghost/releases/download/3.41.8/Ghost-3.41.8.zip
SOURCE_SUM=e650e3d55155c5974a8c3e58bf996c523be51b3a38f9728517b14d9114e0106a
SOURCE_URL=https://github.com/TryGhost/Ghost/releases/download/v4.3.3/Ghost-4.3.3.zip
SOURCE_SUM=7b3acd2acdbb26521c0ec6c717484c173b8751bcd054018e5a335495426338c8
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=false

21
doc/DISCLAIMER.md Normal file
View file

@ -0,0 +1,21 @@
## Installation
1. No LDAP support.
1. You need more then **1GB** of ram. If you don't have it, please create a **swap memory**.
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
1. This app is multi-instance (you can have more then one Ghost blogging websites on a single YunoHost server)
### Installing the Ghost app
0. Note - When making the install public, your Ghost domain link must be accessed WHILE NOT signed into your YunoHost session. It is recommended to use a incognito mode to sign into your Ghost admin account. If you make your install public, and try to login your Ghost admin account while signed into your YunoHost session, you will get a an authorized header error. The reason for this is because Ghost has a feature that allows for a subscription based access for content. This means Ghost allows for the admin user to setup other users (either other staff or paid/unpaid subscribers) to have the abilility to login outside of YunoHost.
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`
2. After installation create an **admin account** by visiting `https://domain.tld/ghost/ghost`. If you choose to name your Ghost instance "blog" during YunoHost setup process, then it would be `https://domain.tld/blog/ghost`. This will allow you to continue to setup your admin account and configure your settings.

21
doc/DISCLAIMER_fr.md Normal file
View file

@ -0,0 +1,21 @@
## Installation
1. Pas de prise en charge LDAP.
1. Vous avez besoin de plus de **1 Go** de RAM. Si vous ne l'avez pas, veuillez créer une **mémoire d'échange**.
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /fichier d'échange
swapon / fichier d'échange
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
1. Cette application est multi-instance (vous pouvez avoir plusieurs sites Web de blogs Ghost sur un seul serveur YunoHost)
### Installation de l'application Ghost
0. Remarque - Lorsque vous rendez l'installation publique, vous devez accéder à votre lien de domaine Ghost SANS vous connecter à votre session YunoHost. Il est recommandé d'utiliser un mode incognito pour vous connecter à votre compte administrateur Ghost. Si vous rendez votre installation publique et essayez de vous connecter à votre compte administrateur Ghost tout en étant connecté à votre session YunoHost, vous obtiendrez une erreur d'en-tête autorisée. La raison en est que Ghost a une fonctionnalité qui permet un accès au contenu basé sur un abonnement. Cela signifie que Ghost permet à l'utilisateur administrateur de configurer d'autres utilisateurs (soit d'autres membres du personnel, soit des abonnés payés/non payés) pour avoir la possibilité de se connecter en dehors de YunoHost.
1. ** L'application peut être installée par l'interface d'administration YunoHost ou par la commande suivante : **
`sudo yunohost installer l'application https://github.com/YunoHost-Apps/ghost_ynh`
2. Après l'installation, créez un **compte administrateur** en visitant `https://domain.tld/ghost/ghost`. Si vous choisissez de nommer votre instance Ghost "blog" pendant le processus d'installation de YunoHost, alors ce sera "https://domain.tld/blog/ghost". Cela vous permettra de continuer à configurer votre compte administrateur et à configurer vos paramètres.

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

View file

@ -6,15 +6,23 @@
"en": "Just a blogging platform",
"fr": "Plateforme de blogging"
},
"version": "3.41.8~ynh1",
"version": "4.3.3~ynh1",
"url": "https://ghost.org/",
"upstream": {
"license": "MIT",
"website": "https://example.com",
"demo": "https://dispatch.khlieng.com/connect",
"admindoc": "https://yunohost.org/packaging_apps",
"userdoc": "https://yunohost.org/apps",
"code": "https://some.forge.com/example/example"
},
"license": "MIT",
"maintainer": {
"name": "Julien Malik",
"email": "julien.malik@paraiso.me"
},
"requirements": {
"yunohost": ">= 3.8.1"
"yunohost": ">= 4.2.0"
},
"multi_instance": true,
"services": [
@ -26,29 +34,17 @@
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for Ghost",
"fr": "Choisissez un domaine pour Ghost"
},
"example": "domain.org"
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for Ghost",
"fr": "Choisissez un chemin pour Ghost"
},
"example": "/blog",
"default": "/blog"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public application?",
"fr": "Est-ce une application publique ?"
},
"default": true
}
]

View file

@ -1,16 +0,0 @@
## 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
---
* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"*

View file

@ -7,7 +7,6 @@
#=================================================
source _common.sh
source ynh_add_config
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
@ -49,7 +48,6 @@ ynh_script_progression --message="Storing installation settings..." --weight=1
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
@ -176,7 +174,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..."
ynh_script_progression --message="Configuring permissions..."
if [ $is_public -eq 1 ]
then

View file

@ -121,7 +121,7 @@ yunohost service add $app --description="$app daemon for Ghost" --log="/var/log/
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Ghost boot"
#=================================================
# GENERIC FINALIZATION

View file

@ -7,7 +7,6 @@
#=================================================
source _common.sh
source ynh_add_config
source /usr/share/yunohost/helpers
#=================================================
@ -19,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME
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)
@ -38,21 +36,19 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
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 --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
@ -75,7 +71,7 @@ ynh_abort_if_errors
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -200,7 +196,7 @@ yunohost service add $app --description="$app daemon for Ghost" --log="/var/log/
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ghost boot"
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Ghost boot"
#=================================================
# RELOAD NGINX

View file

@ -1,137 +0,0 @@
#!/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
}