2020-11-11 11:47:10 +01:00
---
title: App helpers
template: docs
taxonomy:
category: docs
2021-02-06 18:22:00 +01:00
routes:
default: '/packaging_apps_helpers'
2020-11-11 11:47:10 +01:00
---
2023-01-10 14:27:48 +01:00
Doc auto-generated by [this script ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/doc/generate_helper_doc.py ) on 01/10/2023 (YunoHost version 11.1.2.1)
2022-08-05 12:05:55 +02:00
2022-08-08 18:48:32 +02:00
## APPS
#### ynh_install_apps
[details summary="< i > Install others YunoHost apps< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_install_apps --apps="appfoo?domain=domain.foo&path=/foo appbar?domain=domain.bar&path=/bar&admin=USER&language=fr&is_public=1&pass?word=pass&port=666"`
**Arguments**:
- `-a` , `--apps=` : apps to install
**Details**:< br / >
Requires YunoHost version *.* .* or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apps#L9 )
2022-08-08 18:48:32 +02:00
[/details]
----------------
#### ynh_remove_apps
[details summary="< i > Remove other YunoHost apps< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_remove_apps`
**Details**:< br / >
Other YunoHost apps will be removed only if no other apps need them.
Requires YunoHost version *.* .* or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apps#L65 )
2022-08-08 18:48:32 +02:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## APT
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_is_installed
2021-02-07 15:50:29 +01:00
[details summary="< i > Check either a package is installed or not< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_is_installed --package=name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--package=` : the package name to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the package is installed, 1 else.
**Example**: `ynh_package_is_installed --package=yunohost && echo "installed"`
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L53 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_version
2021-02-07 15:50:29 +01:00
[details summary="< i > Get the version of an installed package< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_version --package=name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--package=` : the package name to get version
**Returns**: the version or an empty string
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `version=$(ynh_package_version --package=yunohost)`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L75 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_update
2021-02-07 15:50:29 +01:00
[details summary="< i > Update package index files< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_update`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L107 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_install
2021-02-07 15:50:29 +01:00
[details summary="< i > Install package(s)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_install name [name [...]]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name` : the package name to install
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L117 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_remove
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove package(s)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_remove name [name [...]]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name` : the package name to remove
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L128 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_autoremove
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove package(s) and their uneeded dependencies< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_autoremove name [name [...]]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name` : the package name to remove
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L138 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_package_autopurge
2021-02-07 15:50:29 +01:00
[details summary="< i > Purge package(s) and their uneeded dependencies< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_autopurge name [name [...]]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name` : the package name to autoremove and purge
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L148 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_install_app_dependencies
2021-02-07 15:50:29 +01:00
[details summary="< i > Define and install dependencies with a equivs control file< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_install_app_dependencies dep [dep [...]]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `dep` : the package name to install in dependence.
- `"dep1|dep2|…"` : You can specify alternatives. It will require to install (dep1 or dep2, etc).
**Details**:< br / >
This helper can/should only be called once per app
example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
Requires YunoHost version 2.6.4 or higher.
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L225 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_add_app_dependencies
2021-02-07 15:50:29 +01:00
[details summary="< i > Add dependencies to install with ynh_install_app_dependencies< / i > " class="helper-card-subtitle text-muted"]
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_add_app_dependencies --package=phpversion [--replace]`
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--package=` : Packages to add as dependencies for the app.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.8.1 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L335 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_app_dependencies
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove fake package and its dependencies< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_app_dependencies`
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Dependencies will removed only if no other package need them.
Requires YunoHost version 2.6.4 or higher.
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L354 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_install_extra_app_dependencies
2021-02-07 15:50:29 +01:00
[details summary="< i > Install packages from an extra repository properly.< / i > " class="helper-card-subtitle text-muted"]
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name]`
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-r` , `--repo=` : Complete url of the extra repository.
- `-p` , `--package=` : The packages to install from this extra repository
- `-k` , `--key=` : url to get the public key.
- `-n` , `--name=` : Name for the files for this repo, $app as default value.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.8.1 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/apt#L382 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## BACKUP
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_backup
2021-02-07 15:50:29 +01:00
[details summary="< i > Add a file or a directory to the list of paths to backup< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup --src_path=src_path [--dest_path=dest_path] [--is_big] [--not_mandatory]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s` , `--src_path=` : file or directory to bind or symlink or copy. it shouldn't be in the backup dir.
- `-d` , `--dest_path=` : destination file or directory inside the backup dir
- `-b` , `--is_big` : Indicate data are big (mail, video, image ...)
- `-m` , `--not_mandatory` : Indicate that if the file is missing, the backup can ignore it.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This helper can be used both in a system backup hook, and in an app backup script
`ynh_backup` writes `src_path` and the relative `dest_path` into a CSV file, and it
creates the parent destination directory
If `dest_path` is ended by a slash it complete this path with the basename of `src_path` .
Example in the context of a wordpress app :
```
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
# => This line will be added into CSV file
# "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/etc/nginx/conf.d/$domain.d/$app.conf"
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf"
#Deprecated usages (maintained for retro-compatibility)
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/conf/nginx.conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/conf/"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"
```
How to use `--is_big` :
`--is_big` is used to specify that this part of the backup can be quite huge.
So, you don't want that your package does backup that part during ynh_backup_before_upgrade.
In the same way, an user may doesn't want to backup this big part of the app for
each of his backup. And so handle that part differently.
As this part of your backup may not be done, your restore script has to handle it.
In your restore script, use `--not_mandatory` with `ynh_restore_file`
As well in your remove script, you should not remove those data ! Or an user may end up with
a failed upgrade restoring an app without data anymore !
To have the benefit of `--is_big` while doing a backup, you can whether set the environement
variable `BACKUP_CORE_ONLY` to 1 (`BACKUP_CORE_ONLY=1`) before the backup command. It will affect
only that backup command.
Or set the config `do_not_backup_data` to 1 into the `settings.yml` of the app. This will affect
all backups for this app until the setting is removed.
Requires YunoHost version 2.4.0 or higher.
Requires YunoHost version 3.5.0 or higher for the argument `--not_mandatory`
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L64 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_restore
2021-02-07 15:50:29 +01:00
[details summary="< i > Restore all files that were previously backuped in a core backup script or app backup script< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_restore`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L179 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_restore_file
2021-02-07 15:50:29 +01:00
[details summary="< i > Restore a file or a directory< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_restore_file --origin_path=origin_path [--dest_path=dest_path] [--not_mandatory]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-o` , `--origin_path=` : Path where was located the file or the directory before to be backuped or relative path to $YNH_CWD where it is located in the backup archive
2021-05-10 19:13:19 +02:00
- `-d` , `--dest_path=` : Path where restore the file or the dir. If unspecified, the destination will be `ORIGIN_PATH` or if the `ORIGIN_PATH` doesn't exist in the archive, the destination will be searched into `backup.csv`
2021-02-07 15:50:29 +01:00
- `-m` , `--not_mandatory` : Indicate that if the file is missing, the restore process can ignore it.
2021-05-10 19:13:19 +02:00
**Examples**:
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
- ` ynh_restore_file -o "/etc/nginx/conf.d/$domain.d/$app.conf"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
- `You can also use relative paths:`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
- ` ynh_restore_file -o "conf/nginx.conf"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Use the registered path in backup_list by ynh_backup to restore the file at the right place.
If `DEST_PATH` already exists and is lighter than 500 Mo, a backup will be made in
2022-08-08 18:48:32 +02:00
`/var/cache/yunohost/appconfbackup/` . Otherwise, the existing file is removed.
2021-05-10 19:13:19 +02:00
if `apps/$app/etc/nginx/conf.d/$domain.d/$app.conf` exists, restore it into
`/etc/nginx/conf.d/$domain.d/$app.conf`
if no, search for a match in the csv (eg: conf/nginx.conf) and restore it into
`/etc/nginx/conf.d/$domain.d/$app.conf`
Requires YunoHost version 2.6.4 or higher.
Requires YunoHost version 3.5.0 or higher for the argument --not_mandatory
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L238 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_store_file_checksum
2021-02-07 15:50:29 +01:00
[details summary="< i > Calculate and store a file checksum into the app settings< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_store_file_checksum --file=file`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--file=` : The file on which the checksum will performed, then stored.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
$app should be defined when calling this helper
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L306 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_backup_if_checksum_is_different
2021-02-07 15:50:29 +01:00
[details summary="< i > Verify the checksum and backup the file if it's different< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup_if_checksum_is_different --file=file`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--file=` : The file on which the checksum test will be perfomed.
**Returns**: the name of a backup file, or nothing
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This helper is primarily meant to allow to easily backup personalised/manually
modified config files.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 2.6.4 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L350 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_delete_file_checksum
2021-02-07 15:50:29 +01:00
[details summary="< i > Delete a file checksum from the app settings< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_delete_file_checksum --file=file`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--file=` : The file for which the checksum will be deleted
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
$app should be defined when calling this helper
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.3.1 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L381 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_backup_before_upgrade
2021-02-07 15:50:29 +01:00
[details summary="< i > Make a backup in case of failed upgrade< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_backup_before_upgrade`
**Details**:< br / >
Usage in a package script:
```
ynh_backup_before_upgrade
2020-05-21 01:22:39 +02:00
ynh_clean_setup () {
ynh_restore_upgradebackup
}
2021-05-10 19:13:19 +02:00
ynh_abort_if_errors
```
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L416 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_restore_upgradebackup
2021-02-07 15:50:29 +01:00
[details summary="< i > Restore a previous backup if the upgrade process failed< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_restore_upgradebackup`
**Details**:< br / >
Usage in a package script:
```
ynh_backup_before_upgrade
2020-05-21 01:22:39 +02:00
ynh_clean_setup () {
ynh_restore_upgradebackup
}
2021-05-10 19:13:19 +02:00
ynh_abort_if_errors
```
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/backup#L464 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
## CONFIG
2021-09-17 14:43:33 +02:00
## FAIL2BAN
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_add_fail2ban_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a dedicated fail2ban config (jail and filter conf files)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `1: ynh_add_fail2ban_config --logpath=log_file --failregex=filter [--max_retry=max_retry] [--ports=ports]
2022-08-08 18:48:32 +02:00
2: ynh_add_fail2ban_config --use_template`
2021-02-07 15:50:29 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l` , `--logpath=` : Log file to be checked by fail2ban
- `-r` , `--failregex=` : Failregex to be looked for by fail2ban
- `-m` , `--max_retry=` : Maximum number of retries allowed before banning IP address - default: 3
- `-p` , `--ports=` : Ports blocked for a banned IP address - default: http,https
- `-t` , `--use_template` : Use this helper in template mode
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
-----------------------------------------------------------------------------
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
This will use a template in `../conf/f2b_jail.conf` and `../conf/f2b_filter.conf`
See the documentation of `ynh_add_config` for a description of the template
format and how placeholders are replaced with actual variables.
Generally your template will look like that by example (for synapse):
```
f2b_jail.conf:
[__APP__]
enabled = true
port = http,https
filter = __APP__
logpath = /var/log/__APP__/logfile.log
maxretry = 3
```
```
f2b_filter.conf:
[INCLUDES]
before = common.conf
[Definition]
# Part of regex definition (just used to make more easy to make the global regex)
__synapse_start_line = .? \- synapse\..+ \-
# Regex definition.
failregex = ^%(__synapse_start_line)s INFO \- POST\-(\d+)\- < HOST > \- \d+ \- Received request\: POST /_matrix/client/r0/login\??< SKIPLINES > %(__synapse_start_line)s INFO \- POST\-\1\- Got login request with identifier: \{u'type': u'm.id.user', u'user'\: u'(.+?)'\}, medium\: None, address: None, user\: u'\5'< SKIPLINES > %(__synapse_start_line)s WARNING \- \- (Attempted to login as @\5\:.+ but they do not exist|Failed password login for user @\5\:.+)$
ignoreregex =
```
-----------------------------------------------------------------------------
Note about the "failregex" option:
regex to match the password failure messages in the logfile. The host must be
matched by a group named "`host`". The tag "`< HOST > `" can be used for standard
IP/hostname matching and is only an alias for `(?:::f{4,6}:)?(?P<host>[\w\-.^_]+)`
You can find some more explainations about how to make a regex here :
https://www.fail2ban.org/wiki/index.php/MANUAL_0_8#Filters
Note that the logfile need to exist before to call this helper !!
To validate your regex you can test with this command:
```
fail2ban-regex /var/log/YOUR_LOG_FILE_PATH /etc/fail2ban/filter.d/YOUR_APP.conf
```
2021-06-11 20:35:28 +02:00
Requires YunoHost version 4.1.0 or higher.
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/fail2ban#L64 )
2021-05-10 19:13:19 +02:00
[/details]
2021-02-07 15:50:29 +01:00
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_fail2ban_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the dedicated fail2ban config (jail and filter conf files)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_fail2ban_config`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/fail2ban#L119 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## GETOPTS
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## HARDWARE
2020-05-21 01:22:39 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_get_ram
2021-02-07 15:50:29 +01:00
[details summary="< i > Get the total or free amount of RAM+swap on the system< / i > " class="helper-card-subtitle text-muted"]
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_get_ram [--free|--total] [--ignore_swap|--only_swap]`
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--free` : Count free RAM+swap
- `-t` , `--total` : Count total RAM+swap
- `-s` , `--ignore_swap` : Ignore swap, consider only real RAM
- `-o` , `--only_swap` : Ignore real RAM, consider only swap
2021-05-10 19:13:19 +02:00
**Returns**: the amount of free ram, in MB (MegaBytes)
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.8.1 or higher.
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/hardware#L13 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_require_ram
2021-02-07 15:50:29 +01:00
[details summary="< i > Return 0 or 1 depending if the system has a given amount of RAM+swap free or total< / i > " class="helper-card-subtitle text-muted"]
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_require_ram --required=RAM [--free|--total] [--ignore_swap|--only_swap]`
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-r` , `--required=` : The amount to require, in MB
2021-02-07 15:50:29 +01:00
- `-f` , `--free` : Count free RAM+swap
- `-t` , `--total` : Count total RAM+swap
- `-s` , `--ignore_swap` : Ignore swap, consider only real RAM
- `-o` , `--only_swap` : Ignore real RAM, consider only swap
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 1 if the ram is under the requirement, 0 otherwise.
**Details**:< br / >
Requires YunoHost version 3.8.1 or higher.
2020-05-21 01:22:39 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/hardware#L75 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-09-17 14:43:33 +02:00
## LOGGING
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_die
2021-02-07 15:50:29 +01:00
[details summary="< i > Print a message to stderr and exit< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_die --message=MSG [--ret_code=RETCODE]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--message=` : Message to display
- `-c` , `--ret_code=` : Exit code to exit with
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.4.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L10 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_print_info
2021-02-07 15:50:29 +01:00
[details summary="< i > Display a message in the 'INFO' logging category< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_info --message="Some message"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--message=` : Message to display
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L30 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_print_warn
2021-02-07 15:50:29 +01:00
[details summary="< i > Print a warning on stderr< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_warn --message="Text to print"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--message=` : The text to print
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L56 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_print_err
2021-02-07 15:50:29 +01:00
[details summary="< i > Print an error on stderr< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_err --message="Text to print"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--message=` : The text to print
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L73 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_err
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command and print the result as an error< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
**Usage**: `ynh_exec_err your command and args`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command` : command to execute
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
2021-11-05 14:05:24 +01:00
Note that you should NOT quote the command but only prefix it with ynh_exec_err
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L92 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_warn
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command and print the result as a warning< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
**Usage**: `ynh_exec_warn your command and args`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command` : command to execute
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
2021-11-05 14:05:24 +01:00
Note that you should NOT quote the command but only prefix it with ynh_exec_warn
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L113 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_warn_less
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command and force the result to be printed on stdout< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
**Usage**: `ynh_exec_warn_less your command and args`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command` : command to execute
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
2021-11-05 14:05:24 +01:00
Note that you should NOT quote the command but only prefix it with ynh_exec_warn
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.2.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L134 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_quiet
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command and redirect stdout in /dev/null< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
**Usage**: `ynh_exec_quiet your command and args`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command` : command to execute
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
2021-11-05 14:05:24 +01:00
Note that you should NOT quote the command but only prefix it with ynh_exec_warn
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.2.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L155 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_fully_quiet
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command and redirect stdout and stderr in /dev/null< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-11-05 14:05:24 +01:00
**Usage**: `ynh_exec_quiet your command and args`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command` : command to execute
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
2021-11-05 14:05:24 +01:00
Note that you should NOT quote the command but only prefix it with ynh_exec_quiet
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.2.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L176 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_script_progression
2021-02-07 15:50:29 +01:00
[details summary="< i > Print a progress bar showing the progression of an app script< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_script_progression --message=message [--weight=weight] [--time]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--message=` : The text to print
- `-w` , `--weight=` : The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
- `-t` , `--time` : Print the execution time since the last call to this helper. Especially usefull to define weights. The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
- `-l` , `--last` : Use for the last call of the helper, to fill the progression bar.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L237 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_return
2021-06-11 20:35:28 +02:00
[details summary="< i > Return data to the YunoHost core for later processing
2021-02-07 15:50:29 +01:00
(to be used by special hooks like app config panel and core diagnosis)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_return somedata`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.6.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logging#L325 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## LOGROTATE
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_use_logrotate
2021-02-07 15:50:29 +01:00
[details summary="< i > Use logrotate to manage the logfile< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_use_logrotate [--logfile=/log/file] [--nonappend] [--specific_user=user/group]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l` , `--logfile=` : absolute path of logfile
- `-n` , `--nonappend` : (optional) Replace the config file instead of appending this new config.
- `-u` , `--specific_user=` : run logrotate as the specified user and group. If not specified logrotate is runned as root.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
If no `--logfile` is provided, `/var/log/$app` will be used as default.
`logfile` can point to a directory or a file.
It's possible to use this helper multiple times, each config will be added to
the same logrotate config file. Unless you use the option `--non-append`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 2.6.4 or higher.
Requires YunoHost version 3.2.0 or higher for the argument `--specific_user`
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logrotate#L18 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_logrotate
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the app's logrotate config.< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_logrotate`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/logrotate#L109 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## MULTIMEDIA
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_multimedia_build_main_dir
2021-05-10 19:13:19 +02:00
[details summary="< i > Initialize the multimedia directory system< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_multimedia_build_main_dir`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 4.2 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/multimedia#L11 )
2021-05-10 19:13:19 +02:00
[/details]
----------------
2021-09-17 14:43:33 +02:00
#### ynh_multimedia_addfolder
2021-05-10 19:13:19 +02:00
[details summary="< i > Add a directory in yunohost.multimedia< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_multimedia_addfolder --source_dir="source_dir" --dest_dir="dest_dir"`
**Arguments**:
- `-s` , `--source_dir=` : Source directory - The real directory which contains your medias.
- `-d` , `--dest_dir=` : Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
**Details**:< br / >
This "directory" will be a symbolic link to a existing directory.
Requires YunoHost version 4.2 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/multimedia#L64 )
2021-05-10 19:13:19 +02:00
[/details]
----------------
2021-09-17 14:43:33 +02:00
#### ynh_multimedia_addaccess
2021-05-10 19:13:19 +02:00
[details summary="< i > Allow an user to have an write authorisation in multimedia directories< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_multimedia_addaccess user_name`
**Arguments**:
- `-u` , `--user_name=` : The name of the user which gain this access.
**Details**:< br / >
Requires YunoHost version 4.2 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/multimedia#L93 )
2021-05-10 19:13:19 +02:00
[/details]
----------------
2021-09-17 14:43:33 +02:00
## MYSQL
2021-05-10 19:13:19 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_connect_as
2021-05-10 19:13:19 +02:00
[details summary="< i > Open a connection as a user< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_mysql_connect_as --user=user --password=password [--database=database]`
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--user=` : the user name to connect as
- `-p` , `--password=` : the user password
- `-d` , `--database=` : the database to connect to
2021-05-10 19:13:19 +02:00
**Examples**:
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
- ` ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
- ` ynh_mysql_connect_as --user="user" --password="pass" < /path/to/file.sql`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L15 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_execute_as_root
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command as root user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_execute_as_root --sql=sql [--database=database]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s` , `--sql=` : the SQL command to execute
- `-d` , `--database=` : the database to connect to
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L36 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_execute_file_as_root
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command from a file as root user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_execute_file_as_root --file=file [--database=database]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--file=` : the file containing SQL commands
- `-d` , `--database=` : the database to connect to
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L60 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_dump_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Dump a database< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_dump_db --database=database`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d` , `--database=` : the database name to dump
2021-05-10 19:13:19 +02:00
**Returns**: The mysqldump output
2021-02-07 15:50:29 +01:00
**Example**: `ynh_mysql_dump_db --database=roundcube > ./dump.sql`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L128 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_user_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a mysql user exists< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_mysql_user_exists --user=user`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--user=` : the user for which to check existence
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the user exists, 1 otherwise.
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L160 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_setup_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a database, an user and its password. Then store the password in the app's config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--db_user=` : Owner of the database
- `-n` , `--db_name=` : Name of the database
- `-p` , `--db_pwd=` : Password of the database. If not provided, a password will be generated
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
After executing this helper, the password of the created database will be available in `$db_pwd`
It will also be stored as "`mysqlpwd`" into the app settings.
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L198 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_mysql_remove_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove a database if it exists, and the associated user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_remove_db --db_user=user --db_name=name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--db_user=` : Owner of the database
- `-n` , `--db_name=` : Name of the database
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/mysql#L224 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## NETWORK
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_find_port
2021-02-07 15:50:29 +01:00
[details summary="< i > Find a free port and return it< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_find_port --port=begin_port`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--port=` : port to start to search
**Returns**: the port number
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `port=$(ynh_find_port --port=8080)`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/network#L12 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_port_available
2021-02-07 15:50:29 +01:00
[details summary="< i > Test if a port is available< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_find_port --port=XYZ`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--port=` : port to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the port is available, 1 if it is already used by another process.
**Example**: `ynh_port_available --port=1234 || ynh_die --message="Port 1234 is needs to be available for this app"`
**Details**:< br / >
Requires YunoHost version 3.8.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/network#L36 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_validate_ip4
2021-02-07 15:50:29 +01:00
[details summary="< i > Validate an IPv4 address< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_validate_ip4 --ip_address=ip_address`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-i` , `--ip_address=` : the ipv4 address to check
**Returns**: 0 for valid ipv4 addresses, 1 otherwise
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_validate_ip4 111.222.333.444`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/network#L99 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_validate_ip6
2021-02-07 15:50:29 +01:00
[details summary="< i > Validate an IPv6 address< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_validate_ip6 --ip_address=ip_address`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-i` , `--ip_address=` : the ipv6 address to check
**Returns**: 0 for valid ipv6 addresses, 1 otherwise
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_validate_ip6 2000:dead:beef::1`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/network#L119 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## NGINX
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_add_nginx_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a dedicated nginx config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_add_nginx_config`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This will use a template in `../conf/nginx.conf`
See the documentation of `ynh_add_config` for a description of the template
format and how placeholders are replaced with actual variables.
Additionally, ynh_add_nginx_config will replace:
- `#sub_path_only` by empty string if `path_url` is not `'/'`
- `#root_path_only` by empty string if `path_url` *is* `'/'`
This allows to enable/disable specific behaviors dependenging on the install
location
2021-06-11 20:35:28 +02:00
Requires YunoHost version 4.1.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/nginx#L19 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_nginx_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the dedicated nginx config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_nginx_config`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/nginx#L41 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## NODEJS
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_use_nodejs
2021-02-07 15:50:29 +01:00
[details summary="< i > Load the version of node for an app, and set variables.< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_use_nodejs`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
`ynh_use_nodejs` has to be used in any app scripts before using node for the first time.
This helper will provide alias and variables to use in your scripts.
To use npm or node, use the alias `ynh_npm` and `ynh_node` .
Those alias will use the correct version installed for the app.
For example: use `ynh_npm install` instead of `npm install`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
With `sudo` or `ynh_exec_as` , use instead the fallback variables `$ynh_npm` and `$ynh_node`
And propagate $PATH to sudo with $ynh_node_load_PATH
Exemple: `ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install`
$PATH contains the path of the requested version of node.
However, $PATH is duplicated into $node_PATH to outlast any manipulation of `$PATH`
You can use the variable `$ynh_node_load_PATH` to quickly load your node version
in $PATH for an usage into a separate script.
Exemple: $ynh_node_load_PATH $final_path/script_that_use_npm.sh`
Finally, to start a nodejs service with the correct version, 2 solutions
Either the app is dependent of node or npm, but does not called it directly.
In such situation, you need to load PATH :
```
Environment="__NODE_ENV_PATH__"
ExecStart=__FINALPATH__/my_app
```
You will replace __NODE_ENV_PATH__ with $ynh_node_load_PATH.
Or node start the app directly, then you don't need to load the PATH variable
```
ExecStart=__YNH_NODE__ my_app run
```
You will replace __YNH_NODE__ with $ynh_node
2 other variables are also available
- $nodejs_path: The absolute path to node binaries for the chosen version.
- $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml.
Requires YunoHost version 2.7.12 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/nodejs#L74 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_install_nodejs
2021-02-07 15:50:29 +01:00
[details summary="< i > Install a specific version of nodejs< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_install_nodejs --nodejs_version=nodejs_version`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-n` , `--nodejs_version=` : Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
ynh_install_nodejs will install the version of node provided as argument by using n.
`n` (Node version management) uses the `PATH` variable to store the path of the version of node it is going to use.
That's how it changes the version
Refer to `ynh_use_nodejs` for more information about available commands and variables
Requires YunoHost version 2.7.12 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/nodejs#L114 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_nodejs
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the version of node used by the app.< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_nodejs`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This helper will check if another app uses the same version of node.
- If not, this version of node will be removed.
- If no other app uses node, n will be also removed.
Requires YunoHost version 2.7.12 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/nodejs#L191 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## PERMISSION
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_create
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a new permission for the app< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_create --permission="permission" [--url="url"] [--additional_urls="second-url" [ "third-url" ]] [--auth_header=true|false]
2021-01-08 03:53:37 +01:00
[--allowed=group1 [ group2 ]] [--label="label"] [--show_tile=true|false]
2021-05-10 19:13:19 +02:00
[--protected=true|false]`
2021-02-07 15:50:29 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-p` , `--permission=` : the name for the permission (by default a permission named "main" already exist)
- `-u` , `--url=` : (optional) URL for which access will be allowed/forbidden. Note that if 'show_tile' is enabled, this URL will be the URL of the tile.
- `-A` , `--additional_urls=` : (optional) List of additional URL for which access will be allowed/forbidden
- `-h` , `--auth_header=` : (optional) Define for the URL of this permission, if SSOwat pass the authentication header to the application. Default is true
- `-a` , `--allowed=` : (optional) A list of group/user to allow for the permission
- `-l` , `--label=` : (optional) Define a name for the permission. This label will be shown on the SSO and in the admin. Default is "APP_LABEL (permission name)".
- `-t` , `--show_tile=` : (optional) Define if a tile will be shown in the SSO. If yes the name of the tile will be the 'label' parameter. Defaults to false for the permission different than 'main'.
- `-P` , `--protected=` : (optional) Define if this permission is protected. If it is protected the administrator won't be able to add or remove the visitors group of this permission. Defaults to 'false'.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Example 1: `ynh_permission_create --permission=admin --url=/admin --additional_urls=domain.tld/admin /superadmin --allowed=alice bob \
--label="My app admin" --show_tile=true`
This example will create a new permission permission with this following effect:
- A tile named "My app admin" in the SSO will be available for the users alice and bob. This tile will point to the relative url '/admin'.
- Only the user alice and bob will have the access to theses following url: /admin, domain.tld/admin, /superadmin
Example 2:
ynh_permission_create --permission=api --url=domain.tld/api --auth_header=false --allowed=visitors \
--label="MyApp API" --protected=true
This example will create a new protected permission. So the admin won't be able to add/remove the visitors group of this permission.
In case of an API with need to be always public it avoid that the admin break anything.
With this permission all client will be allowed to access to the url 'domain.tld/api'.
Note that in this case no tile will be show on the SSO.
Note that the auth_header parameter is to 'false'. So no authentication header will be passed to the application.
Generally the API is requested by an application and enabling the auth_header has no advantage and could bring some issues in some case.
So in this case it's better to disable this option for all API.
If provided, 'url' or 'additional_urls' is assumed to be relative to the app domain/path if they
start with '/'. For example:
/ -> domain.tld/app
/admin -> domain.tld/app/admin
domain.tld/app/api -> domain.tld/app/api
'url' or 'additional_urls' can be treated as a PCRE (not lua) regex if it starts with "re:".
For example:
re:/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$
re:domain.tld/app/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$
Note that globally the parameter 'url' and 'additional_urls' are same. The only difference is:
- 'url' is only one url, 'additional_urls' can be a list of urls. There are no limitation of 'additional_urls'
- 'url' is used for the url of tile in the SSO (if enabled with the 'show_tile' parameter)
About the authentication header (auth_header parameter).
The SSO pass (by default) to the application theses following HTTP header (linked to the authenticated user) to the application:
- "Auth-User": username
- "Remote-User": username
- "Email": user email
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Generally this feature is usefull to authenticate automatically the user in the application but in some case the application don't work with theses header and theses header need to be disabled to have the application to work correctly.
See https://github.com/YunoHost/issues/issues/1420 for more informations
Requires YunoHost version 3.7.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L66 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_delete
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove a permission for the app (note that when the app is removed all permission is automatically removed)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_delete --permission="permission"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--permission=` : the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_permission_delete --permission=editors`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.7.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L152 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a permission exists< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_exists --permission=permission
| exit: Return 1 if the permission doesn't exist, 0 otherwise`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--permission=` : the permission to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.7.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L169 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_url
2021-02-07 15:50:29 +01:00
[details summary="< i > Redefine the url associated to a permission< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_url --permission "permission" [--url="url"] [--add_url="new-url" [ "other-new-url" ]] [--remove_url="old-url" [ "other-old-url" ]]
2021-05-10 19:13:19 +02:00
[--auth_header=true|false] [--clear_urls]`
2021-02-07 15:50:29 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-p` , `--permission=` : the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
- `-u` , `--url=` : (optional) URL for which access will be allowed/forbidden. Note that if you want to remove url you can pass an empty sting as arguments ("").
- `-a` , `--add_url=` : (optional) List of additional url to add for which access will be allowed/forbidden.
- `-r` , `--remove_url=` : (optional) List of additional url to remove for which access will be allowed/forbidden
- `-h` , `--auth_header=` : (optional) Define for the URL of this permission, if SSOwat pass the authentication header to the application
- `-c` , `--clear_urls` : (optional) Clean all urls (url and additional_urls)
**Details**:< br / >
Requires YunoHost version 3.7.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L192 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_update
2021-02-07 15:50:29 +01:00
[details summary="< i > Update a permission for the app< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_update --permission "permission" [--add="group" ["group" ...]] [--remove="group" ["group" ...]]
2021-05-10 19:13:19 +02:00
[--label="label"] [--show_tile=true|false] [--protected=true|false]`
2021-02-07 15:50:29 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-p` , `--permission=` : the name for the permission (by default a permission named "main" already exist)
- `-a` , `--add=` : the list of group or users to enable add to the permission
- `-r` , `--remove=` : the list of group or users to remove from the permission
- `-l` , `--label=` : (optional) Define a name for the permission. This label will be shown on the SSO and in the admin.
- `-t` , `--show_tile=` : (optional) Define if a tile will be shown in the SSO
- `-P` , `--protected=` : (optional) Define if this permission is protected. If it is protected the administrator won't be able to add or remove the visitors group of this permission.
**Details**:< br / >
Requires YunoHost version 3.7.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L260 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_permission_has_user
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a permission has an user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_has_user --permission=permission --user=user
| exit: Return 1 if the permission doesn't have that user or doesn't exist, 0 otherwise`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p` , `--permission=` : the permission to check
- `-u` , `--user=` : the user seek in the permission
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_permission_has_user --permission=main --user=visitors`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.7.1 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L329 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_legacy_permissions_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a legacy permissions exist< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_legacy_permissions_exists
| exit: Return 1 if the permission doesn't exist, 0 otherwise`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 4.1.2 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L359 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_legacy_permissions_delete_all
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove all legacy permissions< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_legacy_permissions_delete_all`
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `if ynh_legacy_permissions_exists then ynh_legacy_permissions_delete_all # You can recreate the required permissions here with ynh_permission_create fi Requires YunoHost version 4.1.2 or higher.`
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/permission#L379 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
## PHP
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_add_fpm_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a dedicated PHP-FPM config< / i > " class="helper-card-subtitle text-muted"]
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `1: ynh_add_fpm_config [--phpversion=7.X] [--use_template] [--package=packages] [--dedicated_service]
2021-01-08 03:53:37 +01:00
2: ynh_add_fpm_config [--phpversion=7.X] --usage=usage --footprint=footprint [--package=packages] [--dedicated_service]
low - Less than 20 MB of RAM by pool.
medium - Between 20 MB and 40 MB of RAM by pool.
high - More than 40 MB of RAM by pool.
Or specify exactly the footprint, the load of the service as MB by pool instead of having a standard value.
To have this value, use the following command and stress the service.
2021-02-07 15:50:29 +01:00
watch -n0.5 ps -o user,cmd,%cpu,rss -u APP`
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-v` , `--phpversion=` : Version of PHP to use.
- `-t` , `--use_template` : Use this helper in template mode.
- `-p` , `--package=` : Additionnal PHP packages to install
- `-d` , `--dedicated_service` : Use a dedicated PHP-FPM service instead of the common one.
- `-v` , `--phpversion=` : Version of PHP to use.
- `-f` , `--footprint=` : Memory footprint of the service (low/medium/high).
- `-u` , `--usage=` : Expected usage of the service (low/medium/high).
- `-p` , `--package=` : Additionnal PHP packages to install for a specific version of PHP
- `-d` , `--dedicated_service` : Use a dedicated PHP-FPM service instead of the common one.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
-----------------------------------------------------------------------------
The footprint of the service will be used to defined the maximum footprint we can allow, which is half the maximum RAM.
So it will be used to defined 'pm.max_children'
A lower value for the footprint will allow more children for 'pm.max_children'. And so for
'pm.start_servers', 'pm.min_spare_servers' and 'pm.max_spare_servers' which are defined from the
value of 'pm.max_children'
NOTE: 'pm.max_children' can't exceed 4 times the number of processor's cores.
The usage value will defined the way php will handle the children for the pool.
A value set as 'low' will set the process manager to 'ondemand'. Children will start only if the
service is used, otherwise no child will stay alive. This config gives the lower footprint when the
service is idle. But will use more proc since it has to start a child as soon it's used.
Set as 'medium', the process manager will be at dynamic. If the service is idle, a number of children
equal to pm.min_spare_servers will stay alive. So the service can be quick to answer to any request.
The number of children can grow if needed. The footprint can stay low if the service is idle, but
not null. The impact on the proc is a little bit less than 'ondemand' as there's always a few
children already available.
Set as 'high', the process manager will be set at 'static'. There will be always as many children as
'pm.max_children', the footprint is important (but will be set as maximum a quarter of the maximum
RAM) but the impact on the proc is lower. The service will be quick to answer as there's always many
children ready to answer.
2021-06-11 20:35:28 +02:00
Requires YunoHost version 4.1.0 or higher.
2021-05-10 19:13:19 +02:00
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/php#L59 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_fpm_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the dedicated PHP-FPM config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_fpm_config`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/php#L250 )
2021-05-10 19:13:19 +02:00
[/details]
----------------
2021-09-17 14:43:33 +02:00
#### ynh_composer_exec
2021-05-10 19:13:19 +02:00
[details summary="< i > Execute a command with Composer< / i > " class="helper-card-subtitle text-muted"]
2023-01-06 08:01:32 +01:00
**Usage**: `ynh_composer_exec [--phpversion=phpversion] [--workdir=$install_dir] --commands="commands"`
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-v` , `--phpversion` : PHP version to use with composer
2023-01-06 08:01:32 +01:00
- `-w` , `--workdir` : The directory from where the command will be executed. Default $install_dir or $final_path
2021-05-10 19:13:19 +02:00
- `-c` , `--commands` : Commands to execute.
**Details**:< br / >
Requires YunoHost version 4.2 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/php#L483 )
2021-05-10 19:13:19 +02:00
[/details]
----------------
2021-09-17 14:43:33 +02:00
#### ynh_install_composer
2021-05-10 19:13:19 +02:00
[details summary="< i > Install and initialize Composer in the given directory< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] [--composerversion=composerversion]`
**Arguments**:
- `-v` , `--phpversion` : PHP version to use with composer
- `-w` , `--workdir` : The directory from where the command will be executed. Default $final_path.
- `-a` , `--install_args` : Additional arguments provided to the composer install. Argument --no-dev already include
- `-c` , `--composerversion` : Composer version to install
**Details**:< br / >
Requires YunoHost version 4.2 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/php#L509 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
## POSTGRESQL
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_connect_as
2021-02-07 15:50:29 +01:00
[details summary="< i > Open a connection as a user< / i > " class="helper-card-subtitle text-muted"]
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_connect_as --user=user --password=password [--database=database]`
2021-01-08 03:53:37 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--user=` : the user name to connect as
- `-p` , `--password=` : the user password
- `-d` , `--database=` : the database to connect to
2021-05-10 19:13:19 +02:00
**Examples**:
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- ` ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;"`
2021-01-08 03:53:37 +01:00
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
- ` ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql`
2021-01-08 03:53:37 +01:00
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L18 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_execute_as_root
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command as root user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_execute_as_root --sql=sql [--database=database]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s` , `--sql=` : the SQL command to execute
- `-d` , `--database=` : the database to connect to
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L39 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_execute_file_as_root
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command from a file as root user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_execute_file_as_root --file=file [--database=database]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-f` , `--file=` : the file containing SQL commands
- `-d` , `--database=` : the database to connect to
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L64 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_dump_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Dump a database< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_dump_db --database=database`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d` , `--database=` : the database name to dump
**Returns**: the psqldump output
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_psql_dump_db 'roundcube' > ./dump.sql`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L135 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_user_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a psql user exists< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_user_exists --user=user
| exit: Return 1 if the user doesn't exist, 0 otherwise`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--user=` : the user for which to check existence
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L168 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_database_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a psql database exists< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_database_exists --database=database
| exit: Return 1 if the database doesn't exist, 0 otherwise`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d` , `--database=` : the database for which to check existence
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L190 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_setup_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a database, an user and its password. Then store the password in the app's config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--db_user=` : Owner of the database
- `-n` , `--db_name=` : Name of the database
- `-p` , `--db_pwd=` : Password of the database. If not provided, a password will be generated
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
After executing this helper, the password of the created database will be available in $db_pwd
It will also be stored as "psqlpwd" into the app settings.
Requires YunoHost version 2.7.13 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L234 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_psql_remove_db
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove a database if it exists, and the associated user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_remove_db --db_user=user --db_name=name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--db_user=` : Owner of the database
- `-n` , `--db_name=` : Name of the database
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.13 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/postgresql#L265 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
## SETTING
2021-01-08 03:53:37 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_app_setting_get
2021-02-07 15:50:29 +01:00
[details summary="< i > Get an application setting< / i > " class="helper-card-subtitle text-muted"]
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_setting_get --app=app --key=key`
2021-01-08 03:53:37 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-a` , `--app=` : the application id
- `-k` , `--key=` : the setting to get
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/setting#L10 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_app_setting_set
2021-02-07 15:50:29 +01:00
[details summary="< i > Set an application setting< / i > " class="helper-card-subtitle text-muted"]
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_setting_set --app=app --key=key --value=value`
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-a` , `--app=` : the application id
- `-k` , `--key=` : the setting name to set
- `-v` , `--value=` : the setting value to set
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2020-03-30 16:19:47 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/setting#L36 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_app_setting_delete
2021-02-07 15:50:29 +01:00
[details summary="< i > Delete an application setting< / i > " class="helper-card-subtitle text-muted"]
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_setting_delete --app=app --key=key`
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-a` , `--app=` : the application id
- `-k` , `--key=` : the setting to delete
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2020-03-30 16:19:47 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/setting#L62 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_webpath_available
2021-02-07 15:50:29 +01:00
[details summary="< i > Check availability of a web path< / i > " class="helper-card-subtitle text-muted"]
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_webpath_available --domain=domain --path_url=path`
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d` , `--domain=` : the domain/host of the url
- `-p` , `--path_url=` : the web path to check the availability of
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_webpath_available --domain=some.domain.tld --path_url=/coffee`
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/setting#L123 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_webpath_register
2021-02-07 15:50:29 +01:00
[details summary="< i > Register/book a web path for an app< / i > " class="helper-card-subtitle text-muted"]
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_webpath_register --app=app --domain=domain --path_url=path`
2020-03-30 16:19:47 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-a` , `--app=` : the app for which the domain should be registered
- `-d` , `--domain=` : the domain/host of the web path
- `-p` , `--path_url=` : the web path to be registered
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_webpath_register --app=wordpress --domain=some.domain.tld --path_url=/coffee`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/setting#L145 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## STRING
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_string_random
2021-02-07 15:50:29 +01:00
[details summary="< i > Generate a random string< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_string_random [--length=string_length]`
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l` , `--length=` : the string length to generate (default: 24)
2022-08-08 18:48:32 +02:00
- `-f` , `--filter=` : the kind of characters accepted in the output (default: 'A-Za-z0-9')
2021-02-07 15:50:29 +01:00
**Returns**: the generated string
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `pwd=$(ynh_string_random --length=8)`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/string#L13 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_replace_string
2021-02-07 15:50:29 +01:00
[details summary="< i > Substitute/replace a string (or expression) by another in a file< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_replace_string --match_string=match_string --replace_string=replace_string --target_file=target_file`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--match_string=` : String to be searched and replaced in the file
- `-r` , `--replace_string=` : String that will replace matches
- `-f` , `--target_file=` : File in which the string will be replaced.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
As this helper is based on sed command, regular expressions and references to
sub-expressions can be used (see sed manual page for more information)
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/string#L40 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_replace_special_string
2021-02-07 15:50:29 +01:00
[details summary="< i > Substitute/replace a special string by another in a file< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_replace_special_string --match_string=match_string --replace_string=replace_string --target_file=target_file`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--match_string=` : String to be searched and replaced in the file
- `-r` , `--replace_string=` : String that will replace matches
- `-t` , `--target_file=` : File in which the string will be replaced.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This helper will use ynh_replace_string, but as you can use special
characters, you can't use some regular expressions and sub-expressions.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 2.7.7 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/string#L71 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_sanitize_dbid
2021-05-10 19:13:19 +02:00
[details summary="< i > Sanitize a string intended to be the name of a database< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_sanitize_dbid --db_name=name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-n` , `--db_name=` : name to correct/sanitize
**Returns**: the corrected name
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `dbname=$(ynh_sanitize_dbid $app)`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Underscorify the string (replace - and . by _)
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/string#L103 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## SYSTEMD
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_add_systemd_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a dedicated systemd config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_add_systemd_config [--service=service] [--template=template]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-s` , `--service=` : Service name (optionnal, `$app` by default)
- `-t` , `--template=` : Name of template file (optionnal, this is 'systemd' by default, meaning `../conf/systemd.service` will be used as template)
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This will use the template `../conf/<templatename>.service` .
See the documentation of `ynh_add_config` for a description of the template
format and how placeholders are replaced with actual variables.
2021-06-11 20:35:28 +02:00
Requires YunoHost version 4.1.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/systemd#L15 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_remove_systemd_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove the dedicated systemd config< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_systemd_config [--service=service]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s` , `--service=` : Service name (optionnal, $app by default)
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.2 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/systemd#L38 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_systemd_action
2021-02-07 15:50:29 +01:00
[details summary="< i > Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_systemd_action [--service_name=service_name] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `-n` , `--service_name=` : Name of the service to start. Default : `$app`
2021-02-07 15:50:29 +01:00
- `-a` , `--action=` : Action to perform with systemctl. Default: start
2021-05-10 19:13:19 +02:00
- `-l` , `--line_match=` : Line to match - The line to find in the log to attest the service have finished to boot. If not defined it don't wait until the service is completely started.
- `-p` , `--log_path=` : Log file - Path to the log file. Default : `/var/log/$app/$app.log`
2021-02-07 15:50:29 +01:00
- `-t` , `--timeout=` : Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
- `-e` , `--length=` : Length of the error log : Default : 20
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/systemd#L67 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## USER
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_user_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a YunoHost user exists< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_user_exists --username=username`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--username=` : the username to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the user exists, 1 otherwise.
**Example**: `ynh_user_exists 'toto' || echo "User does not exist"`
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L12 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_user_get_info
2021-02-07 15:50:29 +01:00
[details summary="< i > Retrieve a YunoHost user information< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_user_get_info --username=username --key=key`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--username=` : the username to retrieve info from
- `-k` , `--key=` : the key to retrieve
2021-05-10 19:13:19 +02:00
**Returns**: the value associate to that key
2022-08-08 18:48:32 +02:00
**Example**: `mail=$(ynh_user_get_info --username="toto" --key=mail)`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L33 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_user_list
2021-02-07 15:50:29 +01:00
[details summary="< i > Get the list of YunoHost users< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_user_list`
2021-05-10 19:13:19 +02:00
**Returns**: one username per line as strings
**Example**: `for u in $(ynh_user_list); do ... ; done`
**Details**:< br / >
Requires YunoHost version 2.4.0 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L53 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_system_user_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a user exists on the system< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_system_user_exists --username=username`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--username=` : the username to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the user exists, 1 otherwise.
**Details**:< br / >
Requires YunoHost version 2.2.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L64 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_system_group_exists
2021-02-07 15:50:29 +01:00
[details summary="< i > Check if a group exists on the system< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_system_group_exists --group=group`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-g` , `--group=` : the group to check
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the group exists, 1 otherwise.
**Details**:< br / >
Requires YunoHost version 3.5.0.2 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L82 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_system_user_create
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a system user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_system_user_create --username=user_name [--home_dir=home_dir] [--use_shell] [--groups="group1 group2"]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--username=` : Name of the system user that will be create
- `-h` , `--home_dir=` : Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home
- `-s` , `--use_shell` : Create a user using the default login shell if present. If this argument is omitted, the user will be created with /usr/sbin/nologin shell
2021-05-10 19:13:19 +02:00
- `-g` , `--groups` : Add the user to system groups. Typically meant to add the user to the ssh.app / sftp.app group (e.g. for borgserver, my_webapp)
**Details**:< br / >
Create a nextcloud user with no home directory and /usr/sbin/nologin login shell (hence no login capability) :
```
ynh_system_user_create --username=nextcloud
```
Create a discourse user using /var/www/discourse as home directory and the default login shell :
```
ynh_system_user_create --username=discourse --home_dir=/var/www/discourse --use_shell
```
Requires YunoHost version 2.6.4 or higher.
2021-02-07 15:50:29 +01:00
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L111 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_system_user_delete
2021-02-07 15:50:29 +01:00
[details summary="< i > Delete a system user< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_system_user_delete --username=user_name`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u` , `--username=` : Name of the system user that will be create
2021-02-02 05:00:35 +01:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2021-02-02 05:00:35 +01:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L153 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2021-02-02 05:00:35 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_exec_as
2021-02-07 15:50:29 +01:00
[details summary="< i > Execute a command as another user< / i > " class="helper-card-subtitle text-muted"]
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_as $USER COMMAND [ARG ...]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 4.1.7 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/user#L179 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
## UTILS
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_abort_if_errors
2021-02-07 15:50:29 +01:00
[details summary="< i > Exits if an error occurs during the execution of the script.< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_abort_if_errors`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This configure the rest of the script execution such that, if an error occurs
or if an empty variable is used, the execution of the script stops immediately
and a call to `ynh_clean_setup` is triggered if it has been defined by your script.
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L58 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_setup_source
2021-02-07 15:50:29 +01:00
[details summary="< i > Download, check integrity, uncompress and patch the source from app.src< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2022-10-17 17:59:07 +02:00
**Usage**: `ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] [--keep="file1 file2"] [--full_replace]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d` , `--dest_dir=` : Directory where to setup sources
2021-05-10 19:13:19 +02:00
- `-s` , `--source_id=` : Name of the source, defaults to `app`
- `-k` , `--keep=` : Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs/'
2022-10-17 17:59:07 +02:00
- `-r` , `--full_replace=` : Remove previous sources before installing new sources
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
This helper will read `conf/${source_id}.src` , download and install the sources.
The src file need to contains:
```
SOURCE_URL=Address to download the app archive
SOURCE_SUM=Control sum
# (Optional) Program to check the integrity (sha256sum, md5sum...). Default: sha256
SOURCE_SUM_PRG=sha256
# (Optional) Archive format. Default: tar.gz
SOURCE_FORMAT=tar.gz
# (Optional) Put false if sources are directly in the archive root. Default: true
# Instead of true, SOURCE_IN_SUBDIR could be the number of sub directories to remove.
SOURCE_IN_SUBDIR=false
# (Optionnal) Name of the local archive (offline setup support). Default: ${src_id}.${src_format}
SOURCE_FILENAME=example.tar.gz
# (Optional) If it set as false don't extract the source. Default: true
# (Useful to get a debian package or a python wheel.)
SOURCE_EXTRACT=(true|false)
2022-12-03 19:23:04 +01:00
# (Optionnal) Name of the plateform. Default: "linux/$YNH_ARCH"
SOURCE_PLATFORM=linux/arm64/v8
2021-05-10 19:13:19 +02:00
```
The helper will:
- Check if there is a local source archive in `/opt/yunohost-apps-src/$APP_ID/$SOURCE_FILENAME`
- Download `$SOURCE_URL` if there is no local archive
- Check the integrity with `$SOURCE_SUM_PRG -c --status`
- Uncompress the archive to `$dest_dir` .
- If `$SOURCE_IN_SUBDIR` is true, the first level directory of the archive will be removed.
- If `$SOURCE_IN_SUBDIR` is a numeric value, the N first level directories will be removed.
- Patches named `sources/patches/${src_id}-*.patch` will be applied to `$dest_dir`
- Extra files in `sources/extra_files/$src_id` will be copied to dest_dir
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 2.6.4 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L111 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_local_curl
2021-02-07 15:50:29 +01:00
[details summary="< i > Curl abstraction to help with POST requests to local pages (such as installation forms)< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `page_uri` : Path (relative to `$path_url` ) of the page where POST data will be sent
2021-02-07 15:50:29 +01:00
- `key1=value1` : (Optionnal) POST key and corresponding value
- `key2=value2` : (Optionnal) Another POST key and corresponding value
- `...` : (Optionnal) More POST keys and values
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"`
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
For multiple calls, cookies are persisted between each call for the same app
`$domain` and `$path_url` should be defined externally (and correspond to the domain.tld and the /path (of the app?))
Requires YunoHost version 2.6.4 or higher.
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L285 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-12-31 17:30:18 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_add_config
2021-02-07 15:50:29 +01:00
[details summary="< i > Create a dedicated config file from a template< / i > " class="helper-card-subtitle text-muted"]
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_add_config --template="template" --destination="destination"`
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2022-12-03 19:23:04 +01:00
- `-t` , `--template=` : Template config file to use
2021-02-07 15:50:29 +01:00
- `-d` , `--destination=` : Destination of the config file
2021-05-10 19:13:19 +02:00
**Examples**:
2020-12-31 17:30:18 +01:00
2023-01-06 08:01:32 +01:00
- ` ynh_add_config --template=".env" --destination="$install_dir/.env" use the template file "../conf/.env"`
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
2021-02-07 15:50:29 +01:00
- ` ynh_add_config --template="/etc/nginx/sites-available/default" --destination="etc/nginx/sites-available/mydomain.conf"`
2020-12-31 17:30:18 +01:00
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
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.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
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
__YNH_NODE_LOAD_PATH__ by $ynh_node_load_PATH
```
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.
Requires YunoHost version 4.1.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L369 )
2021-11-05 14:05:24 +01:00
[/details]
----------------
#### ynh_read_var_in_file
[details summary="< i > Get a value from heterogeneous file (yaml, json, php, python...)< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_read_var_in_file --file=PATH --key=KEY`
**Arguments**:
- `-f` , `--file=` : the path to the file
- `-k` , `--key=` : the key to get
**Details**:< br / >
This helpers match several var affectation use case in several languages
We don't use jq or equivalent to keep comments and blank space in files
This helpers work line by line, it is not able to work correctly
if you have several identical keys in your files
Example of line this helpers can managed correctly
.yml
title: YunoHost documentation
email: 'yunohost@yunohost.org'
.json
"theme": "colib'ris",
"port": 8102
"some_boolean": false,
"user": null
.ini
some_boolean = On
action = "Clear"
port = 20
.php
$user=
user => 20
.py
USER = 8102
user = 'https://donate.local'
CUSTOM['user'] = 'YunoHost'
Requires YunoHost version 4.3 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L522 )
2021-11-05 14:05:24 +01:00
[/details]
----------------
#### ynh_write_var_in_file
[details summary="< i > Set a value into heterogeneous file (yaml, json, php, python...)< / i > " class="helper-card-subtitle text-muted"]
**Usage**: `ynh_write_var_in_file --file=PATH --key=KEY --value=VALUE`
**Arguments**:
- `-f` , `--file=` : the path to the file
- `-k` , `--key=` : the key to set
- `-v` , `--value=` : the value to set
**Details**:< br / >
Requires YunoHost version 4.3 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L599 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_get_debian_release
2021-02-07 15:50:29 +01:00
[details summary="< i > Fetch the Debian release codename< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_get_debian_release`
**Returns**: The Debian release codename (i.e. jessie, stretch, ...)
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.7.12 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L711 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_secure_remove
2021-02-07 15:50:29 +01:00
[details summary="< i > Remove a file or a directory securely< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_secure_remove --file=path_to_remove`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f` , `--file=` : File or directory to remove
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 2.6.4 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L742 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_read_manifest
2021-02-07 15:50:29 +01:00
[details summary="< i > Read the value of a key in a ynh manifest file< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_read_manifest --manifest="manifest.json" --key="key"`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--manifest=` : Path of the manifest to read
- `-k` , `--key=` : Name of the key to find
**Returns**: the value associate to that key
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L776 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_app_upstream_version
2021-05-10 19:13:19 +02:00
[details summary="< i > Read the upstream version from the manifest or `$YNH_APP_MANIFEST_VERSION` </ i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_upstream_version [--manifest="manifest.json"]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--manifest=` : Path of the manifest to read
**Returns**: the version number of the upstream app
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
If the `manifest` is not specified, the envvar `$YNH_APP_MANIFEST_VERSION` will be used.
The version number in the manifest is defined by `<upstreamversion>~ynh<packageversion>` .
For example, if the manifest contains `4.3-2~ynh3` the function will return `4.3-2`
Requires YunoHost version 3.5.0 or higher.
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L819 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_app_package_version
2021-02-07 15:50:29 +01:00
[details summary="< i > Read package version from the manifest< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_package_version [--manifest="manifest.json"]`
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m` , `--manifest=` : Path of the manifest to read
**Returns**: the version number of the package
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Details**:< br / >
The version number in the manifest is defined by `<upstreamversion>~ynh<packageversion>` .
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
For example, if the manifest contains `4.3-2~ynh3` the function will return `3`
Requires YunoHost version 3.5.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L848 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2019-07-11 22:04:06 +02:00
2021-09-17 14:43:33 +02:00
#### ynh_check_app_version_changed
2021-02-07 15:50:29 +01:00
[details summary="< i > Checks the app version to upgrade with the existing app version and returns:< / i > " class="helper-card-subtitle text-muted"]
2019-07-11 22:04:06 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_check_app_version_changed`
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
**Returns**: `UPGRADE_APP` if the upstream version changed, `UPGRADE_PACKAGE` otherwise.
**Details**:< br / >
This helper should be used to avoid an upgrade of an app, or the upstream part
of it, when it's not needed
You can force an upgrade, even if the package is up to date, with the `--force` (or `-F` ) argument :
```
sudo yunohost app upgrade < appname > --force
```
Requires YunoHost version 3.5.0 or higher.
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L873 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2020-12-31 17:30:18 +01:00
2021-09-17 14:43:33 +02:00
#### ynh_compare_current_package_version
2021-05-10 19:13:19 +02:00
[details summary="< i > Compare the current package version against another version given as an argument.< / i > " class="helper-card-subtitle text-muted"]
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
**Usage**: `ynh_compare_current_package_version --comparison (lt|le|eq|ne|ge|gt) --version <X~ynhY>`
2020-12-31 17:30:18 +01:00
2021-05-10 19:13:19 +02:00
**Arguments**:
- `--comparison` : Comparison type. Could be : `lt` (lower than), `le` (lower or equal), `eq` (equal), `ne` (not equal), `ge` (greater or equal), `gt` (greater than)
- `--version` : The version to compare. Need to be a version in the yunohost package version type (like `2.3.1~ynh4` )
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
**Returns**: 0 if the evaluation is true, 1 if false.
**Example**: `ynh_compare_current_package_version --comparison lt --version 2.3.2~ynh1`
**Details**:< br / >
This helper is usually used when we need to do some actions only for some old package versions.
Generally you might probably use it as follow in the upgrade script :
```
if ynh_compare_current_package_version --comparison lt --version 2.3.2~ynh1
then
# Do something that is needed for the package version older than 2.3.2~ynh1
fi
```
2019-07-11 22:04:06 +02:00
2021-05-10 19:13:19 +02:00
Requires YunoHost version 3.8.0 or higher.
2023-01-10 14:27:48 +01:00
[Dude, show me the code! ](https://github.com/YunoHost/yunohost/blob/37b424e9680668564c8393c4d56352fbe4747599/helpers/utils#L903 )
2021-02-07 15:50:29 +01:00
[/details]
----------------
2021-11-15 00:42:46 +01:00