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.logIt'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
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/
Usage: ynh_remove_systemd_config [service]
Arguments:
service
: Service name (optionnal, $app by default)
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_pathAnd dynamic variables (from the last example) : __PATH_2__ by $path_2 __PORT_2__ by $port_2
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 indest
: destination file or directory inside theis_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 anapp packageDetails: ynh_backup writes SRC and the relative DEST into a CSV file. And itcreates the parent destination directoryIf 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"
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 beforeDEST_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 atthe 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"
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
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
Usage: ynh_secure_remove path_to_remove
Arguments:
path_to_remove
: File or directory to remove
Usage: ynh_validate_ip [family] [ip_address]
Returns: 0 for valid ip addresses, 1 otherwise
Example: ynh_validate_ip 4 111.222.333.444
Usage: ynh_validate_ip4
Returns: 0 for valid ipv4 addresses, 1 otherwise
Example: ynh_validate_ip4 111.222.333.444
Usage: ynh_validate_ip6
Returns: 0 for valid ipv6 addresses, 1 otherwise
Example: ynh_validate_ip6 2000:dead:beef::1
Usage: ynh_mysql_connect_as user pwd [db]
Arguments:
user
: the user name to connect aspwd
: the user passworddb
: the database to connect to
Example: ynh_mysql_connect_as 'user' 'pass' <<< "UPDATE ...;" example: ynh_mysql_connect_as 'user' 'pass' < /path/to/file.sql
Usage: ynh_mysql_execute_as_root sql [db]
Arguments:
sql
: the SQL command to executedb
: the database to connect to
Usage: ynh_mysql_execute_file_as_root file [db]
Arguments:
file
: the file containing SQL commandsdb
: the database to connect to
Usage: ynh_mysql_dump_db db
Arguments:
db
: the database name to dumpReturns: the mysqldump output
Example: ynh_mysql_dump_db 'roundcube' > ./dump.sql
Usage: ynh_mysql_user_exists user
Arguments:
user
: the user for which to check existence
Usage: ynh_mysql_setup_db user name [pwd]
Arguments:
user
: Owner of the databasename
: Name of the databasepwd
: Password of the database. If not given, a password will be generatedDetails:
After executing this helper, the password of the created database will be available in $db_pwdIt will also be stored as "mysqlpwd" into the app settings.
Usage: ynh_mysql_remove_db user name
Arguments:
user
: Owner of the databasename
: Name of the database
Usage: ynh_sanitize_dbid name
Arguments:
name
: name to correct/sanitizeReturns: the corrected name
Example: dbname=$(ynh_sanitize_dbid $app)
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 / -> /
Usage: ynh_find_port begin_port
Arguments:
begin_port
: port to start to search
Example: port=$(ynh_find_port 8080)
Usage: ynh_webpath_available domain path
Arguments:
domain
: the domain/host of the urlpath
: the web path to check the availability of
Example: ynh_webpath_available some.domain.tld /coffee
Usage: ynh_webpath_register app domain path
Arguments:
app
: the app for which the domain should be registereddomain
: the domain/host of the web pathpath
: the web path to be registered
Example: ynh_webpath_register wordpress some.domain.tld /coffee
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.
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 versionynh_install_nodejs will install the version of node provided as argument by using n.
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.
Usage: ynh_package_is_installed name
Arguments:
name
: the package name to check
Example: ynh_package_is_installed 'yunohost' && echo "ok"
Usage: ynh_package_version name
Arguments:
name
: the package name to get versionReturns: the version or an empty string
Example: version=$(ynh_package_version 'yunohost')
Usage: ynh_package_install name [name [...]]
Arguments:
name
: the package name to install
Usage: ynh_package_remove name [name [...]]
Arguments:
name
: the package name to remove
Usage: ynh_package_autoremove name [name [...]]
Arguments:
name
: the package name to remove
Usage: ynh_package_autopurge name [name [...]]
Arguments:
name
: the package name to autoremove and purge
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
Usage: ynh_remove_app_dependencies
Details:
Dependencies will removed only if no other package need them.
Usage: ynh_psql_connect_as user pwd [db]
Arguments:
user
: the user name to connect aspwd
: the user passworddb
: the database to connect to
Example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql
Usage: ynh_psql_execute_as_root sql [db]
Arguments:
sql
: the SQL command to execute
Usage: ynh_psql_execute_file_as_root file [db]
Arguments:
file
: the file containing SQL commandsdb
: the database to connect to
Usage: ynh_psql_setup_db user name [pwd]
Arguments:
user
: Owner of the databasename
: Name of the databasepwd
: Password of the database. If not given, a password will be generatedDetails:
After executing this helper, the password of the created database will be available in $db_pwdIt will also be stored as "psqlpwd" into the app settings.
Usage: ynh_psql_create_db db [user [pwd]]
Arguments:
db
: the database name to createuser
: the user to grant privilegiespwd
: the user password
Usage: ynh_psql_drop_db db
Arguments:
db
: the database name to dropuser
: the user to drop
Usage: ynh_psql_dump_db db
Arguments:
db
: the database name to dumpReturns: the psqldump output
Example: ynh_psql_dump_db 'roundcube' > ./dump.sql
Usage: ynh_psql_create_user user pwd [host]
Arguments:
user
: the user name to create
Usage: ynh_app_setting_get app key
Arguments:
app
: the application idkey
: the setting to get
Usage: ynh_app_setting_set app key value
Arguments:
app
: the application idkey
: the setting name to setvalue
: the setting value to set
Usage: ynh_app_setting_delete app key
Arguments:
app
: the application idkey
: the setting to delete
Usage: ynh_string_random [length]
Arguments:
length
: the string length to generate (default: 24)
Example: pwd=$(ynh_string_random 8)
Usage: ynh_replace_string match_string replace_string target_file
Arguments:
match_string
: String to be searched and replaced in the filereplace_string
: String that will replace matchestarget_file
: File in which the string will be replaced.Details:
As this helper is based on sed command, regular expressions andreferences to sub-expressions can be used(see sed manual page for more information)
Usage: ynh_replace_special_string match_string replace_string target_file
Arguments:
match_string
: String to be searched and replaced in the filereplace_string
: String that will replace matchestarget_file
: File in which the string will be replaced.Details:
This helper will use ynh_replace_string, but as you can use specialcharacters, you can't use some regular expressions and sub-expressions.
Usage: ynh_abort_if_errors
Details:
This configure the rest of the script execution such that, if an error occursor if an empty variable is used, the execution of the script stopsimmediately and a call to `ynh_clean_setup` is triggered if it has beendefined by your script.
Usage: ynh_get_debian_release
Returns: The Debian release codename (i.e. jessie, stretch, ...)
Usage: ynh_user_exists username
Arguments:
username
: the username to check
Example: ynh_user_exists 'toto' || exit 1
Usage: ynh_user_get_info username key
Arguments:
username
: the username to retrieve info fromkey
: the key to retrieveReturns: string - the key's value
Example: mail=$(ynh_user_get_info 'toto' 'mail')
Usage: ynh_user_list
Returns: string - one username per line
Example: for u in $(ynh_user_list); do ...
Usage: ynh_system_user_exists username
Arguments:
username
: the username to check
Usage: ynh_system_user_create user_name [home_dir]
Arguments:
user_name
: Name of the system user that will be createhome_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
Usage: ynh_system_user_delete user_name
Arguments:
user_name
: Name of the system user that will be create
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
Usage: ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_restore_upgradebackup
}
ynh_abort_if_errors
Usage: ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_restore_upgradebackup
}
ynh_abort_if_errors
Usage: ynh_setup_source dest_dir [source_id]
Arguments:
dest_dir
: Directory where to setup sourcessource_id
: Name of the app, if the package contains more than one appDetails:
The file conf/app.src need to contains:SOURCE_URL=Address to download the app archiveSOURCE_SUM=Control sum# (Optional) Program to check the integrity (sha256sum, md5sum...)# default: sha256SOURCE_SUM_PRG=sha256# (Optional) Archive format# default: tar.gzSOURCE_FORMAT=tar.gz# (Optional) Put false if sources are directly in the archive root# default: trueSOURCE_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: trueSOURCE_EXTRACT=(true|false)Details:This helper downloads sources from SOURCE_URL if there is no local sourcearchive in /opt/yunohost-apps-src/APP_ID/SOURCE_FILENAMENext, 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 theSOURCE_IN_SUBDIR is true, the first level directory of the archive will beremoved.Finally, patches named sources/patches/${src_id}-*.patch and extra files insources/extra_files/$src_id will be applied to dest_dir
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 sentkey1=value1
: (Optionnal) POST key and corresponding valuekey2=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?))
Usage: ynh_render_template some_template output_path
Arguments:
some_template
: Template file to be renderedoutput_path
: The path where the output will be redirected toDetails:
Attention : Variables should be exported before calling this helper to beaccessible inside templates.