Add min version for all helpers

This commit is contained in:
Maniack Crudelis 2019-02-25 18:44:21 +01:00
parent fa4023283b
commit 873bf4ae37
16 changed files with 193 additions and 0 deletions

View file

@ -14,6 +14,8 @@
# #
# It's possible to use this helper several times, each config will be added to the same logrotate config file. # 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 # Unless you use the option --non-append
#
# Requires YunoHost version 2.6.4 or higher.
ynh_use_logrotate () { ynh_use_logrotate () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=lnuya local legacy_args=lnuya
@ -92,6 +94,8 @@ EOF
# Remove the app's logrotate config. # Remove the app's logrotate config.
# #
# usage: ynh_remove_logrotate # usage: ynh_remove_logrotate
#
# Requires YunoHost version 2.6.4 or higher.
ynh_remove_logrotate () { ynh_remove_logrotate () {
if [ -e "/etc/logrotate.d/$app" ]; then if [ -e "/etc/logrotate.d/$app" ]; then
sudo rm "/etc/logrotate.d/$app" sudo rm "/etc/logrotate.d/$app"
@ -112,6 +116,7 @@ ynh_remove_logrotate () {
# __APP__ by $app # __APP__ by $app
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# #
# Requires YunoHost version 2.7.2 or higher.
ynh_add_systemd_config () { ynh_add_systemd_config () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=st local legacy_args=st
@ -147,6 +152,7 @@ ynh_add_systemd_config () {
# usage: ynh_remove_systemd_config [--service=service] # usage: ynh_remove_systemd_config [--service=service]
# | arg: -s, --service - Service name (optionnal, $app by default) # | arg: -s, --service - Service name (optionnal, $app by default)
# #
# Requires YunoHost version 2.7.2 or higher.
ynh_remove_systemd_config () { ynh_remove_systemd_config () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=s local legacy_args=s
@ -183,6 +189,7 @@ ynh_remove_systemd_config () {
# __PATH_2__ by $path_2 # __PATH_2__ by $path_2
# __PORT_2__ by $port_2 # __PORT_2__ by $port_2
# #
# Requires YunoHost version 2.7.2 or higher.
ynh_add_nginx_config () { ynh_add_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
local others_var=${1:-} local others_var=${1:-}
@ -233,6 +240,8 @@ ynh_add_nginx_config () {
# Remove the dedicated nginx config # Remove the dedicated nginx config
# #
# usage: ynh_remove_nginx_config # usage: ynh_remove_nginx_config
#
# Requires YunoHost version 2.7.2 or higher.
ynh_remove_nginx_config () { ynh_remove_nginx_config () {
ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx sudo systemctl reload nginx
@ -241,6 +250,8 @@ ynh_remove_nginx_config () {
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
# #
# usage: ynh_add_fpm_config # usage: ynh_add_fpm_config
#
# Requires YunoHost version 2.7.2 or higher.
ynh_add_fpm_config () { ynh_add_fpm_config () {
# Configure PHP-FPM 7.0 by default # Configure PHP-FPM 7.0 by default
local fpm_config_dir="/etc/php/7.0/fpm" local fpm_config_dir="/etc/php/7.0/fpm"
@ -276,6 +287,8 @@ ynh_add_fpm_config () {
# Remove the dedicated php-fpm config # Remove the dedicated php-fpm config
# #
# usage: ynh_remove_fpm_config # usage: ynh_remove_fpm_config
#
# Requires YunoHost version 2.7.2 or higher.
ynh_remove_fpm_config () { ynh_remove_fpm_config () {
local fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir) local fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
local fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service) local fpm_service=$(ynh_app_setting_get --app=$app --key=fpm_service)
@ -350,6 +363,7 @@ ynh_remove_fpm_config () {
# To validate your regex you can test with this command: # To validate your regex you can test with this command:
# fail2ban-regex /var/log/YOUR_LOG_FILE_PATH /etc/fail2ban/filter.d/YOUR_APP.conf # fail2ban-regex /var/log/YOUR_LOG_FILE_PATH /etc/fail2ban/filter.d/YOUR_APP.conf
# #
# Requires YunoHost version 3.?.? or higher.
ynh_add_fail2ban_config () { ynh_add_fail2ban_config () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template [v]=others_var=) declare -Ar args_array=( [l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template [v]=others_var=)
@ -429,6 +443,8 @@ EOF
# Remove the dedicated fail2ban config (jail and filter conf files) # Remove the dedicated fail2ban config (jail and filter conf files)
# #
# usage: ynh_remove_fail2ban_config # usage: ynh_remove_fail2ban_config
#
# Requires YunoHost version 3.?.? or higher.
ynh_remove_fail2ban_config () { ynh_remove_fail2ban_config () {
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"

View file

@ -5,6 +5,8 @@
# usage: ynh_debug [--message=message] [--trace=1/0] # usage: ynh_debug [--message=message] [--trace=1/0]
# | arg: -m, --message= - The text to print # | arg: -m, --message= - The text to print
# | arg: -t, --trace= - Turn on or off the trace of the script. Usefull to trace nonly a small part of a script. # | arg: -t, --trace= - Turn on or off the trace of the script. Usefull to trace nonly a small part of a script.
#
# Requires YunoHost version 3.?.? or higher.
ynh_debug () { ynh_debug () {
# Disable set xtrace for the helper itself, to not pollute the debug log # Disable set xtrace for the helper itself, to not pollute the debug log
set +x set +x
@ -54,6 +56,8 @@ ynh_debug () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.?.? or higher.
ynh_debug_exec () { ynh_debug_exec () {
ynh_debug --message="$(eval $@)" ynh_debug --message="$(eval $@)"
} }

View file

@ -46,6 +46,7 @@ CAN_BIND=${CAN_BIND:-1}
# ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/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" # # => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf"
# #
# Requires YunoHost version 2.4.0 or higher.
ynh_backup() { ynh_backup() {
# TODO find a way to avoid injection by file strange naming ! # TODO find a way to avoid injection by file strange naming !
@ -158,6 +159,7 @@ ynh_backup() {
# #
# usage: ynh_restore # usage: ynh_restore
# #
# Requires YunoHost version 2.6.4 or higher.
ynh_restore () { ynh_restore () {
# Deduce the relative path of $YNH_CWD # Deduce the relative path of $YNH_CWD
local REL_DIR="${YNH_CWD#$YNH_BACKUP_DIR/}" local REL_DIR="${YNH_CWD#$YNH_BACKUP_DIR/}"
@ -219,6 +221,7 @@ with open(sys.argv[1], 'r') as backup_file:
# # DON'T GIVE THE ARCHIVE PATH: # # DON'T GIVE THE ARCHIVE PATH:
# ynh_restore_file "conf/nginx.conf" # ynh_restore_file "conf/nginx.conf"
# #
# Requires YunoHost version 2.6.4 or higher.
ynh_restore_file () { ynh_restore_file () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=odm local legacy_args=odm
@ -313,6 +316,8 @@ properly with chmod/chown." >&2
# #
# usage: ynh_store_file_checksum --file=file # usage: ynh_store_file_checksum --file=file
# | arg: -f, --file - The file on which the checksum will performed, then stored. # | arg: -f, --file - The file on which the checksum will performed, then stored.
#
# Requires YunoHost version 2.6.4 or higher.
ynh_store_file_checksum () { ynh_store_file_checksum () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=f local legacy_args=f
@ -345,6 +350,8 @@ ynh_store_file_checksum () {
# | arg: -f, --file - The file on which the checksum test will be perfomed. # | arg: -f, --file - The file on which the checksum test will be perfomed.
# #
# | ret: Return the name a the backup file, or nothing # | ret: Return the name a the backup file, or nothing
#
# Requires YunoHost version 2.6.4 or higher.
ynh_backup_if_checksum_is_different () { ynh_backup_if_checksum_is_different () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=f local legacy_args=f
@ -376,6 +383,8 @@ ynh_backup_if_checksum_is_different () {
# #
# usage: ynh_remove_file_checksum file # usage: ynh_remove_file_checksum file
# | arg: -f, --file= - The file for which the checksum will be deleted # | arg: -f, --file= - The file for which the checksum will be deleted
#
# Requires YunoHost version 3.3.1 or higher.
ynh_delete_file_checksum () { ynh_delete_file_checksum () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=f local legacy_args=f
@ -392,6 +401,8 @@ ynh_delete_file_checksum () {
# #
# usage: ynh_secure_remove --file=path_to_remove # usage: ynh_secure_remove --file=path_to_remove
# | arg: -f, --file - File or directory to remove # | arg: -f, --file - File or directory to remove
#
# Requires YunoHost version 2.6.4 or higher.
ynh_secure_remove () { ynh_secure_remove () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=f local legacy_args=f

View file

@ -43,6 +43,8 @@
# To keep a retrocompatibility, a package can still call a helper, using getopts, with positional arguments. # To keep a retrocompatibility, a package can still call a helper, using getopts, with positional arguments.
# The "legacy mode" will manage the positional arguments and fill the variable in the same order than they are given in $args_array. # The "legacy mode" will manage the positional arguments and fill the variable in the same order than they are given in $args_array.
# e.g. for `my_helper "val1" val2`, arg1 will be filled with val1, and arg2 with val2. # e.g. for `my_helper "val1" val2`, arg1 will be filled with val1, and arg2 with val2.
#
# Requires YunoHost version 3.2.2 or higher.
ynh_handle_getopts_args () { ynh_handle_getopts_args () {
# Manage arguments only if there's some provided # Manage arguments only if there's some provided
set +x set +x

View file

@ -7,6 +7,7 @@
# #
# example: ynh_validate_ip 4 111.222.333.444 # example: ynh_validate_ip 4 111.222.333.444
# #
# Requires YunoHost version 2.2.4 or higher.
ynh_validate_ip() ynh_validate_ip()
{ {
# http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298 # http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298
@ -40,6 +41,7 @@ EOF
# usage: ynh_validate_ip4 --ip_address=ip_address # usage: ynh_validate_ip4 --ip_address=ip_address
# | ret: 0 for valid ipv4 addresses, 1 otherwise # | ret: 0 for valid ipv4 addresses, 1 otherwise
# #
# Requires YunoHost version 2.2.4 or higher.
ynh_validate_ip4() ynh_validate_ip4()
{ {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
@ -60,6 +62,7 @@ ynh_validate_ip4()
# usage: ynh_validate_ip6 --ip_address=ip_address # usage: ynh_validate_ip6 --ip_address=ip_address
# | ret: 0 for valid ipv6 addresses, 1 otherwise # | ret: 0 for valid ipv6 addresses, 1 otherwise
# #
# Requires YunoHost version 2.2.4 or higher.
ynh_validate_ip6() ynh_validate_ip6()
{ {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.

View file

@ -11,6 +11,8 @@ MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql
# | arg: -u, --user - the user name to connect as # | arg: -u, --user - the user name to connect as
# | arg: -p, --password - the user password # | arg: -p, --password - the user password
# | arg: -d, --database - the database to connect to # | arg: -d, --database - the database to connect to
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_connect_as() { ynh_mysql_connect_as() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=upd local legacy_args=upd
@ -30,6 +32,8 @@ ynh_mysql_connect_as() {
# usage: ynh_mysql_execute_as_root --sql=sql [--database=database] # usage: ynh_mysql_execute_as_root --sql=sql [--database=database]
# | arg: -s, --sql - the SQL command to execute # | arg: -s, --sql - the SQL command to execute
# | arg: -d, --database - the database to connect to # | arg: -d, --database - the database to connect to
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_execute_as_root() { ynh_mysql_execute_as_root() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=sd local legacy_args=sd
@ -49,6 +53,8 @@ ynh_mysql_execute_as_root() {
# usage: ynh_mysql_execute_file_as_root --file=file [--database=database] # usage: ynh_mysql_execute_file_as_root --file=file [--database=database]
# | arg: -f, --file - the file containing SQL commands # | arg: -f, --file - the file containing SQL commands
# | arg: -d, --database - the database to connect to # | arg: -d, --database - the database to connect to
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_execute_file_as_root() { ynh_mysql_execute_file_as_root() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=fd local legacy_args=fd
@ -71,6 +77,8 @@ ynh_mysql_execute_file_as_root() {
# | arg: db - the database name to create # | arg: db - the database name to create
# | arg: user - the user to grant privilegies # | arg: user - the user to grant privilegies
# | arg: pwd - the password to identify user by # | arg: pwd - the password to identify user by
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_create_db() { ynh_mysql_create_db() {
local db=$1 local db=$1
@ -95,6 +103,8 @@ ynh_mysql_create_db() {
# #
# usage: ynh_mysql_drop_db db # usage: ynh_mysql_drop_db db
# | arg: db - the database name to drop # | arg: db - the database name to drop
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_drop_db() { ynh_mysql_drop_db() {
ynh_mysql_execute_as_root --sql="DROP DATABASE ${1};" ynh_mysql_execute_as_root --sql="DROP DATABASE ${1};"
} }
@ -106,6 +116,8 @@ ynh_mysql_drop_db() {
# usage: ynh_mysql_dump_db --database=database # usage: ynh_mysql_dump_db --database=database
# | arg: -d, --database - the database name to dump # | arg: -d, --database - the database name to dump
# | ret: the mysqldump output # | ret: the mysqldump output
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_dump_db() { ynh_mysql_dump_db() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=d local legacy_args=d
@ -124,6 +136,8 @@ ynh_mysql_dump_db() {
# usage: ynh_mysql_create_user user pwd [host] # usage: ynh_mysql_create_user user pwd [host]
# | arg: user - the user name to create # | arg: user - the user name to create
# | arg: pwd - the password to identify user by # | arg: pwd - the password to identify user by
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_create_user() { ynh_mysql_create_user() {
ynh_mysql_execute_as_root \ ynh_mysql_execute_as_root \
--sql="CREATE USER '${1}'@'localhost' IDENTIFIED BY '${2}';" --sql="CREATE USER '${1}'@'localhost' IDENTIFIED BY '${2}';"
@ -133,6 +147,8 @@ ynh_mysql_create_user() {
# #
# usage: ynh_mysql_user_exists --user=user # usage: ynh_mysql_user_exists --user=user
# | arg: -u, --user - the user for which to check existence # | arg: -u, --user - the user for which to check existence
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_user_exists() ynh_mysql_user_exists()
{ {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
@ -156,6 +172,8 @@ ynh_mysql_user_exists()
# #
# usage: ynh_mysql_drop_user user # usage: ynh_mysql_drop_user user
# | arg: user - the user name to drop # | arg: user - the user name to drop
#
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_drop_user() { ynh_mysql_drop_user() {
ynh_mysql_execute_as_root --sql="DROP USER '${1}'@'localhost';" ynh_mysql_execute_as_root --sql="DROP USER '${1}'@'localhost';"
} }
@ -169,6 +187,8 @@ ynh_mysql_drop_user() {
# | arg: -u, --db_user - Owner of the database # | arg: -u, --db_user - Owner of the database
# | arg: -n, --db_name - Name of the database # | arg: -n, --db_name - Name of the database
# | arg: -p, --db_pwd - Password of the database. If not given, a password will be generated # | arg: -p, --db_pwd - Password of the database. If not given, a password will be generated
#
# Requires YunoHost version 2.6.4 or higher.
ynh_mysql_setup_db () { ynh_mysql_setup_db () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=unp local legacy_args=unp
@ -192,6 +212,8 @@ ynh_mysql_setup_db () {
# usage: ynh_mysql_remove_db --db_user=user --db_name=name # usage: ynh_mysql_remove_db --db_user=user --db_name=name
# | arg: -u, --db_user - Owner of the database # | arg: -u, --db_user - Owner of the database
# | arg: -n, --db_name - Name of the database # | arg: -n, --db_name - Name of the database
#
# Requires YunoHost version 2.6.4 or higher.
ynh_mysql_remove_db () { ynh_mysql_remove_db () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=un local legacy_args=un
@ -223,6 +245,8 @@ ynh_mysql_remove_db () {
# usage: ynh_sanitize_dbid --db_name=name # usage: ynh_sanitize_dbid --db_name=name
# | arg: -n, --db_name - name to correct/sanitize # | arg: -n, --db_name - name to correct/sanitize
# | ret: the corrected name # | ret: the corrected name
#
# Requires YunoHost version 2.2.4 or higher.
ynh_sanitize_dbid () { ynh_sanitize_dbid () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=n local legacy_args=n

View file

@ -12,6 +12,8 @@
# #
# usage: ynh_normalize_url_path --path_url=path_to_normalize # usage: ynh_normalize_url_path --path_url=path_to_normalize
# | arg: -p, --path_url - URL path to normalize before using it # | arg: -p, --path_url - URL path to normalize before using it
#
# Requires YunoHost version 2.6.4 or higher.
ynh_normalize_url_path () { ynh_normalize_url_path () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=p local legacy_args=p
@ -36,6 +38,8 @@ ynh_normalize_url_path () {
# #
# usage: ynh_find_port --port=begin_port # usage: ynh_find_port --port=begin_port
# | arg: -p, --port - port to start to search # | arg: -p, --port - port to start to search
#
# Requires YunoHost version 2.6.4 or higher.
ynh_find_port () { ynh_find_port () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=p local legacy_args=p
@ -59,6 +63,8 @@ ynh_find_port () {
# usage: ynh_webpath_available --domain=domain --path_url=path # usage: ynh_webpath_available --domain=domain --path_url=path
# | arg: -d, --domain - the domain/host of the url # | arg: -d, --domain - the domain/host of the url
# | arg: -p, --path_url - the web path to check the availability of # | arg: -p, --path_url - the web path to check the availability of
#
# Requires YunoHost version 2.6.4 or higher.
ynh_webpath_available () { ynh_webpath_available () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=dp local legacy_args=dp
@ -79,6 +85,8 @@ ynh_webpath_available () {
# | arg: -a, --app - the app for which the domain should be registered # | arg: -a, --app - the app for which the domain should be registered
# | arg: -d, --domain - the domain/host of the web path # | arg: -d, --domain - the domain/host of the web path
# | arg: -p, --path_url - the web path to be registered # | arg: -p, --path_url - the web path to be registered
#
# Requires YunoHost version 2.6.4 or higher.
ynh_webpath_register () { ynh_webpath_register () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=adp local legacy_args=adp

View file

@ -10,6 +10,8 @@ export N_PREFIX="$n_install_dir"
# [internal] # [internal]
# #
# usage: ynh_install_n # usage: ynh_install_n
#
# Requires YunoHost version 2.7.12 or higher.
ynh_install_n () { ynh_install_n () {
echo "Installation of N - Node.js version management" >&2 echo "Installation of N - Node.js version management" >&2
# Build an app.src for n # Build an app.src for n
@ -36,6 +38,8 @@ SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "
# That's means it has to be added to any systemd script. # That's means it has to be added to any systemd script.
# #
# usage: ynh_use_nodejs # usage: ynh_use_nodejs
#
# Requires YunoHost version 2.7.12 or higher.
ynh_use_nodejs () { ynh_use_nodejs () {
nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version)
@ -59,6 +63,8 @@ ynh_use_nodejs () {
# | arg: -n, --nodejs_version - Version of node to install. # | arg: -n, --nodejs_version - Version of node to install.
# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0). # 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. # The crontab will handle the update of minor versions when needed.
#
# Requires YunoHost version 2.7.12 or higher.
ynh_install_nodejs () { ynh_install_nodejs () {
# Use n, https://github.com/tj/n to manage the nodejs versions # Use n, https://github.com/tj/n to manage the nodejs versions
@ -135,6 +141,8 @@ ynh_install_nodejs () {
# If no other app uses node, n will be also removed. # If no other app uses node, n will be also removed.
# #
# usage: ynh_remove_nodejs # usage: ynh_remove_nodejs
#
# Requires YunoHost version 2.7.12 or higher.
ynh_remove_nodejs () { ynh_remove_nodejs () {
nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version)
@ -164,6 +172,8 @@ ynh_remove_nodejs () {
# This cron will check and update all minor node versions used by your apps. # This cron will check and update all minor node versions used by your apps.
# #
# usage: ynh_cron_upgrade_node # usage: ynh_cron_upgrade_node
#
# Requires YunoHost version 2.7.12 or higher.
ynh_cron_upgrade_node () { ynh_cron_upgrade_node () {
# Build the update script # Build the update script
cat > "$n_install_dir/node_update.sh" << EOF cat > "$n_install_dir/node_update.sh" << EOF

View file

@ -5,6 +5,8 @@
# [internal] # [internal]
# #
# usage: ynh_wait_dpkg_free # usage: ynh_wait_dpkg_free
#
# Requires YunoHost version 3.3.1 or higher.
ynh_wait_dpkg_free() { ynh_wait_dpkg_free() {
local try local try
# With seq 1 17, timeout will be almost 30 minutes # With seq 1 17, timeout will be almost 30 minutes
@ -44,6 +46,8 @@ ynh_wait_dpkg_free() {
# #
# usage: ynh_package_is_installed --package=name # usage: ynh_package_is_installed --package=name
# | arg: -p, --package - the package name to check # | arg: -p, --package - the package name to check
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_is_installed() { ynh_package_is_installed() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=p local legacy_args=p
@ -64,6 +68,8 @@ ynh_package_is_installed() {
# usage: ynh_package_version --package=name # usage: ynh_package_version --package=name
# | arg: -p, --package - the package name to get version # | arg: -p, --package - the package name to get version
# | ret: the version or an empty string # | ret: the version or an empty string
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_version() { ynh_package_version() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=p local legacy_args=p
@ -84,6 +90,8 @@ ynh_package_version() {
# [internal] # [internal]
# #
# usage: ynh_apt update # usage: ynh_apt update
#
# Requires YunoHost version 2.4.0.3 or higher.
ynh_apt() { ynh_apt() {
ynh_wait_dpkg_free ynh_wait_dpkg_free
DEBIAN_FRONTEND=noninteractive apt-get -y $@ DEBIAN_FRONTEND=noninteractive apt-get -y $@
@ -92,6 +100,8 @@ ynh_apt() {
# Update package index files # Update package index files
# #
# usage: ynh_package_update # usage: ynh_package_update
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_update() { ynh_package_update() {
ynh_apt update ynh_apt update
} }
@ -100,6 +110,8 @@ ynh_package_update() {
# #
# usage: ynh_package_install name [name [...]] # usage: ynh_package_install name [name [...]]
# | arg: name - the package name to install # | arg: name - the package name to install
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_install() { ynh_package_install() {
ynh_apt --no-remove -o Dpkg::Options::=--force-confdef \ ynh_apt --no-remove -o Dpkg::Options::=--force-confdef \
-o Dpkg::Options::=--force-confold install $@ -o Dpkg::Options::=--force-confold install $@
@ -109,6 +121,8 @@ ynh_package_install() {
# #
# usage: ynh_package_remove name [name [...]] # usage: ynh_package_remove name [name [...]]
# | arg: name - the package name to remove # | arg: name - the package name to remove
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_remove() { ynh_package_remove() {
ynh_apt remove $@ ynh_apt remove $@
} }
@ -117,6 +131,8 @@ ynh_package_remove() {
# #
# usage: ynh_package_autoremove name [name [...]] # usage: ynh_package_autoremove name [name [...]]
# | arg: name - the package name to remove # | arg: name - the package name to remove
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_autoremove() { ynh_package_autoremove() {
ynh_apt autoremove $@ ynh_apt autoremove $@
} }
@ -125,6 +141,8 @@ ynh_package_autoremove() {
# #
# usage: ynh_package_autopurge name [name [...]] # usage: ynh_package_autopurge name [name [...]]
# | arg: name - the package name to autoremove and purge # | arg: name - the package name to autoremove and purge
#
# Requires YunoHost version 2.7.2 or higher.
ynh_package_autopurge() { ynh_package_autopurge() {
ynh_apt autoremove --purge $@ ynh_apt autoremove --purge $@
} }
@ -139,6 +157,8 @@ ynh_package_autopurge() {
# #
# usage: ynh_package_install_from_equivs controlfile # usage: ynh_package_install_from_equivs controlfile
# | arg: controlfile - path of the equivs control file # | arg: controlfile - path of the equivs control file
#
# Requires YunoHost version 2.2.4 or higher.
ynh_package_install_from_equivs () { ynh_package_install_from_equivs () {
local controlfile=$1 local controlfile=$1
@ -181,6 +201,8 @@ ynh_package_install_from_equivs () {
# You can give a choice between some package with this syntax : "dep1|dep2" # You can give a choice between some package with this syntax : "dep1|dep2"
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" # Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) # This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
#
# Requires YunoHost version 2.6.4 or higher.
ynh_install_app_dependencies () { ynh_install_app_dependencies () {
local dependencies=$@ local dependencies=$@
local dependencies=${dependencies// /, } local dependencies=${dependencies// /, }
@ -217,6 +239,8 @@ EOF
# Dependencies will removed only if no other package need them. # Dependencies will removed only if no other package need them.
# #
# usage: ynh_remove_app_dependencies # usage: ynh_remove_app_dependencies
#
# Requires YunoHost version 2.6.4 or higher.
ynh_remove_app_dependencies () { ynh_remove_app_dependencies () {
local dep_app=${app//_/-} # Replace all '_' by '-' local dep_app=${app//_/-} # Replace all '_' by '-'
ynh_package_autopurge ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used. ynh_package_autopurge ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.

View file

@ -2,6 +2,8 @@
# Print a message to stderr and exit # Print a message to stderr and exit
# usage: ynh_die --message=MSG [--ret_code=RETCODE] # usage: ynh_die --message=MSG [--ret_code=RETCODE]
#
# Requires YunoHost version 2.4.0 or higher.
ynh_die() { ynh_die() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=mc local legacy_args=mc
@ -18,6 +20,8 @@ ynh_die() {
# Display a message in the 'INFO' logging category # Display a message in the 'INFO' logging category
# #
# usage: ynh_print_info --message="Some message" # usage: ynh_print_info --message="Some message"
#
# Requires YunoHost version 3.2.0 or higher.
ynh_print_info() { ynh_print_info() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=m local legacy_args=m
@ -37,6 +41,8 @@ ynh_print_info() {
# #
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command # Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
# It's a very badly hack... # It's a very badly hack...
#
# Requires YunoHost version 2.6.4 or higher.
ynh_no_log() { ynh_no_log() {
local ynh_cli_log=/var/log/yunohost/yunohost-cli.log local ynh_cli_log=/var/log/yunohost/yunohost-cli.log
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
@ -50,6 +56,7 @@ ynh_no_log() {
# #
# [internal] # [internal]
# #
# Requires YunoHost version 3.2.0 or higher.
ynh_print_log () { ynh_print_log () {
echo -e "${1}" echo -e "${1}"
} }
@ -58,6 +65,8 @@ ynh_print_log () {
# #
# usage: ynh_print_warn --message="Text to print" # usage: ynh_print_warn --message="Text to print"
# | arg: -m, --message - The text to print # | arg: -m, --message - The text to print
#
# Requires YunoHost version 3.2.0 or higher.
ynh_print_warn () { ynh_print_warn () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=m local legacy_args=m
@ -73,6 +82,8 @@ ynh_print_warn () {
# #
# usage: ynh_print_err --message="Text to print" # usage: ynh_print_err --message="Text to print"
# | arg: -m, --message - The text to print # | arg: -m, --message - The text to print
#
# Requires YunoHost version 3.2.0 or higher.
ynh_print_err () { ynh_print_err () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=m local legacy_args=m
@ -91,6 +102,8 @@ ynh_print_err () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.2.0 or higher.
ynh_exec_err () { ynh_exec_err () {
ynh_print_err "$(eval $@)" ynh_print_err "$(eval $@)"
} }
@ -102,6 +115,8 @@ ynh_exec_err () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.2.0 or higher.
ynh_exec_warn () { ynh_exec_warn () {
ynh_print_warn "$(eval $@)" ynh_print_warn "$(eval $@)"
} }
@ -113,6 +128,8 @@ ynh_exec_warn () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.2.0 or higher.
ynh_exec_warn_less () { ynh_exec_warn_less () {
eval $@ 2>&1 eval $@ 2>&1
} }
@ -124,6 +141,8 @@ ynh_exec_warn_less () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.2.0 or higher.
ynh_exec_quiet () { ynh_exec_quiet () {
eval $@ > /dev/null eval $@ > /dev/null
} }
@ -135,6 +154,8 @@ ynh_exec_quiet () {
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be sent to the next pipe.
# #
# | arg: command - command to execute # | arg: command - command to execute
#
# Requires YunoHost version 3.2.0 or higher.
ynh_exec_fully_quiet () { ynh_exec_fully_quiet () {
eval $@ > /dev/null 2>&1 eval $@ > /dev/null 2>&1
} }
@ -143,6 +164,8 @@ ynh_exec_fully_quiet () {
# #
# usage: ynh_print_OFF # usage: ynh_print_OFF
# WARNING: You should be careful with this helper, and never forget to use ynh_print_ON as soon as possible to restore the logging. # WARNING: You should be careful with this helper, and never forget to use ynh_print_ON as soon as possible to restore the logging.
#
# Requires YunoHost version 3.2.0 or higher.
ynh_print_OFF () { ynh_print_OFF () {
set +x set +x
} }
@ -150,6 +173,8 @@ ynh_print_OFF () {
# Restore the logging after ynh_print_OFF # Restore the logging after ynh_print_OFF
# #
# usage: ynh_print_ON # usage: ynh_print_ON
#
# Requires YunoHost version 3.2.0 or higher.
ynh_print_ON () { ynh_print_ON () {
set -x set -x
# Print an echo only for the log, to be able to know that ynh_print_ON has been called. # Print an echo only for the log, to be able to know that ynh_print_ON has been called.
@ -163,6 +188,8 @@ ynh_print_ON () {
# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script. # | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights. # | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights.
# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar. # | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar.
#
# Requires YunoHost version 3.?.? or higher.
increment_progression=0 increment_progression=0
previous_weight=0 previous_weight=0
# Define base_time when the file is sourced # Define base_time when the file is sourced

View file

@ -2,6 +2,8 @@
# Please always call this script in install and restore scripts # Please always call this script in install and restore scripts
# #
# usage: ynh_psql_test_if_first_run # usage: ynh_psql_test_if_first_run
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_test_if_first_run() { ynh_psql_test_if_first_run() {
if [ -f /etc/yunohost/psql ]; if [ -f /etc/yunohost/psql ];
then then
@ -43,6 +45,8 @@ ynh_psql_test_if_first_run() {
# | arg: user - the user name to connect as # | arg: user - the user name to connect as
# | arg: pwd - the user password # | arg: pwd - the user password
# | arg: db - the database to connect to # | arg: db - the database to connect to
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_connect_as() { ynh_psql_connect_as() {
local user="$1" local user="$1"
local pwd="$2" local pwd="$2"
@ -54,6 +58,8 @@ ynh_psql_connect_as() {
# #
# usage: ynh_psql_execute_as_root sql [db] # usage: ynh_psql_execute_as_root sql [db]
# | arg: sql - the SQL command to execute # | arg: sql - the SQL command to execute
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_execute_as_root () { ynh_psql_execute_as_root () {
local sql="$1" local sql="$1"
sudo --login --user=postgres psql <<< "$sql" sudo --login --user=postgres psql <<< "$sql"
@ -64,6 +70,8 @@ ynh_psql_execute_as_root () {
# usage: ynh_psql_execute_file_as_root file [db] # usage: ynh_psql_execute_file_as_root file [db]
# | arg: file - the file containing SQL commands # | arg: file - the file containing SQL commands
# | arg: db - the database to connect to # | arg: db - the database to connect to
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_execute_file_as_root() { ynh_psql_execute_file_as_root() {
local file="$1" local file="$1"
local db="$2" local db="$2"
@ -79,6 +87,8 @@ ynh_psql_execute_file_as_root() {
# | arg: user - Owner of the database # | arg: user - Owner of the database
# | arg: name - Name of the database # | arg: name - Name of the database
# | arg: pwd - Password of the database. If not given, a password will be generated # | arg: pwd - Password of the database. If not given, a password will be generated
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_setup_db () { ynh_psql_setup_db () {
local db_user="$1" local db_user="$1"
local db_name="$2" local db_name="$2"
@ -95,6 +105,8 @@ ynh_psql_setup_db () {
# | arg: db - the database name to create # | arg: db - the database name to create
# | arg: user - the user to grant privilegies # | arg: user - the user to grant privilegies
# | arg: pwd - the user password # | arg: pwd - the user password
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_create_db() { ynh_psql_create_db() {
local db="$1" local db="$1"
local user="$2" local user="$2"
@ -108,6 +120,8 @@ ynh_psql_create_db() {
# usage: ynh_psql_drop_db db # usage: ynh_psql_drop_db db
# | arg: db - the database name to drop # | arg: db - the database name to drop
# | arg: user - the user to drop # | arg: user - the user to drop
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_remove_db() { ynh_psql_remove_db() {
local db="$1" local db="$1"
local user="$2" local user="$2"
@ -122,6 +136,8 @@ ynh_psql_remove_db() {
# usage: ynh_psql_dump_db db # usage: ynh_psql_dump_db db
# | arg: db - the database name to dump # | arg: db - the database name to dump
# | ret: the psqldump output # | ret: the psqldump output
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_dump_db() { ynh_psql_dump_db() {
local db="$1" local db="$1"
sudo --login --user=postgres pg_dump "$db" sudo --login --user=postgres pg_dump "$db"
@ -132,6 +148,8 @@ ynh_psql_dump_db() {
# #
# usage: ynh_psql_create_user user pwd [host] # usage: ynh_psql_create_user user pwd [host]
# | arg: user - the user name to create # | arg: user - the user name to create
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_create_user() { ynh_psql_create_user() {
local user="$1" local user="$1"
local pwd="$2" local pwd="$2"
@ -142,6 +160,8 @@ ynh_psql_create_user() {
# #
# usage: ynh_psql_drop_user user # usage: ynh_psql_drop_user user
# | arg: user - the user name to drop # | arg: user - the user name to drop
#
# Requires YunoHost version 3.?.? or higher.
ynh_psql_drop_user() { ynh_psql_drop_user() {
local user="$1" local user="$1"
sudo --login --user=postgres dropuser "$user" sudo --login --user=postgres dropuser "$user"

View file

@ -5,6 +5,8 @@
# usage: ynh_app_setting_get --app=app --key=key # usage: ynh_app_setting_get --app=app --key=key
# | arg: -a, --app - the application id # | arg: -a, --app - the application id
# | arg: -k, --key - the setting to get # | arg: -k, --key - the setting to get
#
# Requires YunoHost version 2.2.4 or higher.
ynh_app_setting_get() { ynh_app_setting_get() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=ak local legacy_args=ak
@ -23,6 +25,8 @@ ynh_app_setting_get() {
# | arg: -a, --app - the application id # | arg: -a, --app - the application id
# | arg: -k, --key - the setting name to set # | arg: -k, --key - the setting name to set
# | arg: -v, --value - the setting value to set # | arg: -v, --value - the setting value to set
#
# Requires YunoHost version 2.2.4 or higher.
ynh_app_setting_set() { ynh_app_setting_set() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=akv local legacy_args=akv
@ -41,6 +45,8 @@ ynh_app_setting_set() {
# usage: ynh_app_setting_delete --app=app --key=key # usage: ynh_app_setting_delete --app=app --key=key
# | arg: -a, --app - the application id # | arg: -a, --app - the application id
# | arg: -k, --key - the setting to delete # | arg: -k, --key - the setting to delete
#
# Requires YunoHost version 2.2.4 or higher.
ynh_app_setting_delete() { ynh_app_setting_delete() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=ak local legacy_args=ak

View file

@ -6,6 +6,8 @@
# #
# usage: ynh_string_random [--length=string_length] # usage: ynh_string_random [--length=string_length]
# | arg: -l, --length - the string length to generate (default: 24) # | arg: -l, --length - the string length to generate (default: 24)
#
# Requires YunoHost version 2.2.4 or higher.
ynh_string_random() { ynh_string_random() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=l local legacy_args=l
@ -30,6 +32,8 @@ ynh_string_random() {
# As this helper is based on sed command, regular expressions and # As this helper is based on sed command, regular expressions and
# references to sub-expressions can be used # references to sub-expressions can be used
# (see sed manual page for more information) # (see sed manual page for more information)
#
# Requires YunoHost version 2.6.4 or higher.
ynh_replace_string () { ynh_replace_string () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=mrf local legacy_args=mrf
@ -57,6 +61,8 @@ ynh_replace_string () {
# #
# This helper will use ynh_replace_string, but as you can use special # This helper will use ynh_replace_string, but as you can use special
# characters, you can't use some regular expressions and sub-expressions. # characters, you can't use some regular expressions and sub-expressions.
#
# Requires YunoHost version 2.7.7 or higher.
ynh_replace_special_string () { ynh_replace_special_string () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=mrf local legacy_args=mrf

View file

@ -16,6 +16,7 @@
# #
# It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script # It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script
# #
# Requires YunoHost version 2.6.4 or higher.
ynh_exit_properly () { ynh_exit_properly () {
local exit_code=$? local exit_code=$?
if [ "$exit_code" -eq 0 ]; then if [ "$exit_code" -eq 0 ]; then
@ -43,6 +44,7 @@ ynh_exit_properly () {
# immediately and a call to `ynh_clean_setup` is triggered if it has been # immediately and a call to `ynh_clean_setup` is triggered if it has been
# defined by your script. # defined by your script.
# #
# Requires YunoHost version 2.6.4 or higher.
ynh_abort_if_errors () { ynh_abort_if_errors () {
set -eu # Exit if a command fail, and if a variable is used unset. set -eu # Exit if a command fail, and if a variable is used unset.
trap ynh_exit_properly EXIT # Capturing exit signals on shell script trap ynh_exit_properly EXIT # Capturing exit signals on shell script
@ -52,6 +54,8 @@ ynh_abort_if_errors () {
# #
# usage: ynh_get_debian_release # usage: ynh_get_debian_release
# | ret: The Debian release codename (i.e. jessie, stretch, ...) # | ret: The Debian release codename (i.e. jessie, stretch, ...)
#
# Requires YunoHost version 2.7.12 or higher.
ynh_get_debian_release () { ynh_get_debian_release () {
echo $(lsb_release --codename --short) echo $(lsb_release --codename --short)
} }
@ -61,6 +65,8 @@ ynh_get_debian_release () {
# usage: ynh_read_manifest manifest key # usage: ynh_read_manifest manifest key
# | arg: -m, --manifest= - Path of the manifest to read # | arg: -m, --manifest= - Path of the manifest to read
# | arg: -k, --key= - Name of the key to find # | arg: -k, --key= - Name of the key to find
#
# Requires YunoHost version 3.?.? or higher.
ynh_read_manifest () { ynh_read_manifest () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=manifest= [k]=manifest_key= ) declare -Ar args_array=( [m]=manifest= [k]=manifest_key= )
@ -85,6 +91,8 @@ ynh_read_manifest () {
# #
# usage: ynh_app_upstream_version [-m manifest] # usage: ynh_app_upstream_version [-m manifest]
# | arg: -m, --manifest= - Path of the manifest to read # | arg: -m, --manifest= - Path of the manifest to read
#
# Requires YunoHost version 3.?.? or higher.
ynh_app_upstream_version () { ynh_app_upstream_version () {
declare -Ar args_array=( [m]=manifest= ) declare -Ar args_array=( [m]=manifest= )
local manifest local manifest
@ -104,6 +112,8 @@ ynh_app_upstream_version () {
# #
# usage: ynh_app_package_version [-m manifest] # usage: ynh_app_package_version [-m manifest]
# | arg: -m, --manifest= - Path of the manifest to read # | arg: -m, --manifest= - Path of the manifest to read
#
# Requires YunoHost version 3.?.? or higher.
ynh_app_package_version () { ynh_app_package_version () {
declare -Ar args_array=( [m]=manifest= ) declare -Ar args_array=( [m]=manifest= )
local manifest local manifest
@ -129,6 +139,8 @@ ynh_app_package_version () {
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp # example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
# #
# usage: ynh_check_app_version_changed # usage: ynh_check_app_version_changed
#
# Requires YunoHost version 3.?.? or higher.
ynh_check_app_version_changed () { ynh_check_app_version_changed () {
local force_upgrade=${YNH_FORCE_UPGRADE:-0} local force_upgrade=${YNH_FORCE_UPGRADE:-0}
local package_check=${PACKAGE_CHECK_EXEC:-0} local package_check=${PACKAGE_CHECK_EXEC:-0}

View file

@ -6,6 +6,8 @@
# #
# usage: ynh_user_exists --username=username # usage: ynh_user_exists --username=username
# | arg: -u, --username - the username to check # | arg: -u, --username - the username to check
#
# Requires YunoHost version 2.2.4 or higher.
ynh_user_exists() { ynh_user_exists() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=u local legacy_args=u
@ -25,6 +27,8 @@ ynh_user_exists() {
# | arg: -u, --username - the username to retrieve info from # | arg: -u, --username - the username to retrieve info from
# | arg: -k, --key - the key to retrieve # | arg: -k, --key - the key to retrieve
# | ret: string - the key's value # | ret: string - the key's value
#
# Requires YunoHost version 2.2.4 or higher.
ynh_user_get_info() { ynh_user_get_info() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=uk local legacy_args=uk
@ -43,6 +47,8 @@ ynh_user_get_info() {
# #
# usage: ynh_user_list # usage: ynh_user_list
# | ret: string - one username per line # | ret: string - one username per line
#
# Requires YunoHost version 2.4.0 or higher.
ynh_user_list() { ynh_user_list() {
sudo yunohost user list --output-as plain --quiet \ sudo yunohost user list --output-as plain --quiet \
| awk '/^##username$/{getline; print}' | awk '/^##username$/{getline; print}'
@ -52,6 +58,8 @@ ynh_user_list() {
# #
# usage: ynh_system_user_exists --username=username # usage: ynh_system_user_exists --username=username
# | arg: -u, --username - the username to check # | arg: -u, --username - the username to check
#
# Requires YunoHost version 2.2.4 or higher.
ynh_system_user_exists() { ynh_system_user_exists() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=u local legacy_args=u
@ -76,6 +84,8 @@ ynh_system_user_exists() {
# | arg: -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 # | arg: -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
# | arg: -s, --use_shell - Create a user using the default login shell if present. # | arg: -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 # If this argument is omitted, the user will be created with /usr/sbin/nologin shell
#
# Requires YunoHost version 2.6.4 or higher.
ynh_system_user_create () { ynh_system_user_create () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=uhs local legacy_args=uhs
@ -108,6 +118,8 @@ ynh_system_user_create () {
# #
# usage: ynh_system_user_delete --username=user_name # usage: ynh_system_user_delete --username=user_name
# | arg: -u, --username - Name of the system user that will be create # | arg: -u, --username - Name of the system user that will be create
#
# Requires YunoHost version 2.6.4 or higher.
ynh_system_user_delete () { ynh_system_user_delete () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=u local legacy_args=u

View file

@ -6,6 +6,8 @@
# #
# usage: ynh_get_plain_key key [subkey [subsubkey ...]] # usage: ynh_get_plain_key key [subkey [subsubkey ...]]
# | ret: string - the key's value # | ret: string - the key's value
#
# Requires YunoHost version 2.2.4 or higher.
ynh_get_plain_key() { ynh_get_plain_key() {
local prefix="#" local prefix="#"
local founded=0 local founded=0
@ -36,6 +38,7 @@ ynh_get_plain_key() {
# } # }
# ynh_abort_if_errors # ynh_abort_if_errors
# #
# Requires YunoHost version 2.7.2 or higher.
ynh_restore_upgradebackup () { ynh_restore_upgradebackup () {
echo "Upgrade failed." >&2 echo "Upgrade failed." >&2
local app_bck=${app//_/-} # Replace all '_' by '-' local app_bck=${app//_/-} # Replace all '_' by '-'
@ -67,6 +70,7 @@ ynh_restore_upgradebackup () {
# } # }
# ynh_abort_if_errors # ynh_abort_if_errors
# #
# Requires YunoHost version 2.7.2 or higher.
ynh_backup_before_upgrade () { ynh_backup_before_upgrade () {
if [ ! -e "/etc/yunohost/apps/$app/scripts/backup" ] if [ ! -e "/etc/yunohost/apps/$app/scripts/backup" ]
then then
@ -150,6 +154,8 @@ ynh_backup_before_upgrade () {
# usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] # usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id]
# | arg: -d, --dest_dir - Directory where to setup sources # | arg: -d, --dest_dir - Directory where to setup sources
# | arg: -s, --source_id - Name of the app, if the package contains more than one app # | arg: -s, --source_id - Name of the app, if the package contains more than one app
#
# Requires YunoHost version 2.6.4 or higher.
ynh_setup_source () { ynh_setup_source () {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=ds local legacy_args=ds
@ -255,6 +261,8 @@ ynh_setup_source () {
# | arg: key1=value1 - (Optionnal) POST key and corresponding value # | arg: key1=value1 - (Optionnal) POST key and corresponding value
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value # | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
# | arg: ... - (Optionnal) More POST keys and values # | arg: ... - (Optionnal) More POST keys and values
#
# Requires YunoHost version 2.6.4 or higher.
ynh_local_curl () { ynh_local_curl () {
# Define url of page to curl # Define url of page to curl
local local_page=$(ynh_normalize_url_path $1) local local_page=$(ynh_normalize_url_path $1)