doc/pages/04.contribute/04.packaging_apps/11.helpers/packaging_apps_helpers.md

3365 lines
100 KiB
Markdown
Raw Normal View History

2020-11-11 11:47:10 +01:00
---
title: App helpers
template: docs
taxonomy:
category: docs
routes:
default: '/packaging_apps_helpers'
2020-11-11 11:47:10 +01:00
---
2021-02-07 15:50:29 +01:00
Doc auto-generated by [this script](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/doc/generate_helper_doc.py) on 02/07/2021 (Yunohost version 4.1.7)
2021-02-07 15:50:29 +01:00
### APT
2021-02-07 15:50:29 +01:00
**ynh_package_is_installed**
[details summary="<i>Check either a package is installed or not</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_is_installed --package=name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: the package name to check
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_package_is_installed --package=yunohost && echo "ok"`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L56)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_version**
[details summary="<i>Get the version of an installed package</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_version --package=name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: the package name to get version
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: the version or an empty string
2021-02-07 15:50:29 +01:00
**Example**: `version=$(ynh_package_version --package=yunohost)`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L78)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_update**
[details summary="<i>Update package index files</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_update`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L111)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_install**
[details summary="<i>Install package(s)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_install name [name [...]]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name`: the package name to install
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L121)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_remove**
[details summary="<i>Remove package(s)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_remove name [name [...]]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name`: the package name to remove
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L132)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_autoremove**
[details summary="<i>Remove package(s) and their uneeded dependencies</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_autoremove name [name [...]]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name`: the package name to remove
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L142)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_package_autopurge**
[details summary="<i>Purge package(s) and their uneeded dependencies</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_package_autopurge name [name [...]]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `name`: the package name to autoremove and purge
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L152)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_install_app_dependencies**
[details summary="<i>Define and install dependencies with a equivs control file</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_install_app_dependencies dep [dep [...]]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `dep`: the package name to install in dependence. Writing "dep3|dep4|dep5" can be used to specify alternatives. For example : dep1 dep2 "dep3|dep4|dep5" will require to install dep1 and dep 2 and (dep3 or dep4 or dep5).
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
This helper can/should only be called once per app</br></br>example : ynh\_install\_app\_dependencies dep1 dep2 "dep3|dep4|dep5"</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L222)
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**ynh_add_app_dependencies**
[details summary="<i>Add dependencies to install with ynh_install_app_dependencies</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: Packages to add as dependencies for the app.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-r`, `--replace`: Replace dependencies instead of adding to existing ones.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.8.1 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L295)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_app_dependencies**
[details summary="<i>Remove fake package and its dependencies</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_app_dependencies`
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Dependencies will removed only if no other package need them.</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L327)
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**ynh_install_extra_app_dependencies**
[details summary="<i>Install packages from an extra repository properly.</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-r`, `--repo=`: Complete url of the extra repository.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: The packages to install from this extra repository
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: url to get the public key.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-n`, `--name=`: Name for the files for this repo, $app as default value.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.8.1 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/apt#L341)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### BACKUP
2021-02-07 15:50:29 +01:00
**ynh_backup**
[details summary="<i>Add a file or a directory to the list of paths to backup</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup --src_path=src_path [--dest_path=dest_path] [--is_big] [--not_mandatory]`
2021-02-07 15:50:29 +01: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.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--dest_path=`: destination file or directory inside the backup dir
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-b`, `--is_big`: Indicate data are big (mail, video, image ...)
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-m`, `--not_mandatory`: Indicate that if the file is missing, the backup can ignore it.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `arg`: Deprecated arg
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
This helper can be used both in a system backup hook, and in an app backup script</br></br>Details: ynh\_backup writes SRC and the relative DEST into a CSV file. And it</br>creates the parent destination directory</br></br>If DEST is ended by a slash it complete this path with the basename of SRC.</br></br>Example in the context of a wordpress app</br></br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf"</br># => This line will be added into CSV file</br># "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/etc/nginx/conf.d/$domain.d/$app.conf"</br></br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"</br># => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"</br></br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/"</br># => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"</br></br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf"</br># => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf"</br></br>#Deprecated usages (maintained for retro-compatibility)</br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup\_dir}/conf/nginx.conf"</br># => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"</br></br>ynh\_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/conf/"</br># => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"</br></br>How to use --is\_big:</br>--is\_big is used to specify that this part of the backup can be quite huge.</br>So, you don't want that your package does backup that part during ynh\_backup\_before\_upgrade.</br>In the same way, an user may doesn't want to backup this big part of the app for</br> each of his backup. And so handle that part differently.</br></br>As this part of your backup may not be done, your restore script has to handle it.</br>In your restore script, use --not\_mandatory with ynh\_restore\_file</br>As well in your remove script, you should not remove those data ! Or an user may end up with</br> a failed upgrade restoring an app without data anymore !</br></br>To have the benefit of --is\_big while doing a backup, you can whether set the environement</br> variable BACKUP\_CORE\_ONLY to 1 (BACKUP\_CORE\_ONLY=1) before the backup command. It will affect</br> only that backup command.</br>Or set the config do\_not\_backup\_data to 1 into the settings.yml of the app. This will affect</br> all backups for this app until the setting is removed.</br></br>Requires YunoHost version 2.4.0 or higher.</br>Requires YunoHost version 3.5.0 or higher for the argument --not\_mandatory</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L63)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_restore**
[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"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_restore`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L186)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_restore_file**
[details summary="<i>Restore a file or a directory</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_restore_file --origin_path=origin_path [--dest_path=dest_path] [--not_mandatory]`
2021-02-07 15:50:29 +01: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-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01: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
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-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Examples**:
2021-02-07 15:50:29 +01:00
- ` ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"`
2021-02-07 15:50:29 +01:00
- `You can also use relative paths:`
2021-02-07 15:50:29 +01:00
- ` ynh_restore_file "conf/nginx.conf"`
2021-02-07 15:50:29 +01:00
**Details**:
Use the registered path in backup\_list by ynh\_backup to restore the file at</br>the right place.</br></br>If DEST\_PATH already exists and is lighter than 500 Mo, a backup will be made in</br>/home/yunohost.conf/backup/. Otherwise, the existing file is removed.</br></br>if apps/wordpress/etc/nginx/conf.d/$domain.d/$app.conf exists, restore it into</br>/etc/nginx/conf.d/$domain.d/$app.conf</br>if no, search for a match in the csv (eg: conf/nginx.conf) and restore it into</br>/etc/nginx/conf.d/$domain.d/$app.conf</br></br>Requires YunoHost version 2.6.4 or higher.</br>Requires YunoHost version 3.5.0 or higher for the argument --not\_mandatory</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L247)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_store_file_checksum**
[details summary="<i>Calculate and store a file checksum into the app settings</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_store_file_checksum --file=file`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: The file on which the checksum will performed, then stored.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
$app should be defined when calling this helper</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L325)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_backup_if_checksum_is_different**
[details summary="<i>Verify the checksum and backup the file if it's different</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup_if_checksum_is_different --file=file`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: The file on which the checksum test will be perfomed.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: the name of a backup file, or nothing
2021-02-07 15:50:29 +01:00
**Details**:
This helper is primarily meant to allow to easily backup personalised/manually</br>modified config files.</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L357)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_delete_file_checksum**
[details summary="<i>Delete a file checksum from the app settings</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_delete_file_checksum --file=file`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: The file for which the checksum will be deleted
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
$app should be defined when calling this helper</br></br>Requires YunoHost version 3.3.1 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L390)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_backup_before_upgrade**
[details summary="<i>Make a backup in case of failed upgrade</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup_before_upgrade
2020-05-21 01:22:39 +02:00
ynh_clean_setup () {
ynh_restore_upgradebackup
}
2021-02-07 15:50:29 +01:00
ynh_abort_if_errors`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L412)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_restore_upgradebackup**
[details summary="<i>Restore a previous backup if the upgrade process failed</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_backup_before_upgrade
2020-05-21 01:22:39 +02:00
ynh_clean_setup () {
ynh_restore_upgradebackup
}
2021-02-07 15:50:29 +01:00
ynh_abort_if_errors`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/backup#L461)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### FAIL2BAN
2021-02-07 15:50:29 +01:00
**ynh_add_fail2ban_config**
[details summary="<i>Create a dedicated fail2ban config (jail and filter conf files)</i>" class="helper-card-subtitle text-muted"]
<p></p>
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]
2: ynh_add_fail2ban_config --use_template [--others_var="list of others variables to replace"]
2021-02-07 15:50:29 +01:00
| for example : 'var_1 var_2 ...'`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l`, `--logpath=`: Log file to be checked by fail2ban
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-r`, `--failregex=`: Failregex to be looked for by fail2ban
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-m`, `--max_retry=`: Maximum number of retries allowed before banning IP address - default: 3
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--ports=`: Ports blocked for a banned IP address - default: http,https
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--use_template`: Use this helper in template mode
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-v`, `--others_var=`: List of others variables to replace separeted by a space
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
-----------------------------------------------------------------------------</br></br>This will use a template in ../conf/f2b\_jail.conf and ../conf/f2b\_filter.conf</br> \_\_APP\_\_ by $app</br></br>You can dynamically replace others variables by example :</br> \_\_VAR\_1\_\_ by $var\_1</br> \_\_VAR\_2\_\_ by $var\_2</br></br>Generally your template will look like that by example (for synapse):</br></br>f2b\_jail.conf:</br> [\_\_APP\_\_]</br> enabled = true</br> port = http,https</br> filter = \_\_APP\_\_</br> logpath = /var/log/\_\_APP\_\_/logfile.log</br> maxretry = 3</br></br>f2b\_filter.conf:</br> [INCLUDES]</br> before = common.conf</br> [Definition]</br></br># Part of regex definition (just used to make more easy to make the global regex)</br> \_\_synapse\_start\_line = .? \- synapse\..+ \-</br></br># Regex definition.</br> 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\:.+)$</br></br>ignoreregex =</br></br>-----------------------------------------------------------------------------</br></br>Note about the "failregex" option:</br> regex to match the password failure messages in the logfile. The</br> host must be matched by a group named "host". The tag "<HOST>" can</br> be used for standard IP/hostname matching and is only an alias for</br> (?:::f{4,6}:)?(?P<host>[\w\-.^\_]+)</br></br>You can find some more explainations about how to make a regex here :</br> https://www.fail2ban.org/wiki/index.php/MANUAL\_0\_8#Filters</br></br>Note that the logfile need to exist before to call this helper !!</br></br>To validate your regex you can test with this command:</br>fail2ban-regex /var/log/YOUR\_LOG\_FILE\_PATH /etc/fail2ban/filter.d/YOUR\_APP.conf</br></br>Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/fail2ban#L65)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_fail2ban_config**
[details summary="<i>Remove the dedicated fail2ban config (jail and filter conf files)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_fail2ban_config`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/fail2ban#L150)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### GETOPTS
2021-02-07 15:50:29 +01:00
### HARDWARE
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**ynh_get_ram**
[details summary="<i>Get the total or free amount of RAM+swap on the system</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-f`, `--free`: Count free RAM+swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-t`, `--total`: Count total RAM+swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-s`, `--ignore_swap`: Ignore swap, consider only real RAM
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-o`, `--only_swap`: Ignore real RAM, consider only swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the amount of free ram
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.8.1 or higher.</br></br>
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/hardware#L13)
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**ynh_require_ram**
[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"]
<p></p>
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_require_ram --required=RAM required in Mb [--free|--total] [--ignore_swap|--only_swap]
| exit: Return 1 if the ram is under the requirement, 0 otherwise.`
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-r`, `--required=`: The amount to require, in Mb
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-f`, `--free`: Count free RAM+swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-t`, `--total`: Count total RAM+swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-s`, `--ignore_swap`: Ignore swap, consider only real RAM
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-o`, `--only_swap`: Ignore real RAM, consider only swap
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.8.1 or higher.</br></br>
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/hardware#L82)
[/details]
----------------
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
### LOGGING
2021-02-07 15:50:29 +01:00
**ynh_die**
[details summary="<i>Print a message to stderr and exit</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_die --message=MSG [--ret_code=RETCODE]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: Message to display
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-c`, `--ret_code=`: Exit code to exit with
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.4.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L10)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_print_info**
[details summary="<i>Display a message in the 'INFO' logging category</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_info --message="Some message"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: Message to display
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L30)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_print_warn**
[details summary="<i>Print a warning on stderr</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_warn --message="Text to print"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: The text to print
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L75)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_print_err**
[details summary="<i>Print an error on stderr</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_err --message="Text to print"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: The text to print
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L92)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_exec_err**
[details summary="<i>Execute a command and print the result as an error</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_err your_command
ynh_exec_err "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L114)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_exec_warn**
[details summary="<i>Execute a command and print the result as a warning</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_warn your_command
ynh_exec_warn "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L129)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_exec_warn_less**
[details summary="<i>Execute a command and force the result to be printed on stdout</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_warn_less your_command
ynh_exec_warn_less "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L144)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_exec_quiet**
[details summary="<i>Execute a command and redirect stdout in /dev/null</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_quiet your_command
ynh_exec_quiet "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L159)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_exec_fully_quiet**
[details summary="<i>Execute a command and redirect stdout and stderr in /dev/null</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_fully_quiet your_command
ynh_exec_fully_quiet "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L174)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_print_OFF**
[details summary="<i>Remove any logs for all the following commands.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_OFF`
2021-02-07 15:50:29 +01:00
**Details**:
WARNING: You should be careful with this helper, and never forget to use ynh\_print\_ON as soon as possible to restore the logging.</br></br>Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L185)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_print_ON**
[details summary="<i>Restore the logging after ynh_print_OFF</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_print_ON`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.2.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L194)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_script_progression**
[details summary="<i>Print a progress bar showing the progression of an app script</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_script_progression --message=message [--weight=weight] [--time]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: The text to print
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-w`, `--weight=`: The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-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.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-l`, `--last`: Use for the last call of the helper, to fill the progression bar.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L222)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_return**
[details summary="<i>Return data to the Yunohost core for later processing
(to be used by special hooks like app config panel and core diagnosis)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_return somedata`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.6.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L307)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_debug**
[details summary="<i>Debugger for app packagers</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_debug [--message=message] [--trace=1/0]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--message=`: The text to print
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--trace=`: Turn on or off the trace of the script. Usefull to trace nonly a small part of a script.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L318)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_debug_exec**
[details summary="<i>Execute a command and print the result as debug</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_debug_exec your_command
ynh_debug_exec "your_command | other_command"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `command`: command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
When using pipes, double quotes are required - otherwise, this helper will run the first command, and the whole output will be sent through the next pipe.</br></br>If the command to execute uses double quotes, they have to be escaped or they will be interpreted and removed.</br></br>Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logging#L375)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### LOGROTATE
2021-02-07 15:50:29 +01:00
**ynh_use_logrotate**
[details summary="<i>Use logrotate to manage the logfile</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_use_logrotate [--logfile=/log/file] [--nonappend] [--specific_user=user/group]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l`, `--logfile=`: absolute path of logfile
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-n`, `--nonappend`: (optional) Replace the config file instead of appending this new config.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-u`, `--specific_user=`: run logrotate as the specified user and group. If not specified logrotate is runned as root.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
If no --logfile is provided, /var/log/${app} will be used as default.</br>logfile can be just a directory, or a full path to a logfile :</br>/parentdir/logdir</br>/parentdir/logdir/logfile.log</br></br>It's possible to use this helper multiple times, each config will be added to</br>the same logrotate config file. Unless you use the option --non-append</br></br>Requires YunoHost version 2.6.4 or higher.</br>Requires YunoHost version 3.2.0 or higher for the argument --specific\_user</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logrotate#L20)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_logrotate**
[details summary="<i>Remove the app's logrotate config.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_logrotate`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/logrotate#L108)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### MYSQL
2021-02-07 15:50:29 +01:00
**ynh_mysql_connect_as**
[details summary="<i>Open a connection as a user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_connect_as --user=user --password=password [--database=database]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--user=`: the user name to connect as
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--password=`: the user password
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_mysql_connect_as --user="user" --password="pass" <<< "UPDATE ...;" example: ynh_mysql_connect_as --user="user" --password="pass" < /path/to/file.sql`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L16)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_execute_as_root**
[details summary="<i>Execute a command as root user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_execute_as_root --sql=sql [--database=database]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s`, `--sql=`: the SQL command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L37)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_execute_file_as_root**
[details summary="<i>Execute a command from a file as root user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_execute_file_as_root --file=file [--database=database]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: the file containing SQL commands
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L63)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_dump_db**
[details summary="<i>Dump a database</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_dump_db --database=database`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database name to dump
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: the mysqldump output
2021-02-07 15:50:29 +01:00
**Example**: `ynh_mysql_dump_db --database=roundcube > ./dump.sql`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L135)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_user_exists**
[details summary="<i>Check if a mysql user exists</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_user_exists --user=user
| exit: Return 1 if the user doesn't exist, 0 otherwise.`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--user=`: the user for which to check existence
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L167)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_setup_db**
[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"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--db_user=`: Owner of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-n`, `--db_name=`: Name of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--db_pwd=`: Password of the database. If not provided, a password will be generated
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
After executing this helper, the password of the created database will be available in $db\_pwd</br>It will also be stored as "mysqlpwd" into the app settings.</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L207)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_mysql_remove_db**
[details summary="<i>Remove a database if it exists, and the associated user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_mysql_remove_db --db_user=user --db_name=name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--db_user=`: Owner of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-n`, `--db_name=`: Name of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/mysql#L232)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### NETWORK
2021-02-07 15:50:29 +01:00
**ynh_find_port**
[details summary="<i>Find a free port and return it</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_find_port --port=begin_port`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p`, `--port=`: port to start to search
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the port number
2021-02-07 15:50:29 +01:00
**Example**: `port=$(ynh_find_port --port=8080)`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/network#L12)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_port_available**
[details summary="<i>Test if a port is available</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_find_port --port=XYZ
| exit: Return 1 if the port is already used by another process.`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-p`, `--port=`: port to check
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_port_available --port=1234 || ynh_die "Port 1234 is needs to be available for this app"`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.8.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/network#L37)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_validate_ip4**
[details summary="<i>Validate an IPv4 address</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_validate_ip4 --ip_address=ip_address`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-i`, `--ip_address=`: the ipv4 address to check
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: 0 for valid ipv4 addresses, 1 otherwise
2021-02-07 15:50:29 +01:00
**Example**: `ynh_validate_ip4 111.222.333.444`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/network#L99)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_validate_ip6**
[details summary="<i>Validate an IPv6 address</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_validate_ip6 --ip_address=ip_address`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-i`, `--ip_address=`: the ipv6 address to check
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: 0 for valid ipv6 addresses, 1 otherwise
2021-02-07 15:50:29 +01:00
**Example**: `ynh_validate_ip6 2000:dead:beef::1`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/network#L121)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### NGINX
2021-02-07 15:50:29 +01:00
**ynh_add_nginx_config**
[details summary="<i>Create a dedicated nginx config</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_add_nginx_config "list of others variables to replace"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `list`: (Optional) list of others variables to replace separated by spaces. For example : 'path_2 port_2 ...'
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
This will use a template in ../conf/nginx.conf</br> \_\_PATH\_\_ by $path\_url</br> \_\_DOMAIN\_\_ by $domain</br> \_\_PORT\_\_ by $port</br> \_\_NAME\_\_ by $app</br> \_\_FINALPATH\_\_ by $final\_path</br> \_\_PHPVERSION\_\_ by $YNH\_PHP\_VERSION ($YNH\_PHP\_VERSION is either the default php version or the version defined for the app)</br></br>And dynamic variables (from the last example) :</br> \_\_PATH\_2\_\_ by $path\_2</br> \_\_PORT\_2\_\_ by $port\_2</br></br>Requires YunoHost version 2.7.2 or higher.</br>Requires YunoHost version 2.7.13 or higher for dynamic variables</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/nginx#L23)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_nginx_config**
[details summary="<i>Remove the dedicated nginx config</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_nginx_config`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/nginx#L77)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### NODEJS
2021-02-07 15:50:29 +01:00
**ynh_use_nodejs**
[details summary="<i>Load the version of node for an app, and set variables.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_use_nodejs`
2021-02-07 15:50:29 +01:00
**Details**:
ynh\_use\_nodejs has to be used in any app scripts before using node for the first time.</br>This helper will provide alias and variables to use in your scripts.</br></br>To use npm or node, use the alias `ynh\_npm` and `ynh\_node`</br>Those alias will use the correct version installed for the app</br>For example: use `ynh\_npm install` instead of `npm install`</br></br>With `sudo` or `ynh\_exec\_as`, use instead the fallback variables `$ynh\_npm` and `$ynh\_node`</br>And propagate $PATH to sudo with $ynh\_node\_load\_PATH</br>Exemple: `ynh\_exec\_as $app $ynh\_node\_load\_PATH $ynh\_npm install`</br></br>$PATH contains the path of the requested version of node.</br>However, $PATH is duplicated into $node\_PATH to outlast any manipulation of $PATH</br>You can use the variable `$ynh\_node\_load\_PATH` to quickly load your node version</br> in $PATH for an usage into a separate script.</br>Exemple: $ynh\_node\_load\_PATH $final\_path/script\_that\_use\_npm.sh`</br></br>Finally, to start a nodejs service with the correct version, 2 solutions</br> Either the app is dependent of node or npm, but does not called it directly.</br> In such situation, you need to load PATH</br> `Environment="\_\_NODE\_ENV\_PATH\_\_"`</br> `ExecStart=\_\_FINALPATH\_\_/my\_app`</br> You will replace \_\_NODE\_ENV\_PATH\_\_ with $ynh\_node\_load\_PATH</br></br>Or node start the app directly, then you don't need to load the PATH variable</br> `ExecStart=\_\_YNH\_NODE\_\_ my\_app run`</br> You will replace \_\_YNH\_NODE\_\_ with $ynh\_node</br></br>2 other variables are also available</br> - $nodejs\_path: The absolute path to node binaries for the chosen version.</br> - $nodejs\_version: Just the version number of node for this app. Stored as 'nodejs\_version' in settings.yml.</br></br>Requires YunoHost version 2.7.12 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/nodejs#L68)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_install_nodejs**
[details summary="<i>Install a specific version of nodejs</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_install_nodejs --nodejs_version=nodejs_version`
2021-02-07 15:50:29 +01: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.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
ynh\_install\_nodejs will install the version of node provided as argument by using n.</br></br>n (Node version management) uses the PATH variable to store the path of the version of node it is going to use.</br>That's how it changes the version</br></br>Refer to ynh\_use\_nodejs for more information about available commands and variables</br></br>Requires YunoHost version 2.7.12 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/nodejs#L106)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_nodejs**
[details summary="<i>Remove the version of node used by the app.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_nodejs`
2021-02-07 15:50:29 +01:00
**Details**:
This helper will check if another app uses the same version of node,</br>if not, this version of node will be removed.</br>If no other app uses node, n will be also removed.</br></br>Requires YunoHost version 2.7.12 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/nodejs#L187)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### PERMISSION
2021-02-07 15:50:29 +01:00
**ynh_permission_create**
[details summary="<i>Create a new permission for the app</i>" class="helper-card-subtitle text-muted"]
<p></p>
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]
[--protected=true|false]
| Not that if 'show_tile' is enabled, this URL will be the URL of the tile.
| Default is "APP_LABEL (permission name)".
| Default is false (for the permission different than 'main').
| won't be able to add or remove the visitors group of this permission.
2021-02-07 15:50:29 +01:00
| By default it's 'false'`
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-p,`: - the name for the permission (by default a permission named "main" already exist)
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-u,`: - (optional) URL for which access will be allowed/forbidden.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-A,`: - (optional) List of additional URL for which access will be allowed/forbidden
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-h,`: - (optional) Define for the URL of this permission, if SSOwat pass the authentication header to the application. Default is true
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-a,`: - (optional) A list of group/user to allow for the permission
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-l,`: - (optional) Define a name for the permission. This label will be shown on the SSO and in the admin.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-t,`: - (optional) Define if a tile will be shown in the SSO. If yes the name of the tile will be the 'label' parameter.
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-P,`: - (optional) Define if this permission is protected. If it is protected the administrator
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
example 1: ynh\_permission\_create --permission=admin --url=/admin --additional\_urls=domain.tld/admin /superadmin --allowed=alice bob \</br> --label="My app admin" --show\_tile=true</br></br>This example will create a new permission permission with this following effect:</br>- 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'.</br>- Only the user alice and bob will have the access to theses following url: /admin, domain.tld/admin, /superadmin</br></br>example 2: ynh\_permission\_create --permission=api --url=domain.tld/api --auth\_header=false --allowed=visitors \</br> --label="MyApp API" --protected=true</br></br>This example will create a new protected permission. So the admin won't be able to add/remove the visitors group of this permission.</br>In case of an API with need to be always public it avoid that the admin break anything.</br>With this permission all client will be allowed to access to the url 'domain.tld/api'.</br>Note that in this case no tile will be show on the SSO.</br>Note that the auth\_header parameter is to 'false'. So no authentication header will be passed to the application.</br>Generally the API is requested by an application and enabling the auth\_header has no advantage and could bring some issues in some case.</br>So in this case it's better to disable this option for all API.</br></br>If provided, 'url' or 'additional\_urls' is assumed to be relative to the app domain/path if they</br>start with '/'. For example:</br> / -> domain.tld/app</br> /admin -> domain.tld/app/admin</br> domain.tld/app/api -> domain.tld/app/api</br></br>'url' or 'additional\_urls' can be treated as a PCRE (not lua) regex if it starts with "re:".</br>For example:</br> re:/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$</br> re:domain.tld/app/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$</br></br>Note that globally the parameter 'url' and 'additional\_urls' are same. The only difference is:</br>- 'url' is only one url, 'additional\_urls' can be a list of urls. There are no limitation of 'additional\_urls'</br>- 'url' is used for the url of tile in the SSO (if enabled with the 'show\_tile' parameter)</br></br>About the authentication header (auth\_header parameter).</br>The SSO pass (by default) to the application theses following HTTP header (linked to the authenticated user) to the application:</br> - "Auth-User": username</br> - "Remote-User": username</br> - "Email": user email</br></br>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.</br>See https://github.com/YunoHost/issues/issues/1420 for more informations</br></br>Requires YunoHost version 3.7.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L69)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_permission_delete**
[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"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_delete --permission="permission"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-01-08 03:53:37 +01:00
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-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_permission_delete --permission=editors`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.7.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L164)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_permission_exists**
[details summary="<i>Check if a permission exists</i>" class="helper-card-subtitle text-muted"]
<p></p>
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`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p`, `--permission=`: the permission to check
2021-02-07 15:50:29 +01:00
2019-07-11 22:50:20 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.7.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L181)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_permission_url**
[details summary="<i>Redefine the url associated to a permission</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-01-08 03:53:37 +01:00
[--auth_header=true|false] [--clear_urls]
2021-02-07 15:50:29 +01:00
| Note that if you want to remove url you can pass an empty sting as arguments ("").`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-p,`: - the name for the permission (by default a permission named "main" is removed automatically when the app is removed)
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-u,`: - (optional) URL for which access will be allowed/forbidden.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-a,`: - (optional) List of additional url to add for which access will be allowed/forbidden.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-r,`: - (optional) List of additional url to remove for which access will be allowed/forbidden
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-h,`: - (optional) Define for the URL of this permission, if SSOwat pass the authentication header to the application
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-c,`: - (optional) Clean all urls (url and additional_urls)
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.7.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L204)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_permission_update**
[details summary="<i>Update a permission for the app</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_permission_update --permission "permission" [--add="group" ["group" ...]] [--remove="group" ["group" ...]]
2021-01-08 03:53:37 +01:00
[--label="label"] [--show_tile=true|false] [--protected=true|false]
2021-02-07 15:50:29 +01:00
| won't be able to add or remove the visitors group of this permission.`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-p,`: - the name for the permission (by default a permission named "main" already exist)
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-a,`: - the list of group or users to enable add to the permission
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-r,`: - the list of group or users to remove from the permission
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-l,`: - (optional) Define a name for the permission. This label will be shown on the SSO and in the admin.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-t,`: - (optional) Define if a tile will be shown in the SSO
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-P,`: - (optional) Define if this permission is protected. If it is protected the administrator
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.7.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L280)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_permission_has_user**
[details summary="<i>Check if a permission has an user</i>" class="helper-card-subtitle text-muted"]
<p></p>
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`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-p`, `--permission=`: the permission to check
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-u`, `--user=`: the user seek in the permission
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_permission_has_user --permission=main --user=visitors`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.7.1 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L355)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_legacy_permissions_exists**
[details summary="<i>Check if a legacy permissions exist</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_legacy_permissions_exists
| exit: Return 1 if the permission doesn't exist, 0 otherwise`
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 4.1.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L378)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_legacy_permissions_delete_all**
[details summary="<i>Remove all legacy permissions</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_legacy_permissions_delete_all`
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.`
2020-05-21 01:22:39 +02:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/permission#L399)
[/details]
----------------
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
### PHP
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**ynh_add_fpm_config**
[details summary="<i>Create a dedicated PHP-FPM config</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-v`, `--phpversion=`: Version of PHP to use.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--use_template`: Use this helper in template mode.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: Additionnal PHP packages to install
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--dedicated_service`: Use a dedicated PHP-FPM service instead of the common one.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-v`, `--phpversion=`: Version of PHP to use.
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-f`, `--footprint=`: Memory footprint of the service (low/medium/high).
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-u`, `--usage=`: Expected usage of the service (low/medium/high).
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--package=`: Additionnal PHP packages to install for a specific version of PHP
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--dedicated_service`: Use a dedicated PHP-FPM service instead of the common one.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
-----------------------------------------------------------------------------</br></br>The footprint of the service will be used to defined the maximum footprint we can allow, which is half the maximum RAM.</br>So it will be used to defined 'pm.max\_children'</br>A lower value for the footprint will allow more children for 'pm.max\_children'. And so for</br> 'pm.start\_servers', 'pm.min\_spare\_servers' and 'pm.max\_spare\_servers' which are defined from the</br> value of 'pm.max\_children'</br>NOTE: 'pm.max\_children' can't exceed 4 times the number of processor's cores.</br></br>The usage value will defined the way php will handle the children for the pool.</br>A value set as 'low' will set the process manager to 'ondemand'. Children will start only if the</br> service is used, otherwise no child will stay alive. This config gives the lower footprint when the</br> service is idle. But will use more proc since it has to start a child as soon it's used.</br>Set as 'medium', the process manager will be at dynamic. If the service is idle, a number of children</br> equal to pm.min\_spare\_servers will stay alive. So the service can be quick to answer to any request.</br> The number of children can grow if needed. The footprint can stay low if the service is idle, but</br> not null. The impact on the proc is a little bit less than 'ondemand' as there's always a few</br> children already available.</br>Set as 'high', the process manager will be set at 'static'. There will be always as many children as</br> 'pm.max\_children', the footprint is important (but will be set as maximum a quarter of the maximum</br> RAM) but the impact on the proc is lower. The service will be quick to answer as there's always many</br> children ready to answer.</br></br>Requires YunoHost version 2.7.2 or higher.</br>Requires YunoHost version 3.5.1 or higher for the argument --phpversion</br>Requires YunoHost version 3.8.1 or higher for the arguments --use\_template, --usage, --footprint, --package and --dedicated\_service</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/php#L61)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_fpm_config**
[details summary="<i>Remove the dedicated PHP-FPM config</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_fpm_config`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/php#L288)
[/details]
----------------
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
### POSTGRESQL
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**ynh_psql_connect_as**
[details summary="<i>Open a connection as a user</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--user=`: the user name to connect as
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--password=`: the user password
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01: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-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
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L18)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_execute_as_root**
[details summary="<i>Execute a command as root user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_execute_as_root --sql=sql [--database=database]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s`, `--sql=`: the SQL command to execute
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L39)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_execute_file_as_root**
[details summary="<i>Execute a command from a file as root user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_execute_file_as_root --file=file [--database=database]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: the file containing SQL commands
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database to connect to
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L65)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_dump_db**
[details summary="<i>Dump a database</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_dump_db --database=database`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database name to dump
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: the psqldump output
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_psql_dump_db 'roundcube' > ./dump.sql`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L137)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_user_exists**
[details summary="<i>Check if a psql user exists</i>" class="helper-card-subtitle text-muted"]
<p></p>
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`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--user=`: the user for which to check existence
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L170)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_database_exists**
[details summary="<i>Check if a psql database exists</i>" class="helper-card-subtitle text-muted"]
<p></p>
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`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d`, `--database=`: the database for which to check existence
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L193)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_setup_db**
[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"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_setup_db --db_user=user --db_name=name [--db_pwd=pwd]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--db_user=`: Owner of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-n`, `--db_name=`: Name of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--db_pwd=`: Password of the database. If not provided, a password will be generated
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
After executing this helper, the password of the created database will be available in $db\_pwd</br>It will also be stored as "psqlpwd" into the app settings.</br></br>Requires YunoHost version 2.7.13 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L232)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_remove_db**
[details summary="<i>Remove a database if it exists, and the associated user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_psql_remove_db --db_user=user --db_name=name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--db_user=`: Owner of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-n`, `--db_name=`: Name of the database
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.13 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L263)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_psql_test_if_first_run**
[details summary="<i>Create a master password and set up global settings
2021-01-08 03:53:37 +01:00
It also make sure that postgresql is installed and running
2021-02-07 15:50:29 +01:00
Please always call this script in install and restore scripts</i>" class="helper-card-subtitle text-muted"]
<p></p>
**Usage**: `ynh_psql_test_if_first_run`
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.13 or higher.</br></br>
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/postgresql#L295)
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
### SETTING
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
**ynh_app_setting_get**
[details summary="<i>Get an application setting</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-a`, `--app=`: the application id
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: the setting to get
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/setting#L10)
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**ynh_app_setting_set**
[details summary="<i>Set an application setting</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-03-30 16:19:47 +02:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-a`, `--app=`: the application id
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: the setting name to set
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-v`, `--value=`: the setting value to set
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/setting#L34)
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**ynh_app_setting_delete**
[details summary="<i>Delete an application setting</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-a`, `--app=`: the application id
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: the setting to delete
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/setting#L58)
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**ynh_webpath_available**
[details summary="<i>Check availability of a web path</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-d`, `--domain=`: the domain/host of the url
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-p`, `--path_url=`: the web path to check the availability of
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2020-05-21 01:22:39 +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-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/setting#L118)
[/details]
----------------
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**ynh_webpath_register**
[details summary="<i>Register/book a web path for an app</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-a`, `--app=`: the app for which the domain should be registered
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--domain=`: the domain/host of the web path
2021-01-08 03:53:37 +01:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
- `-p`, `--path_url=`: the web path to be registered
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
2020-03-30 16:19:47 +02:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_webpath_register --app=wordpress --domain=some.domain.tld --path_url=/coffee`
2020-03-30 16:19:47 +02:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/setting#L140)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### STRING
2021-02-07 15:50:29 +01:00
**ynh_string_random**
[details summary="<i>Generate a random string</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_string_random [--length=string_length]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-l`, `--length=`: the string length to generate (default: 24)
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the generated string
2021-02-07 15:50:29 +01:00
**Example**: `pwd=$(ynh_string_random --length=8)`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/string#L12)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_replace_string**
[details summary="<i>Substitute/replace a string (or expression) by another in a file</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_replace_string --match_string=match_string --replace_string=replace_string --target_file=target_file`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--match_string=`: String to be searched and replaced in the file
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-r`, `--replace_string=`: String that will replace matches
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-f`, `--target_file=`: File in which the string will be replaced.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
As this helper is based on sed command, regular expressions and</br>references to sub-expressions can be used</br>(see sed manual page for more information)</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/string#L38)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_replace_special_string**
[details summary="<i>Substitute/replace a special string by another in a file</i>" class="helper-card-subtitle text-muted"]
<p></p>
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`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--match_string=`: String to be searched and replaced in the file
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-r`, `--replace_string=`: String that will replace matches
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--target_file=`: File in which the string will be replaced.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
This helper will use ynh\_replace\_string, but as you can use special</br>characters, you can't use some regular expressions and sub-expressions.</br></br>Requires YunoHost version 2.7.7 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/string#L67)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_sanitize_dbid**
[details summary="<i>Sanitize a string intended to be the name of a database
(More specifically : replace - and . by _)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_sanitize_dbid --db_name=name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-n`, `--db_name=`: name to correct/sanitize
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: the corrected name
2021-02-07 15:50:29 +01:00
**Example**: `dbname=$(ynh_sanitize_dbid $app)`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/string#L98)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### SYSTEMD
2021-02-07 15:50:29 +01:00
**ynh_add_systemd_config**
[details summary="<i>Create a dedicated systemd config</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_add_systemd_config [--service=service] [--template=template]
ynh_add_systemd_config [--service=service] [--template=template] [--others_var="list of others variables to replace"]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s`, `--service=`: Service name (optionnal, $app by default)
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
- `-t`, `--template=`: Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template)
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-v`, `--others_var=`: List of others variables to replace separated by a space. For example: 'var_1 var_2 ...'
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
This will use the template ../conf/<templatename>.service</br>to generate a systemd config, by replacing the following keywords</br>with global variables that should be defined before calling</br>this helper :</br></br>\_\_APP\_\_ by $app</br> \_\_FINALPATH\_\_ by $final\_path</br></br>And dynamic variables (from the last example) :</br> \_\_VAR\_1\_\_ by $var\_1</br> \_\_VAR\_2\_\_ by $var\_2</br></br>Requires YunoHost version 2.7.11 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/systemd#L24)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_remove_systemd_config**
[details summary="<i>Remove the dedicated systemd config</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_remove_systemd_config [--service=service]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-s`, `--service=`: Service name (optionnal, $app by default)
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/systemd#L71)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_systemd_action**
[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"]
<p></p>
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] ]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-n`, `--service_name=`: Name of the service to start. Default : $app
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-a`, `--action=`: Action to perform with systemctl. Default: start
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01: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. WARNING: When using --line_match, you should always add `ynh_clean_check_starting` into your `ynh_clean_setup` at the beginning of the script. Otherwise, tail will not stop in case of failure of the script. The script will then hang forever.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-p`, `--log_path=`: Log file - Path to the log file. Default : /var/log/$app/$app.log
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--timeout=`: Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-e`, `--length=`: Length of the error log : Default : 20
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/systemd#L101)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_clean_check_starting**
[details summary="<i>Clean temporary process and file used by ynh_check_starting
(usually used in ynh_clean_setup scripts)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_clean_check_starting`
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/systemd#L203)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### USER
2021-02-07 15:50:29 +01:00
**ynh_user_exists**
[details summary="<i>Check if a YunoHost user exists</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_user_exists --username=username
| exit: Return 1 if the user doesn't exist, 0 otherwise`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--username=`: the username to check
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_user_exists 'toto' || exit 1`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L12)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_user_get_info**
[details summary="<i>Retrieve a YunoHost user information</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_user_get_info --username=username --key=key`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--username=`: the username to retrieve info from
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: the key to retrieve
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Returns**: string - the key's value
2021-02-07 15:50:29 +01:00
**Example**: `mail=$(ynh_user_get_info 'toto' 'mail')`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L33)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_user_list**
[details summary="<i>Get the list of YunoHost users</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_user_list`
2021-02-07 15:50:29 +01:00
**Returns**: string - one username per line
2021-02-07 15:50:29 +01:00
**Example**: `for u in $(ynh_user_list); do ...`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.4.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L53)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_system_user_exists**
[details summary="<i>Check if a user exists on the system</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_system_user_exists --username=username
| exit: Return 1 if the user doesn't exist, 0 otherwise`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--username=`: the username to check
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.2.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L65)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_system_group_exists**
[details summary="<i>Check if a group exists on the system</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_system_group_exists --group=group
| exit: Return 1 if the group doesn't exist, 0 otherwise`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-g`, `--group=`: the group to check
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0.2 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L83)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_system_user_create**
[details summary="<i>Create a system user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_system_user_create --username=user_name [--home_dir=home_dir] [--use_shell]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--username=`: Name of the system user that will be create
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-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
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-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-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Examples**:
2021-02-07 15:50:29 +01:00
- `Create a nextcloud user with no home directory and /usr/sbin/nologin login shell (hence no login capability)`
2021-02-07 15:50:29 +01:00
- ` ynh_system_user_create --username=nextcloud`
2021-02-07 15:50:29 +01:00
- `Create a discourse user using /var/www/discourse as home directory and the default login shell`
2021-02-07 15:50:29 +01:00
- ` ynh_system_user_create --username=discourse --home_dir=/var/www/discourse --use_shell`
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L108)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_system_user_delete**
[details summary="<i>Delete a system user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_system_user_delete --username=user_name`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-u`, `--username=`: Name of the system user that will be create
2021-02-07 15:50:29 +01:00
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L144)
[/details]
----------------
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
**ynh_exec_as**
[details summary="<i>Execute a command as another user</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_exec_as $USER COMMAND [ARG ...]`
2021-02-02 05:00:35 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 4.1.7 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/user#L172)
[/details]
----------------
2021-02-07 15:50:29 +01:00
### UTILS
2021-02-07 15:50:29 +01:00
**ynh_abort_if_errors**
[details summary="<i>Exits if an error occurs during the execution of the script.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_abort_if_errors`
2021-02-07 15:50:29 +01:00
**Details**:
This configure the rest of the script execution such that, if an error occurs</br>or if an empty variable is used, the execution of the script stops</br>immediately and a call to `ynh\_clean\_setup` is triggered if it has been</br>defined by your script.</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L54)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_setup_source**
[details summary="<i>Download, check integrity, uncompress and patch the source from app.src</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_setup_source --dest_dir=dest_dir [--source_id=source_id]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-d`, `--dest_dir=`: Directory where to setup sources
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-s`, `--source_id=`: Name of the app, if the package contains more than one app
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
The file conf/app.src need to contains:</br></br>SOURCE\_URL=Address to download the app archive</br>SOURCE\_SUM=Control sum</br># (Optional) Program to check the integrity (sha256sum, md5sum...)</br># default: sha256</br>SOURCE\_SUM\_PRG=sha256</br># (Optional) Archive format</br># default: tar.gz</br>SOURCE\_FORMAT=tar.gz</br># (Optional) Put false if sources are directly in the archive root</br># default: true</br># Instead of true, SOURCE\_IN\_SUBDIR could be the number of sub directories</br># to remove.</br>SOURCE\_IN\_SUBDIR=false</br># (Optionnal) Name of the local archive (offline setup support)</br># default: ${src\_id}.${src\_format}</br>SOURCE\_FILENAME=example.tar.gz</br># (Optional) If it set as false don't extract the source.</br># (Useful to get a debian package or a python wheel.)</br># default: true</br>SOURCE\_EXTRACT=(true|false)</br></br>Details:</br>This helper downloads sources from SOURCE\_URL if there is no local source</br>archive in /opt/yunohost-apps-src/APP\_ID/SOURCE\_FILENAME</br></br>Next, it checks the integrity with "SOURCE\_SUM\_PRG -c --status" command.</br></br>If it's ok, the source archive will be uncompressed in $dest\_dir. If the</br>SOURCE\_IN\_SUBDIR is true, the first level directory of the archive will be</br>removed.</br>If SOURCE\_IN\_SUBDIR is a numeric value, 2 for example, the 2 first level</br>directories will be removed</br></br>Finally, patches named sources/patches/${src\_id}-*.patch and extra files in</br>sources/extra\_files/$src\_id will be applied to dest\_dir</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L105)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_local_curl**
[details summary="<i>Curl abstraction to help with POST requests to local pages (such as installation forms)</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `page_uri`: Path (relative to $path_url) of the page where POST data will be sent
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `key1=value1`: (Optionnal) POST key and corresponding value
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `key2=value2`: (Optionnal) Another POST key and corresponding value
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `...`: (Optionnal) More POST keys and values
2021-02-07 15:50:29 +01: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-02-07 15:50:29 +01:00
**Details**:
For multiple calls, cookies are persisted between each call for the same app</br></br>$domain and $path\_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))</br></br>Requires YunoHost version 2.6.4 or higher.</br></br>
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L230)
[/details]
----------------
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**ynh_add_config**
[details summary="<i>Create a dedicated config file from a template</i>" class="helper-card-subtitle text-muted"]
<p></p>
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-02-07 15:50:29 +01:00
**Arguments**:
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- `-t`, `--template=`: Template config file to use
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- `-d`, `--destination=`: Destination of the config file
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Examples**:
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- ` ynh_add_config --template=".env" --destination="$final_path/.env"`
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- ` ynh_add_config --template="../conf/.env" --destination="$final_path/.env"`
2020-12-31 17:30:18 +01: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
2021-02-07 15:50:29 +01:00
**Details**:
The template can be by default the name of a file in the conf directory</br>of a YunoHost Package, a relative path or an absolute path</br>The helper will use the template $template to generate a config file</br>$destination by replacing the following keywords with global variables</br>that should be defined before calling this helper :</br> \_\_PATH\_\_ by $path\_url</br> \_\_NAME\_\_ by $app</br> \_\_NAMETOCHANGE\_\_ by $app</br> \_\_USER\_\_ by $app</br> \_\_FINALPATH\_\_ by $final\_path</br> \_\_PHPVERSION\_\_ by $YNH\_PHP\_VERSION</br> \_\_YNH\_NODE\_LOAD\_PATH\_\_ by $ynh\_node\_load\_PATH</br></br>And any dynamic variables that should be defined before calling this helper like:</br> \_\_DOMAIN\_\_ by $domain</br> \_\_APP\_\_ by $app</br> \_\_VAR\_1\_\_ by $var\_1</br> \_\_VAR\_2\_\_ by $var\_2</br></br>The helper will verify the checksum and backup the destination file</br>if it's different before applying the new template.</br>And it will calculate and store the destination file checksum</br>into the app settings when configuration is done.</br></br>Requires YunoHost version 4.1.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L302)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_get_debian_release**
[details summary="<i>Fetch the Debian release codename</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_get_debian_release`
2021-02-07 15:50:29 +01:00
**Returns**: The Debian release codename (i.e. jessie, stretch, ...)
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.7.12 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L436)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_secure_remove**
[details summary="<i>Remove a file or a directory securely</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_secure_remove --file=path_to_remove`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-f`, `--file=`: File or directory to remove
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 2.6.4 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L466)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_read_manifest**
[details summary="<i>Read the value of a key in a ynh manifest file</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_read_manifest --manifest="manifest.json" --key="key"`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--manifest=`: Path of the manifest to read
2021-02-07 15:50:29 +01:00
2021-02-07 15:50:29 +01:00
- `-k`, `--key=`: Name of the key to find
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the value associate to that key
2021-02-07 15:50:29 +01:00
**Details**:
Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L547)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_app_upstream_version**
[details summary="<i>Read the upstream version from the manifest, or from the env variable $YNH_APP_MANIFEST_VERSION if not given</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_upstream_version [--manifest="manifest.json"]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--manifest=`: Path of the manifest to read
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the version number of the upstream app
2021-02-07 15:50:29 +01:00
**Details**:
The version number in the manifest is defined by <upstreamversion>~ynh<packageversion></br>For example : 4.3-2~ynh3</br>This include the number before ~ynh</br>In the last example it return 4.3-2</br></br>Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L576)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_app_package_version**
[details summary="<i>Read package version from the manifest</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_app_package_version [--manifest="manifest.json"]`
2021-02-07 15:50:29 +01:00
**Arguments**:
2021-02-07 15:50:29 +01:00
- `-m`, `--manifest=`: Path of the manifest to read
2021-02-07 15:50:29 +01:00
2020-05-21 01:22:39 +02:00
2021-02-07 15:50:29 +01:00
**Returns**: the version number of the package
2021-02-07 15:50:29 +01:00
**Details**:
The version number in the manifest is defined by <upstreamversion>~ynh<packageversion></br>For example : 4.3-2~ynh3</br>This include the number after ~ynh</br>In the last example it return 3</br></br>Requires YunoHost version 3.5.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L607)
[/details]
----------------
2021-02-07 15:50:29 +01:00
**ynh_check_app_version_changed**
[details summary="<i>Checks the app version to upgrade with the existing app version and returns:</i>" class="helper-card-subtitle text-muted"]
<p></p>
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_check_app_version_changed`
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
- UPGRADE\_PACKAGE if only the YunoHost package has changed</br>- UPGRADE\_APP otherwise</br></br>This helper should be used to avoid an upgrade of an app, or the upstream part</br>of it, when it's not needed</br></br>To force an upgrade, even if the package is up to date,</br>you have to use the parameter --force (or -F).</br>example: sudo yunohost app upgrade MyApp --force</br></br>Requires YunoHost version 3.5.0 or higher.</br></br>
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L634)
[/details]
----------------
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**ynh_compare_current_package_version**
[details summary="<i>Compare the current package version against another version given as an argument.
This is really useful when we need to do some actions only for some old package versions.</i>" class="helper-card-subtitle text-muted"]
<p></p>
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Usage**: `ynh_compare_current_package_version --comparison lt|le|eq|ne|ge|gt
| eq (equal), ne (not equal), ge (greater or equal), gt (greater than)`
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Arguments**:
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- `--comparison`: Comparison type. Could be : lt (lower than), le (lower or equal),
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
- `--version`: The version to compare. Need to be a version in the yunohost package version type (like 2.3.1~ynh4)
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Example**: `ynh_compare_current_package_version --comparison lt --version 2.3.2~ynh1 This example will check if the installed version is lower than (lt) the version 2.3.2~ynh1`
2020-12-31 17:30:18 +01:00
2021-02-07 15:50:29 +01:00
**Details**:
Generally you might probably use it as follow in the upgrade script</br></br>if ynh\_compare\_current\_package\_version --comparison lt --version 2.3.2~ynh1</br>then</br> # Do something that is needed for the package version older than 2.3.2~ynh1</br>fi</br></br>Return 0 if the evaluation is true. 1 if false.</br></br>Requires YunoHost version 3.8.0 or higher.</br></br>
2021-02-07 15:50:29 +01:00
[Dude, show me the code!](https://github.com/YunoHost/yunohost/blob/adc83b4c9c2c30e9ef75f3609c538b646f91f1db/data/helpers.d/utils#L666)
[/details]
----------------