diff --git a/packaging_apps_helpers.md b/packaging_apps_helpers.md index 3edf714c..6780502e 100644 --- a/packaging_apps_helpers.md +++ b/packaging_apps_helpers.md @@ -1,277 +1,3015 @@ -Application packaging - -## Shell helpers - -Since YunoHost 2.4 release, **new shell helpers** are available to ease common packaging tasks like password generation, MySQL database creation… - -Usage examples are available in the [example application](https://github.com/YunoHost/example_ynh/blob/master/scripts/install). We advise to use them. - -You can find them on this [repository](https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d). - -To use them, you need to add following lines in the shell scripts: -```bash -# Source app helpers -source /usr/share/yunohost/helpers -``` - -### Available helpers list (non exhaustive) -#### Database - -```bash -ynh_mysql_execute_as_root SQL DB -``` - -> Runs the SQL command `SQL` as database root user on `DB` database (this last argument is optional). - -```bash -ynh_mysql_execute_file_as_root FILE DB -``` - -> Runs the SQL commands listed inside `FILE` as root user on `DB` database (this last argument is optional). - -```bash -ynh_mysql_create_db DB USER PWD -``` -> Create the `DB` database and grants all rights to `USER` (created on the fly with `PASSWORD` password). - -```bash -ynh_mysql_drop_db DB -``` -> Delete the `DB` database. - -```bash -ynh_mysql_drop_user USERNAME -``` -> Delete the `USERNAME` MySQL user. - -```bash -ynh_mysql_dump_db DB > ./FILE -``` - -> Exports the `DB` database into the `FILE` file. - -#### Debian packages handling - -```bash -ynh_package_is_installed PACKAGE -``` - -> Tests if the Debian package `PACKAGE` is installed on the system. - > Read command output to know the result. e.g: -> ```bash -> if ! ynh_package_is_installed "yunohost" ; then -> echo "Oops, package is not installed" -> else -> echo "Package is installed" -> fi -> ``` - -```bash -ynh_package_version PACKAGE -``` -> Returns the installed version number of `PACKAGE`. - -```bash -ynh_package_update -``` -> Updates the packages list (`apt update`) in a silent and non-interactive way. - -**Be careful, the following commands are to be avoided when possible. Installing (and even more removing) a package without handling conflicts and dependencies is risky. That will be improved in future Yunohost versions.** - -```bash -ynh_package_install PACKAGE1 PACKAGE2 -``` -> Installs (`apt install`) `PACKAGE1`, `PACKAGE2`… packages, in a non interactive and silent way. - -```bash -ynh_package_autoremove PACKAGE1 PACKAGE2 -``` - -> Removes (`apt-get autoremove`) `PACKAGE1`, `PACKAGE2`… packages in a silent and non-interactive way. - -#### Apps configuration - -```bash -ynh_app_setting_set APP KEY VALUE -``` - -> Store the setting named `KEY` with value `VALUE` for the app `APP`. This allows to reuse it later (typically in the `upgrade` script), or so that YunoHost can autoconfigure the SSO. -> The settings are stored in the /etc/yunohost/apps/${APP}/settings.yml file. -> For example, to store the visibility setting (private or public app), you can use : -> ```bash -> ynh_app_setting_set my_app is_public "yes" -> ``` - -The SSO uses app stored settings to allow or deny public access to HTTP resources. There are 6 configuration keys : - -`skipped_uris`, `unprotected_uris` and `protected_uris` are relative to app path. Example: -> ```bash -> ynh_app_setting_set app_name skipped_uris "/blog" -> ``` -> Matches the /blog path of the application: https://domain.tld/path_app/blog and everything under this path, but not https://domain.tld/path_app/. - -**skipped_uris** -An URL set with *skipped_uris* key will be totally ignored by the SSO, which means that the access will be public and the logged-in user information will not be passed to the app. - -**unprotected_uris** -An URL set with *unprotected_uris* key will be accessible publicly, but if an user is logged in, his information will be accessible (though HTTP headers) to the app. - -**protected_uris** -An URL set with *protected_uris* will be blocked by the SSO and accessible only to authenticated and authorized users. - -`skipped_regex`, `unprotected_uris` and `protected_regex` are regex counterparts of the above keys. - -> The syntax is **not** the "standard" regex syntax ([PCRE](https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions)) but [Lua patterns](http://lua-users.org/wiki/PatternsTutorial). - -The regex patterns match the whole URL, unlike the string patterns (which match only the app-local part of the URL, as detailed above). This means you must write complete patterns including the *domain* and *path*. -> For example, to use *skipped_regex* to match /blog followed by a 1+ digit number: -> ```bash -> ynh_app_setting_set app_name skipped_regex "$domain$path/blog%?%d+$" -> ``` -> This may lead to an issue : if $domain or $path contain a dash (-), it will interpreted as a pattern magic char. That is why dashes must be escaped with a %. -> ```bash -> domainregex=$(echo "$domain" | sed 's/-/\%&/g') -> pathregex=$(echo "$path" | sed 's/-/\%&/g') -> ynh_app_setting_set app_name skipped_regex "$domainregex$pathregex/blog%?%d+$" -> ``` - -```bash -ynh_app_setting_get APP KEY -``` - -> Get the value of the setting named `KEY` for the `APP` app. -> Example : -> ```bash -> is_public=$(ynh_app_setting_get app_name is_public) -> ``` - - -```bash -ynh_app_setting_delete APP KEY -``` - -Delete the setting named `KEY` for the `APP` app. - -#### Users management - -```bash -ynh_user_exists USERNAME -``` - -> Checks the existence of `USERNAME` user in YunoHost. -> Command return code must be checked to know the result. -> Example: -> ```bash -> if ynh_user_exists "johndoe" ; then -> echo "This user exists!" -> fi -> ``` -```bash -ynh_user_get_info USERNAME KEY -``` - -> Get the `KEY` information on `USERNAME` user. -> Possible `KEY` values are: -> - firstname -> - fullname -> - lastname -> - mail -> - mail-aliases -> - mailbox-quota -> Example: -> ```bash -> mailadmin=$(ynh_user_get_info $admin mail) -> ``` - - -```bash -ynh_system_user_exists USERNAME -``` -> Checks if the `USERNAME` unix user exists. -> Command return code must be checked to know the result. -> Example: -> ```bash -> if ynh_system_user_exists "www-data" ; then -> echo "User exists on system!" -> fi -> ``` - - -#### Other commands -```bash -ynh_string_random LENGTH -``` -> Generates a random string of `LENGTH` chars (defaults to 24). - - -```bash -ynh_die MSG RETCODE -``` -> Displays the `MSG` message on stderr and exits the script with `RETCODE` return code (defaults to 1). - -
- -**Following commands are to be replaced (or even deleted) in future YunoHost versions.** - -```bash -sudo yunohost app checkport -``` -> This helper checks the port and returns an error if the port is already in use. -> Command return code must be checked to know the result. -> Example: -> ```bash -> port=DEFAULT_PORT -> while ! sudo yunohost app checkport $port ; do -> port=$((port+1)) -> done -> ``` - - -```bash -sudo yunohost firewall allow [--no-upnp] {TCP,UDP,Both} PORT -``` -> Opens the port number `PORT` on the firewall, for TCP, UDP or both. -> Automatic port opening via upnp may be disabled on this port using `--no-upnp` - -```bash -sudo yunohost firewall disallow {TCP,UDP,Both} PORT -``` -> Closes the port number `PORT` on the firewall for TCP, UDP or both. - -```bash -sudo yunohost app checkurl DOMAINPATH -a APP -``` - -> Checks `DOMAIN`/`PATH` url availability. Useful for web apps to make sure the chosen URL is not already taken by another app. If the URL is available, that commands register for the `APP` application. -> **Note**: do not prepend `http://` or `https://` to `DOMAINPATH`. - - -```bash -sudo yunohost app addaccess APP [--users=USER] -``` -> Allow the `USER` user to access `APP`. - -> it's possible to add several users on several apps at once, for exemple: -```bash -sudo yunohost app addaccess app1 app2 -u user1 user2 -``` - -```bash -sudo yunohost app removeaccess APP --users=USER -``` -> Remove the access authorization to `APP` from `USER` user. - -> like for addaccess, it's possible to remove several users on several apps at once, for exemple: -```bash -sudo yunohost app removeaccess app1 app2 -u user1 user2 - -```bash -sudo yunohost service remove NAME -``` -> Remove the service `NAME` from the YunoHost management interface. - - -```bash -sudo yunohost app ssowatconf -``` -> This commands rebuilds the SSO configuration. It is called automatically at the end of any script, but you may want to call it by hand before. + + +

App helpers

+ + + +

backend

+ + + +
+
+
+
ynh_use_logrotate
+
Use logrotate to manage the logfile
+
+
+
+

+ + Usage: ynh_use_logrotate [logfile] [--non-append|--append] [specific_user/specific_group] + +

+ +

+ Arguments: +

    + +
  • logfile : absolute path of logfile
  • + +
  • --non-append : (Option) Replace the config file instead of appending this new config.
  • + +
  • specific_user : run logrotate as the specified user and group. If not specified logrotate is runned as root.
  • + +
+

+ + + + +

+ Details: +

+ If no argument provided, a standard directory will be use. /var/log/${app}
You can provide a path with the directory only or with the logfile.
/parentdir/logdir
/parentdir/logdir/logfile.log

It's possible to use this helper several times, each config will be added to the same logrotate config file.
Unless you use the option --non-append

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_logrotate
+
Remove the app's logrotate config.
+
+
+
+

+ + Usage: ynh_remove_logrotate + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_add_systemd_config
+
Create a dedicated systemd config
+
+
+
+

+ + Usage: ynh_add_systemd_config [service] [template] + +

+ +

+ Arguments: +

    + +
  • service : Service name (optionnal, $app by default)
  • + +
  • template : Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.service will be used as template)
  • + +
+

+ + + + +

+ Details: +

+ This will use the template ../conf/.service
to generate a systemd config, by replacing the following keywords
with global variables that should be defined before calling
this helper :

__APP__ by $app
__FINALPATH__ by $final_path

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_systemd_config
+
Remove the dedicated systemd config
+
+
+
+

+ + Usage: ynh_remove_systemd_config [service] + +

+ +

+ Arguments: +

    + +
  • service : Service name (optionnal, $app by default)
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_add_nginx_config
+
Create a dedicated nginx config
+
+
+
+

+ + Usage: ynh_add_nginx_config "list of others variables to replace" + +

+ +

+ Arguments: +

    + +
  • list : ['others', 'variables', 'to', 'replace', 'separeted', 'by', 'a', 'space']
  • + +
+

+ + + + +

+ Details: +

+ This will use a template in ../conf/nginx.conf
__PATH__ by $path_url
__DOMAIN__ by $domain
__PORT__ by $port
__NAME__ by $app
__FINALPATH__ by $final_path

And dynamic variables (from the last example) :
__PATH_2__ by $path_2
__PORT_2__ by $port_2

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_nginx_config
+
Remove the dedicated nginx config
+
+
+
+

+ + Usage: ynh_remove_nginx_config + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_add_fpm_config
+
Create a dedicated php-fpm config
+
+
+
+

+ + Usage: ynh_add_fpm_config + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_fpm_config
+
Remove the dedicated php-fpm config
+
+
+
+

+ + Usage: ynh_remove_fpm_config + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

filesystem

+ + + +
+
+
+
ynh_backup
+
Add a file or a directory to the list of paths to backup
+
+
+
+

+ + Usage: ynh_backup src [dest [is_big [arg]]] +the backup dir. +backup dir + +

+ +

+ Arguments: +

    + +
  • src : file or directory to bind or symlink or copy. it shouldn't be in
  • + +
  • dest : destination file or directory inside the
  • + +
  • is_big : 1 to indicate data are big (mail, video, image ...)
  • + +
  • arg : Deprecated arg
  • + +
+

+ + + +

+ Example: # Wordpress app context +

+ + +

+ Details: +

+ Note: this helper could be used in backup hook or in backup script inside an
app package

Details: ynh_backup writes SRC and the relative DEST into a CSV file. And it
creates the parent destination directory

If DEST is ended by a slash it complete this path with the basename of SRC.

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
# => This line will be added into CSV file
# "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/etc/nginx/conf.d/$domain.d/$app.conf"

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf"

#Deprecated usages (maintained for retro-compatibility)
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/conf/nginx.conf"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/nginx.conf"

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/conf/"
# => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_restore
+
Restore all files linked to the restore hook or to the restore app script
+
+
+
+

+ + Usage: ynh_restore + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_restore_file
+
Restore a file or a directory
+
+
+
+

+ + Usage: ynh_restore_file ORIGIN_PATH [ DEST_PATH ] +to be backuped or relative path to $YNH_CWD where it is located in the backup archive +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 + +

+ +

+ Arguments: +

    + +
  • ORIGIN_PATH : Path where was located the file or the directory before
  • + +
  • DEST_PATH : Path where restore the file or the dir, if unspecified,
  • + +
+

+ + + +

+ Example: ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" # if apps/wordpress/etc/nginx/conf.d/$domain.d/$app.conf exists, restore it into # /etc/nginx/conf.d/$domain.d/$app.conf # if no, search a correspondance in the csv (eg: conf/nginx.conf) and restore it into # /etc/nginx/conf.d/$domain.d/$app.conf +

+ + +

+ Details: +

+ Use the registered path in backup_list by ynh_backup to restore the file at
the good place.

If DEST_PATH already exists and is lighter than 500 Mo, a backup will be made in
/home/yunohost.conf/backup/. Otherwise, the existing file is removed.

# DON'T GIVE THE ARCHIVE PATH:
ynh_restore_file "conf/nginx.conf"

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_store_file_checksum
+
Calculate and store a file checksum into the app settings
+
+
+
+

+ + Usage: ynh_store_file_checksum file + +

+ +

+ Arguments: +

    + +
  • file : The file on which the checksum will performed, then stored.
  • + +
+

+ + + + +

+ Details: +

+ $app should be defined when calling this helper

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_backup_if_checksum_is_different
+
Verify the checksum and backup the file if it's different +This helper is primarily meant to allow to easily backup personalised/manually +modified config files.
+
+
+
+

+ + Usage: ynh_backup_if_checksum_is_different file + +

+ +

+ Arguments: +

    + +
  • file : The file on which the checksum test will be perfomed.
  • + +
+

+ + + + +

+ Details: +

+ $app should be defined when calling this helper

| ret: Return the name a the backup file, or nothing

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_secure_remove
+
Remove a file or a directory securely
+
+
+
+

+ + Usage: ynh_secure_remove path_to_remove + +

+ +

+ Arguments: +

    + +
  • path_to_remove : File or directory to remove
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

ip

+ + + +
+
+
+
ynh_validate_ip
+
Validate an IP address
+
+
+
+

+ + Usage: ynh_validate_ip [family] [ip_address] + +

+ + +

+ Returns: 0 for valid ip addresses, 1 otherwise +

+ + +

+ Example: ynh_validate_ip 4 111.222.333.444 +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_validate_ip4
+
Validate an IPv4 address
+
+
+
+

+ + Usage: ynh_validate_ip4 + +

+ + +

+ Returns: 0 for valid ipv4 addresses, 1 otherwise +

+ + +

+ Example: ynh_validate_ip4 111.222.333.444 +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_validate_ip6
+
Validate an IPv6 address
+
+
+
+

+ + Usage: ynh_validate_ip6 + +

+ + +

+ Returns: 0 for valid ipv6 addresses, 1 otherwise +

+ + +

+ Example: ynh_validate_ip6 2000:dead:beef::1 +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

mysql

+ + + +
+
+
+
ynh_mysql_connect_as
+
Open a connection as a user
+
+
+
+

+ + Usage: ynh_mysql_connect_as user pwd [db] + +

+ +

+ Arguments: +

    + +
  • user : the user name to connect as
  • + +
  • pwd : the user password
  • + +
  • db : the database to connect to
  • + +
+

+ + + +

+ Example: ynh_mysql_connect_as 'user' 'pass' <<< "UPDATE ...;" example: ynh_mysql_connect_as 'user' 'pass' < /path/to/file.sql +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_execute_as_root
+
Execute a command as root user
+
+
+
+

+ + Usage: ynh_mysql_execute_as_root sql [db] + +

+ +

+ Arguments: +

    + +
  • sql : the SQL command to execute
  • + +
  • db : the database to connect to
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_execute_file_as_root
+
Execute a command from a file as root user
+
+
+
+

+ + Usage: ynh_mysql_execute_file_as_root file [db] + +

+ +

+ Arguments: +

    + +
  • file : the file containing SQL commands
  • + +
  • db : the database to connect to
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_dump_db
+
Dump a database
+
+
+
+

+ + Usage: ynh_mysql_dump_db db + +

+ +

+ Arguments: +

    + +
  • db : the database name to dump
  • + +
+

+ + +

+ Returns: the mysqldump output +

+ + +

+ Example: ynh_mysql_dump_db 'roundcube' > ./dump.sql +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_user_exists
+
Check if a mysql user exists
+
+
+
+

+ + Usage: ynh_mysql_user_exists user + +

+ +

+ Arguments: +

    + +
  • user : the user for which to check existence
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_setup_db
+
Create a database, an user and its password. Then store the password in the app's config
+
+
+
+

+ + Usage: ynh_mysql_setup_db user name [pwd] + +

+ +

+ Arguments: +

    + +
  • user : Owner of the database
  • + +
  • name : Name of the database
  • + +
  • pwd : Password of the database. If not given, a password will be generated
  • + +
+

+ + + + +

+ Details: +

+ After executing this helper, the password of the created database will be available in $db_pwd
It will also be stored as "mysqlpwd" into the app settings.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_mysql_remove_db
+
Remove a database if it exists, and the associated user
+
+
+
+

+ + Usage: ynh_mysql_remove_db user name + +

+ +

+ Arguments: +

    + +
  • user : Owner of the database
  • + +
  • name : Name of the database
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_sanitize_dbid
+
Sanitize a string intended to be the name of a database +(More specifically : replace - and . by _)
+
+
+
+

+ + Usage: ynh_sanitize_dbid name + +

+ +

+ Arguments: +

    + +
  • name : name to correct/sanitize
  • + +
+

+ + +

+ Returns: the corrected name +

+ + +

+ Example: dbname=$(ynh_sanitize_dbid $app) +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

network

+ + + +
+
+
+
ynh_normalize_url_path
+
Normalize the url path syntax +Handle the slash at the beginning of path and its absence at ending +Return a normalized url path
+
+
+
+

+ + Usage: ynh_normalize_url_path path_to_normalize + +

+ +

+ Arguments: +

    + +
  • url_path_to_normalize : URL path to normalize before using it
  • + +
+

+ + + +

+ Example: url_path=$(ynh_normalize_url_path $url_path) ynh_normalize_url_path example -> /example ynh_normalize_url_path /example -> /example ynh_normalize_url_path /example/ -> /example ynh_normalize_url_path / -> / +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_find_port
+
Find a free port and return it
+
+
+
+

+ + Usage: ynh_find_port begin_port + +

+ +

+ Arguments: +

    + +
  • begin_port : port to start to search
  • + +
+

+ + + +

+ Example: port=$(ynh_find_port 8080) +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_webpath_available
+
Check availability of a web path
+
+
+
+

+ + Usage: ynh_webpath_available domain path + +

+ +

+ Arguments: +

    + +
  • domain : the domain/host of the url
  • + +
  • path : the web path to check the availability of
  • + +
+

+ + + +

+ Example: ynh_webpath_available some.domain.tld /coffee +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_webpath_register
+
Register/book a web path for an app
+
+
+
+

+ + Usage: ynh_webpath_register app domain path + +

+ +

+ Arguments: +

    + +
  • app : the app for which the domain should be registered
  • + +
  • domain : the domain/host of the web path
  • + +
  • path : the web path to be registered
  • + +
+

+ + + +

+ Example: ynh_webpath_register wordpress some.domain.tld /coffee +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

nodejs

+ + + +
+
+
+
export
+
N_PREFIX is the directory of n, it needs to be loaded as a environment variable.
+
+
+
+

+ + Usage: + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_use_nodejs
+
Load the version of node for an app, and set variables.
+
+
+
+

+ + Usage: ynh_use_nodejs + +

+ + + + +

+ Details: +

+ ynh_use_nodejs has to be used in any app scripts before using node for the first time.

2 variables are available:
- $nodejs_path: The absolute path of node for the chosen version.
- $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml.
And 2 alias stored in variables:
- $nodejs_use_version: An old variable, not used anymore. Keep here to not break old apps
NB: $PATH will contain the path to node, it has to be propagated to any other shell which needs to use it.
That's means it has to be added to any systemd script.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_install_nodejs
+
Install a specific version of nodejs
+
+
+
+

+ + Usage: ynh_install_nodejs [nodejs_version] + If possible, prefer to use major version number (e.g. 8 instead of 8.10.0). + The crontab will handle the update of minor versions when needed. + +

+ +

+ Arguments: +

    + +
  • nodejs_version : Version of node to install.
  • + +
+

+ + + + +

+ Details: +

+ n (Node version management) uses the PATH variable to store the path of the version of node it is going to use.
That's how it changes the version

ynh_install_nodejs will install the version of node provided as argument by using n.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_nodejs
+
Remove the version of node used by the app.
+
+
+
+

+ + Usage: ynh_remove_nodejs + +

+ + + + +

+ Details: +

+ This helper will check if another app uses the same version of node,
if not, this version of node will be removed.
If no other app uses node, n will be also removed.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

package

+ + + +
+
+
+
ynh_package_is_installed
+
Check either a package is installed or not
+
+
+
+

+ + Usage: ynh_package_is_installed name + +

+ +

+ Arguments: +

    + +
  • name : the package name to check
  • + +
+

+ + + +

+ Example: ynh_package_is_installed 'yunohost' && echo "ok" +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_version
+
Get the version of an installed package
+
+
+
+

+ + Usage: ynh_package_version name + +

+ +

+ Arguments: +

    + +
  • name : the package name to get version
  • + +
+

+ + +

+ Returns: the version or an empty string +

+ + +

+ Example: version=$(ynh_package_version 'yunohost') +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_update
+
Update package index files
+
+
+
+

+ + Usage: ynh_package_update + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_install
+
Install package(s)
+
+
+
+

+ + Usage: ynh_package_install name [name [...]] + +

+ +

+ Arguments: +

    + +
  • name : the package name to install
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_remove
+
Remove package(s)
+
+
+
+

+ + Usage: ynh_package_remove name [name [...]] + +

+ +

+ Arguments: +

    + +
  • name : the package name to remove
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_autoremove
+
Remove package(s) and their uneeded dependencies
+
+
+
+

+ + Usage: ynh_package_autoremove name [name [...]] + +

+ +

+ Arguments: +

    + +
  • name : the package name to remove
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_package_autopurge
+
Purge package(s) and their uneeded dependencies
+
+
+
+

+ + Usage: ynh_package_autopurge name [name [...]] + +

+ +

+ Arguments: +

    + +
  • name : the package name to autoremove and purge
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_install_app_dependencies
+
Define and install dependencies with a equivs control file +This helper can/should only be called once per app
+
+
+
+

+ + Usage: ynh_install_app_dependencies dep [dep [...]] + You can give a choice between some package with this syntax : "dep1|dep2" + Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" + This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) + +

+ +

+ Arguments: +

    + +
  • dep : the package name to install in dependence
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_remove_app_dependencies
+
Remove fake package and its dependencies
+
+
+
+

+ + Usage: ynh_remove_app_dependencies + +

+ + + + +

+ Details: +

+ Dependencies will removed only if no other package need them.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

print

+ + + +
+
+
+
ynh_die
+
Print a message to stderr and exit +usage: ynh_die MSG [RETCODE]
+
+
+
+

+ + Usage: + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_info
+
Display a message in the 'INFO' logging category
+
+
+
+

+ + Usage: ynh_info "Some message" + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

psql

+ + + +
+
+
+
ynh_psql_test_if_first_run
+
Create a master password and set up global settings +Please always call this script in install and restore scripts
+
+
+
+

+ + Usage: ynh_psql_test_if_first_run + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_connect_as
+
Open a connection as a user
+
+
+
+

+ + Usage: ynh_psql_connect_as user pwd [db] + +

+ +

+ Arguments: +

    + +
  • user : the user name to connect as
  • + +
  • pwd : the user password
  • + +
  • db : the database to connect to
  • + +
+

+ + + +

+ Example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_execute_as_root
+
# Execute a command as root user
+
+
+
+

+ + Usage: ynh_psql_execute_as_root sql [db] + +

+ +

+ Arguments: +

    + +
  • sql : the SQL command to execute
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_execute_file_as_root
+
Execute a command from a file as root user
+
+
+
+

+ + Usage: ynh_psql_execute_file_as_root file [db] + +

+ +

+ Arguments: +

    + +
  • file : the file containing SQL commands
  • + +
  • db : the database to connect to
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_setup_db
+
Create a database, an user and its password. Then store the password in the app's config
+
+
+
+

+ + Usage: ynh_psql_setup_db user name [pwd] + +

+ +

+ Arguments: +

    + +
  • user : Owner of the database
  • + +
  • name : Name of the database
  • + +
  • pwd : Password of the database. If not given, a password will be generated
  • + +
+

+ + + + +

+ Details: +

+ After executing this helper, the password of the created database will be available in $db_pwd
It will also be stored as "psqlpwd" into the app settings.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_create_db
+
Create a database and grant privilegies to a user
+
+
+
+

+ + Usage: ynh_psql_create_db db [user [pwd]] + +

+ +

+ Arguments: +

    + +
  • db : the database name to create
  • + +
  • user : the user to grant privilegies
  • + +
  • pwd : the user password
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_remove_db
+
Drop a database
+
+
+
+

+ + Usage: ynh_psql_drop_db db + +

+ +

+ Arguments: +

    + +
  • db : the database name to drop
  • + +
  • user : the user to drop
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_dump_db
+
Dump a database
+
+
+
+

+ + Usage: ynh_psql_dump_db db + +

+ +

+ Arguments: +

    + +
  • db : the database name to dump
  • + +
+

+ + +

+ Returns: the psqldump output +

+ + +

+ Example: ynh_psql_dump_db 'roundcube' > ./dump.sql +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_create_user
+
Create a user
+
+
+
+

+ + Usage: ynh_psql_create_user user pwd [host] + +

+ +

+ Arguments: +

    + +
  • user : the user name to create
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_psql_drop_user
+
Drop a user
+
+
+
+

+ + Usage: ynh_psql_drop_user user + +

+ +

+ Arguments: +

    + +
  • user : the user name to drop
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

setting

+ + + +
+
+
+
ynh_app_setting_get
+
Get an application setting
+
+
+
+

+ + Usage: ynh_app_setting_get app key + +

+ +

+ Arguments: +

    + +
  • app : the application id
  • + +
  • key : the setting to get
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_app_setting_set
+
Set an application setting
+
+
+
+

+ + Usage: ynh_app_setting_set app key value + +

+ +

+ Arguments: +

    + +
  • app : the application id
  • + +
  • key : the setting name to set
  • + +
  • value : the setting value to set
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_app_setting_delete
+
Delete an application setting
+
+
+
+

+ + Usage: ynh_app_setting_delete app key + +

+ +

+ Arguments: +

    + +
  • app : the application id
  • + +
  • key : the setting to delete
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

string

+ + + +
+
+
+
ynh_string_random
+
Generate a random string
+
+
+
+

+ + Usage: ynh_string_random [length] + +

+ +

+ Arguments: +

    + +
  • length : the string length to generate (default: 24)
  • + +
+

+ + + +

+ Example: pwd=$(ynh_string_random 8) +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_replace_string
+
Substitute/replace a string (or expression) by another in a file
+
+
+
+

+ + Usage: ynh_replace_string match_string replace_string target_file + +

+ +

+ Arguments: +

    + +
  • match_string : String to be searched and replaced in the file
  • + +
  • replace_string : String that will replace matches
  • + +
  • target_file : File in which the string will be replaced.
  • + +
+

+ + + + +

+ Details: +

+ As this helper is based on sed command, regular expressions and
references to sub-expressions can be used
(see sed manual page for more information)

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_replace_special_string
+
Substitute/replace a special string by another in a file
+
+
+
+

+ + Usage: ynh_replace_special_string match_string replace_string target_file + +

+ +

+ Arguments: +

    + +
  • match_string : String to be searched and replaced in the file
  • + +
  • replace_string : String that will replace matches
  • + +
  • target_file : File in which the string will be replaced.
  • + +
+

+ + + + +

+ Details: +

+ This helper will use ynh_replace_string, but as you can use special
characters, you can't use some regular expressions and sub-expressions.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

system

+ + + +
+
+
+
ynh_abort_if_errors
+
Exits if an error occurs during the execution of the script.
+
+
+
+

+ + Usage: ynh_abort_if_errors + +

+ + + + +

+ Details: +

+ This configure the rest of the script execution such that, if an error occurs
or if an empty variable is used, the execution of the script stops
immediately and a call to `ynh_clean_setup` is triggered if it has been
defined by your script.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_get_debian_release
+
Fetch the Debian release codename
+
+
+
+

+ + Usage: ynh_get_debian_release + +

+ + +

+ Returns: The Debian release codename (i.e. jessie, stretch, ...) +

+ + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

user

+ + + +
+
+
+
ynh_user_exists
+
Check if a YunoHost user exists
+
+
+
+

+ + Usage: ynh_user_exists username + +

+ +

+ Arguments: +

    + +
  • username : the username to check
  • + +
+

+ + + +

+ Example: ynh_user_exists 'toto' || exit 1 +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_user_get_info
+
Retrieve a YunoHost user information
+
+
+
+

+ + Usage: ynh_user_get_info username key + +

+ +

+ Arguments: +

    + +
  • username : the username to retrieve info from
  • + +
  • key : the key to retrieve
  • + +
+

+ + +

+ Returns: string - the key's value +

+ + +

+ Example: mail=$(ynh_user_get_info 'toto' 'mail') +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_user_list
+
Get the list of YunoHost users
+
+
+
+

+ + Usage: ynh_user_list + +

+ + +

+ Returns: string - one username per line +

+ + +

+ Example: for u in $(ynh_user_list); do ... +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_system_user_exists
+
Check if a user exists on the system
+
+
+
+

+ + Usage: ynh_system_user_exists username + +

+ +

+ Arguments: +

    + +
  • username : the username to check
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_system_user_create
+
Create a system user
+
+
+
+

+ + Usage: ynh_system_user_create user_name [home_dir] + +

+ +

+ Arguments: +

    + +
  • user_name : Name of the system user that will be create
  • + +
  • 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
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_system_user_delete
+
Delete a system user
+
+
+
+

+ + Usage: ynh_system_user_delete user_name + +

+ +

+ Arguments: +

    + +
  • user_name : Name of the system user that will be create
  • + +
+

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + +

utils

+ + + +
+
+
+
ynh_get_plain_key
+
Extract a key from a plain command output
+
+
+
+

+ + Usage: ynh_get_plain_key key [subkey [subsubkey ...]] + +

+ + +

+ Returns: string - the key's value +

+ + +

+ Example: yunohost user info tata --output-as plain | ynh_get_plain_key mail +

+ + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_restore_upgradebackup
+
Restore a previous backup if the upgrade process failed
+
+
+
+

+ + Usage: ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_restore_upgradebackup +} +ynh_abort_if_errors + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_backup_before_upgrade
+
Make a backup in case of failed upgrade
+
+
+
+

+ + Usage: ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_restore_upgradebackup +} +ynh_abort_if_errors + +

+ + + + +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_setup_source
+
Download, check integrity, uncompress and patch the source from app.src
+
+
+
+

+ + Usage: ynh_setup_source dest_dir [source_id] + +

+ +

+ Arguments: +

    + +
  • dest_dir : Directory where to setup sources
  • + +
  • source_id : Name of the app, if the package contains more than one app
  • + +
+

+ + + + +

+ Details: +

+ The file conf/app.src need to contains:

SOURCE_URL=Address to download the app archive
SOURCE_SUM=Control sum
# (Optional) Program to check the integrity (sha256sum, md5sum...)
# default: sha256
SOURCE_SUM_PRG=sha256
# (Optional) Archive format
# default: tar.gz
SOURCE_FORMAT=tar.gz
# (Optional) Put false if sources are directly in the archive root
# default: true
SOURCE_IN_SUBDIR=false
# (Optionnal) Name of the local archive (offline setup support)
# default: ${src_id}.${src_format}
SOURCE_FILENAME=example.tar.gz
# (Optional) If it set as false don't extract the source.
# (Useful to get a debian package or a python wheel.)
# default: true
SOURCE_EXTRACT=(true|false)

Details:
This helper downloads sources from SOURCE_URL if there is no local source
archive in /opt/yunohost-apps-src/APP_ID/SOURCE_FILENAME

Next, it checks the integrity with "SOURCE_SUM_PRG -c --status" command.

If it's ok, the source archive will be uncompressed in $dest_dir. If the
SOURCE_IN_SUBDIR is true, the first level directory of the archive will be
removed.

Finally, patches named sources/patches/${src_id}-*.patch and extra files in
sources/extra_files/$src_id will be applied to dest_dir

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_local_curl
+
Curl abstraction to help with POST requests to local pages (such as installation forms)
+
+
+
+

+ + Usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ... + +

+ +

+ Arguments: +

    + +
  • page_uri : Path (relative to $path_url) of the page where POST data will be sent
  • + +
  • key1=value1 : (Optionnal) POST key and corresponding value
  • + +
  • key2=value2 : (Optionnal) Another POST key and corresponding value
  • + +
  • ... : (Optionnal) More POST keys and values
  • + +
+

+ + + +

+ Example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2" +

+ + +

+ Details: +

+ $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + +
+
+
+
ynh_render_template
+
Render templates with Jinja2
+
+
+
+

+ + Usage: ynh_render_template some_template output_path + +

+ +

+ Arguments: +

    + +
  • some_template : Template file to be rendered
  • + +
  • output_path : The path where the output will be redirected to
  • + +
+

+ + + + +

+ Details: +

+ Attention : Variables should be exported before calling this helper to be
accessible inside templates.

+

+

+ +

+ Dude, show me the code ! +

+ +
+
+ +
+ + + + + + diff --git a/packaging_apps_helpers_fr.md b/packaging_apps_helpers_fr.md deleted file mode 100644 index 06857b13..00000000 --- a/packaging_apps_helpers_fr.md +++ /dev/null @@ -1,539 +0,0 @@ -Packaging d’application - - -## Commandes pratiques en Shell - -À partir de YunoHost 2.4, de **nouvelles commandes pratiques *(helpers)* en shell** sont disponible pour faciliter le *packaging*, particulièrement pour des tâches répétitives comme la génération de mot de passe, la création de base de données MySQL… - -Des exemples sont disponibles dans l’[application d’exemple](https://github.com/YunoHost/example_ynh/blob/master/scripts/install). Il est conseillé d’utiliser les commandes pratiques. - -Vous pourrez les retrouver dans ce [dépôt](https://github.com/YunoHost/yunohost/blob/stable/data/helpers.d). - -Pour pouvoir utiliser les helpers, il faudra ajouter les lignes suivantes au début des scripts shell : -```bash -# Source app helpers -source /usr/share/yunohost/helpers -``` - -Le script helpers va exécuter tout les scripts présent dans helpers.d et donc charger les fonctions des helpers. Afin qu'elles puissent être appelées simplement. - - -### Liste non exhaustive des helpers disponibles -#### Base de données -```bash -ynh_mysql_setup_db USER NAME [PWD] -``` -> Créer l'utilisateur sql `USER` et lui octroie tout les droits sur une nouvelle base de donnée `NAME`. -Si aucun mot de passe n'est indiqué, un nouveau est généré et stocké dans la variable $db_pwd ainsi que dans la configuration de l'application sous le nom "mysqlpwd" -**Nécessite YunoHost version 2.6.4** - - -```bash -ynh_mysql_remove_db USER NAME -``` -> Supprime l'utilisateur sql `USER` et sa base de donnée `NAME`. -**Nécessite YunoHost version 2.6.4** - - -```bash -ynh_sanitize_dbid NAME -``` -> Corrige le nom d'une base de donnée pour s'assurer qu'il ne contient pas de caractères interdits. -Et renvoi ce nom corrigé. -> ```bash -> dbname=$(ynh_sanitize_dbid $app) -> ``` -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_mysql_execute_as_root SQL DB -``` -> Exécute la commande SQL `SQL` en tant que l'utilisateur root sur la base de données `DB` (ce dernier argument est optionnel). - - -```bash -ynh_mysql_execute_file_as_root FILE DB -``` -> Exécute les commandes SQL contenues dans le fichier `FILE` en tant que l'utilisateur root sur la base de données `DB` (ce dernier argument est optionnel). - - -```bash -ynh_mysql_create_db DB USER PWD -``` -> Crée la base de données `DB` et donne tous les droits sur celle-ci à l'utilisateur `USER` (automatiquement créé) identifié par le mot de passe `PWD`. - - -```bash -ynh_mysql_drop_db DB -``` -> Supprime la base de données `DB`. - -```bash -ynh_mysql_drop_user USERNAME -``` -> Supprime l'utilisateur MySQL `USERNAME` MySQL. - -```bash -ynh_mysql_dump_db DB > ./FILE -``` -> Exporte la base de données `DB` dans le fichier `FILE`. - - -#### Gestion des paquets Debian -```bash -ynh_package_is_installed PACKAGE -``` -> Détermine si le paquet `PACKAGE` est installé sur le système. -> La sortie de la commande doit être testée pour en connaître le résultat. Par exemple : -> ```bash -> if ! ynh_package_is_installed "yunohost" ; then -> echo "Oups, le paquet n'est pas installé." -> else -> echo "Le paquet est installé !" -> fi -> ``` - - -```bash -ynh_package_version PACKAGE -``` -> Retourne la version du paquet `PACKAGE` installé sur le système. - - -```bash -ynh_package_update -``` -> Met à jour la liste des paquets disponibles de manière silencieuse et non interactive. -> C'est un `apt-get update` avec les options -y -qq et noninteractive. - - -```bash -ynh_install_app_dependencies DEPENDANCE1 DEPENDANCE2 ... -``` -> Installe les paquets requis par une app sous forme de dépendance. De cette manière les paquets supplémentaires installés sont gérés en tant que dépendances par apt. -Il est préférable d'installer les paquets nécessaire par ce helper plutôt que par apt directement. -**Nécessite YunoHost version 2.6.4** - - -```bash -ynh_remove_app_dependencies -``` -> Supprime les dépendances de l'application, précédemment installées avec ynh_install_app_dependencies. -Les paquets ne seront supprimés que si aucune application ou paquet ne les utilisent encore, selon apt. -**Nécessite YunoHost version 2.6.4** - - -#### Configuration des applications -```bash -ynh_app_setting_set APP KEY VALUE -``` -> Stocke le réglage nommé `KEY` dont la valeur est `VALUE` pour l'application `APP `, afin de le réutiliser plus tard (typiquement dans le script `upgrade`) ou pour que YunoHost puisse se configurer automatiquement (par exemple pour le SSO). -> Les réglages sont stockés dans le fichier /etc/yunohost/apps/${APP}/settings.yml. -> Par exemple, pour stocker le paramètre de visibilité, privé ou public, d'une application, on notera ainsi : -> ```bash -> ynh_app_setting_set nom_app is_public "yes" -> ``` - -Le SSO fait appel aux réglages stockés pour l'application afin de déterminer si cette dernière peux être accessible publiquement ou non. -Pour cela, 6 clés différentes sont disponible : - -Tout d'abord `skipped_uris`, `unprotected_uris` et `protected_uris`. Ces 3 clés sont relatives au chemin (ou *path*) de l'application. -> Par exemple : -> ```bash -> ynh_app_setting_set nom_app skipped_uris "/" -> ``` -> concernera la racine de l'application, soit https://domain.tld/path_app/ ainsi que tout ce qui suivra. -> Alors que : -> ```bash -> ynh_app_setting_set nom_app skipped_uris "/blog" -> ``` -> concernera le path /blog de l'application, soit https://domain.tld/path_app/blog et ce qui suivra, mais pas https://domain.tld/path_app/. - -**skipped_uris** -Une url ajoutée avec la clé *skipped_uris* sera totalement ignorée par le SSO, donc l'accès sera public et ne prendra pas en compte un utilisateur déjà connecté. - -**unprotected_uris** -Une url ajoutée avec la clé *unprotected_uris* sera accessible publiquement, mais un utilisateur connecté au SSO pourra se connecter en utilisant le header HTTP. - -**protected_uris** -Une url ajoutée avec la clé *protected_uris* sera bloquée par le SSO et accessible uniquement aux utilisateurs authentifiés. - -Les clés `skipped_regex`, `unprotected_regex` et `protected_regex` sont les équivalents en "expressions régulières" des 3 clés précédentes. -> Il est important de noter que ce ne sont pas véritablement des expressions régulières qui seront interprétés, mais des patterns lua, dont la syntaxe différe légèrement. -> [Plus d'infos sur la syntaxe des patterns lua.](http://wxlua.free.fr/Tutoriel_Lua/Tuto/Strings/strings6.php) [Ainsi que quelques exemples.](http://wxlua.free.fr/Tutoriel_Lua/Tuto/Strings/strings7.php) -Les patterns utilisant des regex, contrairement aux précédents, sont recherchés sur la totalité de l'URL, et non uniquement sur la partie spécifique à l'application. Il convient donc d'écrire des patterns qui englobent l'URL entière (incluant *domaine* et *chemin*). -> Par exemple, si on souhaite placer *skipped_regex* sur /blog en considérant une suite de chiffres indéfinie en argument. On indiquera ceci : -> ```bash -> ynh_app_setting_set nom_app skipped_regex "$domain$path/blog%?%d+$" -> ``` -> Cela pose toutefois un éventuel problème, si les variables $domain ou $path contiennent un tiret (-), celui-ci sera interprété comme étant un caractère magique du pattern. Il faut donc échapper les éventuels tirets avec un %. -> ```bash -> domainregex=$(echo "$domain" | sed 's/-/\%&/g') -> pathregex=$(echo "$path" | sed 's/-/\%&/g') -> ynh_app_setting_set nom_app skipped_regex "$domainregex$pathregex/blog%?%d+$" -> ``` - - -```bash -ynh_app_setting_get APP KEY -``` -> Récupère le paramètre `KEY` stocké précédemment pour l'application `APP`. -> Par exemple : -> ```bash -> is_public=$(ynh_app_setting_get nom_app is_public) -> ``` - - -```bash -ynh_app_setting_delete APP KEY -``` -> Supprime le paramètre `KEY` enregistré pour l'application `APP`. - - -#### Gestion des utilisateurs -```bash -ynh_user_exists USERNAME -``` -> Vérifie l'existence de l'utilisateur `USERNAME` dans Yunohost. -> La sortie de la commande doit être testée pour en connaître le résultat. Par exemple : -> ```bash -> if ynh_user_exists "johndoe" ; then -> echo "L'utilisateur existe !" -> fi -> ``` - - -```bash -ynh_user_get_info USERNAME KEY -``` -> Récupère l'information `KEY` sur l'utilisateur `USERNAME`. -> Les valeurs possibles de `KEY` sont : -> - firstname -> - fullname -> - lastname -> - mail -> - mail-aliases -> - mailbox-quota -> Par exemple : -> ```bash -> mailadmin=$(ynh_user_get_info $admin mail) -> ``` - - -```bash -ynh_system_user_exists USERNAME -``` -> Détermine si l'utilisateur `USERNAME` existe sur le système. -> La sortie de la commande doit être testée pour en connaître le résultat. Par exemple : -> ```bash -> if ynh_system_user_exists "www-data" ; then -> echo "L'utilisateur existe sur le système !" -> fi -> ``` - - -```bash -ynh_system_user_create USER_NAME [HOME_DIR] -``` -> Créer l'utilisateur système `USER_NAME`, si il n'existe pas déjà. -> Si aucun dossier home n'est mentionné, l'utilisateur sera créé sans home. -> **Nécessite YunoHost version 2.6** - - -```bash -ynh_system_user_delete USER_NAME -``` -> Supprime l'utilisateur système `USER_NAME`. -> **Nécessite YunoHost version 2.6** - - -#### Gestion des ports -```bash -ynh_find_port BEGIN_PORT -``` -> Cherche un port libre en commençant par `BEGIN_PORT` -> Le numéro de port trouvé est renvoyé en fin de commande. -> ```bash -> port=$(ynh_find_port 8080) -> ``` -> **Nécessite YunoHost version 2.6** - - -#### Configuration système -```bash -ynh_use_logrotate [LOGFILE] [--non-append] -``` -> Créer un fichier de configuration logrotate pour cette application. -Si `LOGFILE` est renseigné, ce fichier de log sera utilisé. Sinon, la configuration concernera le dossier de log /var/log/${app}. -Si `--non-append` est ajouté, le fichier de configuration logrotate sera effacé puis recréé. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_remove_logrotate -``` -> Supprime la configuration logrotate pour cette application. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_add_systemd_config -``` -> Utilise la configuration systemd présente dans conf/systemd.service pour configurer un service. -Les termes `__APP__` et `__FINALPATH__` sont remplacés respectivement par $app et $final_path. -Le fichier de configuration est copié dans /etc/systemd/system/$app.service et le service est activé. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_remove_systemd_config -``` -> Supprime la configuration systemd pour cette application. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_add_nginx_config -``` -> Utilise la configuration nginx présente dans conf/nginx.conf. -Les termes suivant sont remplacés `__PATH__` par $path_url, `__DOMAIN__` par $domain, `__PORT__` par $port, `__NAME__` par $app et `__FINALPATH__` par $final_path. -Le fichier de configuration est copié dans /etc/nginx/conf.d/$domain.d/$app.conf et nginx est rechargé. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_remove_nginx_config -``` -> Supprime la configuration nginx pour cette application. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_add_fpm_config -``` -> Utilise la configuration phpfpm présente dans conf/php-fpm.conf. -Les termes suivant sont remplacés `__NAMETOCHANGE__` par $app, `__FINALPATH__` par $final_path et `__USER__` par $app. -Le fichier de configuration est copié dans /etc/php5/fpm/pool.d/$app.conf. -Le fichier conf/php-fpm.ini est copié dans /etc/php5/fpm/conf.d/20-$app.ini et php-fpm est rechargé. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_remove_fpm_config -``` -> Supprime la configuration php-fpm pour cette application. -> **Nécessite YunoHost version 2.6.4** - - -#### Backup/restore -```bash -ynh_backup DEST -``` -> Ajoute le fichier ou dossier `DEST` à la liste des fichiers à ajouter au backup de l'application. -`DEST` doit être un chemin absolu. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_restore_file DEST -``` -> Restaure le fichier ou dossier `DEST`. -`DEST` doit être un chemin absolu. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_restore -``` -> Restaure tous les fichiers archivés par le script backup. -> **Nécessite YunoHost version 2.6.4** - - -#### Gestion des erreurs -```bash -ynh_abort_if_errors -``` -> Stop immédiatement l'exécution du script si une commande échoue ou si une variable non initialisée est utilisée. -> **Nécessite YunoHost version 2.6.4** -> Si le script risque de laisser des résidus lors de son arrêt, il est possible d'utiliser la fonction `ynh_clean_setup` pour exécuter des commandes avant l'arrêt effectif du script. -> ```bash -> ynh_clean_setup () { -> instructions... -> } -> ``` - - -```bash -ynh_backup_before_upgrade -``` -> Créer un backup de l'application avant de démarrer l'upgrade. -> **Nécessite YunoHost version 2.6.4** -```bash -ynh_restore_upgradebackup -``` -> Restaure le backup créé par ynh_backup_before_upgrade en cas d'échec de l'upgrade. -> **Nécessite YunoHost version 2.6.4** -> Ces 2 helpers s'utilisent de la manière suivante: -> ```bash -> ynh_backup_before_upgrade -> ynh_clean_setup () { -> ynh_restore_upgradebackup -> } -> ynh_abort_if_errors -> ``` - - -#### Vérification du path -```bash -ynh_normalize_url_path PATH -``` -> Corrige le path et renvoi le résultat. -> ```bash -> url_path=$(ynh_normalize_url_path $url_path) -> ``` -> Le path est corrigé de la manière suivante -> example -> /example -> /example -> /example -> /example/ -> /example -> / -> / -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_webpath_available DOMAIN PATH -``` -> Vérifie la disponibilité du path demandé. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_webpath_register APP DOMAIN PATH -``` -> Réserve le path demandé pour cette application. -> **Nécessite YunoHost version 2.6.4** - - -#### Autres commandes -```bash -ynh_string_random LENGTH -``` -> Génère une chaine de caractères aléatoires de longueur `LENGTH` (par défaut 24). - - -```bash -ynh_die MSG RETCODE -``` -> Affiche le message `MSG` (sur stderr) et termine le script avec le code `RETCODE` (par défaut 1). - - -```bash -ynh_store_file_checksum FILE -``` -> Calcule la somme de contrôle du fichier FILE et la stocke dans la configuration de l'app. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_backup_if_checksum_is_different FILE -``` -> Compare la somme de contrôle du fichier FILE avec la somme de contrôle précédemment stockée par ynh_store_file_checksum. -> Si la somme de contrôle est différente, un backup du fichier est fait. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_secure_remove FILE -``` -> Supprime le fichier ou dossier FILE en vérifiant que ce n'est pas un dossier système sensible. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_replace_string MATCH_STRING REPLACE_STRING TARGET_FILE -``` -> Remplace toute les occurences de la chaine `MATCH_STRING` par `REPLACE_STRING` dans le fichier `TARGET_FILE`. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_local_curl URL KEY1=VALUE1 KEY2=VALUE2 ... -``` -> Effectue une requête curl sur la page `URL` et renseigne les champs POST `KEY1`, `KEY2`, etc par `VALUE1`, `VALUE2`, etc. -> Ce helper est surtout utilisé pour remplir les formulaires d'installation des applications. -> `URL` ne doit pas contenir le domaine et le path. -> **Nécessite YunoHost version 2.6.4** - - -```bash -ynh_setup_source DEST_DIR [SOURCE_ID] -``` -> Télécharge la source de l'application, vérifie la somme de contrôle, la décompresse et la copie dans le dossier `DEST_DIR`. -> Si SOURCE_ID n'est pas renseigné, il prend la valeur `app`. -> Ce helper nécessite un fichier [conf/SOURCE_ID.src](https://github.com/YunoHost/example_ynh/blob/master/conf/app.src) indiquant les informations sur la source à télécharger. -> **Nécessite YunoHost version 2.6.4** - -
- -**Les commandes suivantes sont amenées à être remplacées (voir supprimées) dans les prochaines versions de YunoHost.** - - -```bash -sudo yunohost firewall allow [--no-upnp] {TCP,UDP,Both} PORT -``` -> Ouvre le port `PORT` sur le parefeu en TCP, UDP ou les deux. -> L'ouverture automatique des ports via upnp peux être désactivé sur ce port en spécifiant l'option `--no-upnp`. - - -```bash -sudo yunohost firewall disallow {TCP,UDP,Both} PORT -``` -> Ferme le port `PORT` sur le parefeu en TCP, UDP ou les deux. - - -```bash -sudo yunohost app checkurl DOMAINPATH -a APP -``` -> Vérifie la disponibilité du chemin DOMAIN/PATH. Il est utile pour les applications web et vous permet d’être sûr que le chemin n’est pas utilisé par une autre application. Si le chemin est inutilisé, elle le « réserve » pour l'application APP. -> **Remarque** : ne pas préfixer par `http://` ou par `https://` dans le `DOMAINPATH`. - - -```bash -sudo yunohost app addaccess APP [--users=USER] -``` -> Autorise l'utilisateur `USER` à accéder à l'application `APP`. -> Si l'option `--users` n'est pas spécifiée, l'accès à l'application `APP` est accordé à tout les utilisateurs. - -> il est aussi possible de rajouter plusieurs utilisateurs à plusieurs apps d'un coup, par exemple : -```bash -sudo yunohost app addaccess app1 app2 -u user1 user2 -``` - -```bash -sudo yunohost app removeaccess APP --users=USER -``` -> Retire l'autorisation d'accès de l'utilisateur `USER` à l'application `APP`. - -> de la même manière que pour addaccess, il est aussi possible de retirer plusieurs utilisateurs à plusieurs apps d'un coup, par exemple : -```bash -sudo yunohost app removeaccess app1 app2 -u user1 user2 -``` - -```bash -sudo yunohost service add NAME [-l LOG] -``` -> Ajoute le service `NAME` dans l'interface de gestion admin de YunoHost. -> Le fichier de log du service peux être ajouté avec l'option `-l` en indiquant son chemin absolu. - - -```bash -sudo yunohost service remove NAME -``` -> Retire le service `NAME` dans l'interface de gestion admin de YunoHost. - - -```bash -sudo yunohost app ssowatconf -``` -> Cette commande régénère la configuration du SSO. Elle est appelée automatiquement à la fin du script. -> Mais peux être appelée avant si nécessaire.