From 873bf4ae370cf785c66db0028ca1ab5bc06340c0 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 25 Feb 2019 18:44:21 +0100 Subject: [PATCH] Add min version for all helpers --- data/helpers.d/backend | 16 ++++++++++++++++ data/helpers.d/debug | 4 ++++ data/helpers.d/filesystem | 11 +++++++++++ data/helpers.d/getopts | 2 ++ data/helpers.d/ip | 3 +++ data/helpers.d/mysql | 24 ++++++++++++++++++++++++ data/helpers.d/network | 8 ++++++++ data/helpers.d/nodejs | 10 ++++++++++ data/helpers.d/package | 24 ++++++++++++++++++++++++ data/helpers.d/print | 27 +++++++++++++++++++++++++++ data/helpers.d/psql | 20 ++++++++++++++++++++ data/helpers.d/setting | 6 ++++++ data/helpers.d/string | 6 ++++++ data/helpers.d/system | 12 ++++++++++++ data/helpers.d/user | 12 ++++++++++++ data/helpers.d/utils | 8 ++++++++ 16 files changed, 193 insertions(+) diff --git a/data/helpers.d/backend b/data/helpers.d/backend index e710da9c7..ac6f3e5de 100644 --- a/data/helpers.d/backend +++ b/data/helpers.d/backend @@ -14,6 +14,8 @@ # # 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 +# +# Requires YunoHost version 2.6.4 or higher. ynh_use_logrotate () { # Declare an array to define the options of this helper. local legacy_args=lnuya @@ -92,6 +94,8 @@ EOF # Remove the app's logrotate config. # # usage: ynh_remove_logrotate +# +# Requires YunoHost version 2.6.4 or higher. ynh_remove_logrotate () { if [ -e "/etc/logrotate.d/$app" ]; then sudo rm "/etc/logrotate.d/$app" @@ -112,6 +116,7 @@ ynh_remove_logrotate () { # __APP__ by $app # __FINALPATH__ by $final_path # +# Requires YunoHost version 2.7.2 or higher. ynh_add_systemd_config () { # Declare an array to define the options of this helper. local legacy_args=st @@ -147,6 +152,7 @@ ynh_add_systemd_config () { # usage: ynh_remove_systemd_config [--service=service] # | arg: -s, --service - Service name (optionnal, $app by default) # +# Requires YunoHost version 2.7.2 or higher. ynh_remove_systemd_config () { # Declare an array to define the options of this helper. local legacy_args=s @@ -183,6 +189,7 @@ ynh_remove_systemd_config () { # __PATH_2__ by $path_2 # __PORT_2__ by $port_2 # +# Requires YunoHost version 2.7.2 or higher. ynh_add_nginx_config () { finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" local others_var=${1:-} @@ -233,6 +240,8 @@ ynh_add_nginx_config () { # Remove the dedicated nginx config # # usage: ynh_remove_nginx_config +# +# Requires YunoHost version 2.7.2 or higher. ynh_remove_nginx_config () { ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.conf" sudo systemctl reload nginx @@ -241,6 +250,8 @@ ynh_remove_nginx_config () { # Create a dedicated php-fpm config # # usage: ynh_add_fpm_config +# +# Requires YunoHost version 2.7.2 or higher. ynh_add_fpm_config () { # Configure PHP-FPM 7.0 by default local fpm_config_dir="/etc/php/7.0/fpm" @@ -276,6 +287,8 @@ ynh_add_fpm_config () { # Remove the dedicated php-fpm config # # usage: ynh_remove_fpm_config +# +# Requires YunoHost version 2.7.2 or higher. ynh_remove_fpm_config () { 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) @@ -350,6 +363,7 @@ ynh_remove_fpm_config () { # 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 # +# Requires YunoHost version 3.?.? or higher. ynh_add_fail2ban_config () { # 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=) @@ -429,6 +443,8 @@ EOF # Remove the dedicated fail2ban config (jail and filter conf files) # # usage: ynh_remove_fail2ban_config +# +# Requires YunoHost version 3.?.? or higher. ynh_remove_fail2ban_config () { ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" diff --git a/data/helpers.d/debug b/data/helpers.d/debug index a8b7c8d69..ea20ffc1a 100644 --- a/data/helpers.d/debug +++ b/data/helpers.d/debug @@ -5,6 +5,8 @@ # usage: ynh_debug [--message=message] [--trace=1/0] # | 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. +# +# Requires YunoHost version 3.?.? or higher. ynh_debug () { # Disable set xtrace for the helper itself, to not pollute the debug log 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.?.? or higher. ynh_debug_exec () { ynh_debug --message="$(eval $@)" } diff --git a/data/helpers.d/filesystem b/data/helpers.d/filesystem index 10123dea4..6fb6347a6 100644 --- a/data/helpers.d/filesystem +++ b/data/helpers.d/filesystem @@ -46,6 +46,7 @@ CAN_BIND=${CAN_BIND:-1} # ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/conf/" # # => "/etc/nginx/conf.d/$domain.d/$app.conf","apps/wordpress/conf/$app.conf" # +# Requires YunoHost version 2.4.0 or higher. ynh_backup() { # TODO find a way to avoid injection by file strange naming ! @@ -158,6 +159,7 @@ ynh_backup() { # # usage: ynh_restore # +# Requires YunoHost version 2.6.4 or higher. ynh_restore () { # Deduce the relative path of $YNH_CWD 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: # ynh_restore_file "conf/nginx.conf" # +# Requires YunoHost version 2.6.4 or higher. ynh_restore_file () { # Declare an array to define the options of this helper. local legacy_args=odm @@ -313,6 +316,8 @@ properly with chmod/chown." >&2 # # usage: ynh_store_file_checksum --file=file # | 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 () { # Declare an array to define the options of this helper. 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. # # | ret: Return the name a the backup file, or nothing +# +# Requires YunoHost version 2.6.4 or higher. ynh_backup_if_checksum_is_different () { # Declare an array to define the options of this helper. local legacy_args=f @@ -376,6 +383,8 @@ ynh_backup_if_checksum_is_different () { # # usage: ynh_remove_file_checksum file # | arg: -f, --file= - The file for which the checksum will be deleted +# +# Requires YunoHost version 3.3.1 or higher. ynh_delete_file_checksum () { # Declare an array to define the options of this helper. local legacy_args=f @@ -392,6 +401,8 @@ ynh_delete_file_checksum () { # # usage: ynh_secure_remove --file=path_to_remove # | arg: -f, --file - File or directory to remove +# +# Requires YunoHost version 2.6.4 or higher. ynh_secure_remove () { # Declare an array to define the options of this helper. local legacy_args=f diff --git a/data/helpers.d/getopts b/data/helpers.d/getopts index 7055325f1..f89784578 100644 --- a/data/helpers.d/getopts +++ b/data/helpers.d/getopts @@ -43,6 +43,8 @@ # 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. # 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 () { # Manage arguments only if there's some provided set +x diff --git a/data/helpers.d/ip b/data/helpers.d/ip index c50d8be73..2ca4053d9 100644 --- a/data/helpers.d/ip +++ b/data/helpers.d/ip @@ -7,6 +7,7 @@ # # example: ynh_validate_ip 4 111.222.333.444 # +# Requires YunoHost version 2.2.4 or higher. ynh_validate_ip() { # 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 # | ret: 0 for valid ipv4 addresses, 1 otherwise # +# Requires YunoHost version 2.2.4 or higher. ynh_validate_ip4() { # 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 # | ret: 0 for valid ipv6 addresses, 1 otherwise # +# Requires YunoHost version 2.2.4 or higher. ynh_validate_ip6() { # Declare an array to define the options of this helper. diff --git a/data/helpers.d/mysql b/data/helpers.d/mysql index fa1a61dab..313b7a245 100644 --- a/data/helpers.d/mysql +++ b/data/helpers.d/mysql @@ -11,6 +11,8 @@ MYSQL_ROOT_PWD_FILE=/etc/yunohost/mysql # | arg: -u, --user - the user name to connect as # | arg: -p, --password - the user password # | arg: -d, --database - the database to connect to +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_connect_as() { # Declare an array to define the options of this helper. local legacy_args=upd @@ -30,6 +32,8 @@ ynh_mysql_connect_as() { # usage: ynh_mysql_execute_as_root --sql=sql [--database=database] # | arg: -s, --sql - the SQL command to execute # | arg: -d, --database - the database to connect to +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_execute_as_root() { # Declare an array to define the options of this helper. local legacy_args=sd @@ -49,6 +53,8 @@ ynh_mysql_execute_as_root() { # usage: ynh_mysql_execute_file_as_root --file=file [--database=database] # | arg: -f, --file - the file containing SQL commands # | arg: -d, --database - the database to connect to +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_execute_file_as_root() { # Declare an array to define the options of this helper. local legacy_args=fd @@ -71,6 +77,8 @@ ynh_mysql_execute_file_as_root() { # | arg: db - the database name to create # | arg: user - the user to grant privilegies # | arg: pwd - the password to identify user by +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_create_db() { local db=$1 @@ -95,6 +103,8 @@ ynh_mysql_create_db() { # # usage: ynh_mysql_drop_db db # | arg: db - the database name to drop +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_drop_db() { ynh_mysql_execute_as_root --sql="DROP DATABASE ${1};" } @@ -106,6 +116,8 @@ ynh_mysql_drop_db() { # usage: ynh_mysql_dump_db --database=database # | arg: -d, --database - the database name to dump # | ret: the mysqldump output +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_dump_db() { # Declare an array to define the options of this helper. local legacy_args=d @@ -124,6 +136,8 @@ ynh_mysql_dump_db() { # usage: ynh_mysql_create_user user pwd [host] # | arg: user - the user name to create # | arg: pwd - the password to identify user by +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_create_user() { ynh_mysql_execute_as_root \ --sql="CREATE USER '${1}'@'localhost' IDENTIFIED BY '${2}';" @@ -133,6 +147,8 @@ ynh_mysql_create_user() { # # usage: ynh_mysql_user_exists --user=user # | arg: -u, --user - the user for which to check existence +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_user_exists() { # Declare an array to define the options of this helper. @@ -156,6 +172,8 @@ ynh_mysql_user_exists() # # usage: ynh_mysql_drop_user user # | arg: user - the user name to drop +# +# Requires YunoHost version 2.2.4 or higher. ynh_mysql_drop_user() { 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: -n, --db_name - Name of the database # | 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 () { # Declare an array to define the options of this helper. local legacy_args=unp @@ -192,6 +212,8 @@ ynh_mysql_setup_db () { # usage: ynh_mysql_remove_db --db_user=user --db_name=name # | arg: -u, --db_user - Owner of the database # | arg: -n, --db_name - Name of the database +# +# Requires YunoHost version 2.6.4 or higher. ynh_mysql_remove_db () { # Declare an array to define the options of this helper. local legacy_args=un @@ -223,6 +245,8 @@ ynh_mysql_remove_db () { # usage: ynh_sanitize_dbid --db_name=name # | arg: -n, --db_name - name to correct/sanitize # | ret: the corrected name +# +# Requires YunoHost version 2.2.4 or higher. ynh_sanitize_dbid () { # Declare an array to define the options of this helper. local legacy_args=n diff --git a/data/helpers.d/network b/data/helpers.d/network index a765d6346..8812f8f39 100644 --- a/data/helpers.d/network +++ b/data/helpers.d/network @@ -12,6 +12,8 @@ # # usage: ynh_normalize_url_path --path_url=path_to_normalize # | arg: -p, --path_url - URL path to normalize before using it +# +# Requires YunoHost version 2.6.4 or higher. ynh_normalize_url_path () { # Declare an array to define the options of this helper. local legacy_args=p @@ -36,6 +38,8 @@ ynh_normalize_url_path () { # # usage: ynh_find_port --port=begin_port # | arg: -p, --port - port to start to search +# +# Requires YunoHost version 2.6.4 or higher. ynh_find_port () { # Declare an array to define the options of this helper. local legacy_args=p @@ -59,6 +63,8 @@ ynh_find_port () { # usage: ynh_webpath_available --domain=domain --path_url=path # | arg: -d, --domain - the domain/host of the url # | arg: -p, --path_url - the web path to check the availability of +# +# Requires YunoHost version 2.6.4 or higher. ynh_webpath_available () { # Declare an array to define the options of this helper. local legacy_args=dp @@ -79,6 +85,8 @@ ynh_webpath_available () { # | arg: -a, --app - the app for which the domain should be registered # | arg: -d, --domain - the domain/host of the web path # | arg: -p, --path_url - the web path to be registered +# +# Requires YunoHost version 2.6.4 or higher. ynh_webpath_register () { # Declare an array to define the options of this helper. local legacy_args=adp diff --git a/data/helpers.d/nodejs b/data/helpers.d/nodejs index 61a1414ef..34583328d 100644 --- a/data/helpers.d/nodejs +++ b/data/helpers.d/nodejs @@ -10,6 +10,8 @@ export N_PREFIX="$n_install_dir" # [internal] # # usage: ynh_install_n +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_n () { echo "Installation of N - Node.js version management" >&2 # 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. # # usage: ynh_use_nodejs +# +# Requires YunoHost version 2.7.12 or higher. ynh_use_nodejs () { 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. # 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. +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_nodejs () { # 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. # # usage: ynh_remove_nodejs +# +# Requires YunoHost version 2.7.12 or higher. ynh_remove_nodejs () { 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. # # usage: ynh_cron_upgrade_node +# +# Requires YunoHost version 2.7.12 or higher. ynh_cron_upgrade_node () { # Build the update script cat > "$n_install_dir/node_update.sh" << EOF diff --git a/data/helpers.d/package b/data/helpers.d/package index 3924fc14e..75323521d 100644 --- a/data/helpers.d/package +++ b/data/helpers.d/package @@ -5,6 +5,8 @@ # [internal] # # usage: ynh_wait_dpkg_free +# +# Requires YunoHost version 3.3.1 or higher. ynh_wait_dpkg_free() { local try # 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 # | arg: -p, --package - the package name to check +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_is_installed() { # Declare an array to define the options of this helper. local legacy_args=p @@ -64,6 +68,8 @@ ynh_package_is_installed() { # usage: ynh_package_version --package=name # | arg: -p, --package - the package name to get version # | ret: the version or an empty string +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_version() { # Declare an array to define the options of this helper. local legacy_args=p @@ -84,6 +90,8 @@ ynh_package_version() { # [internal] # # usage: ynh_apt update +# +# Requires YunoHost version 2.4.0.3 or higher. ynh_apt() { ynh_wait_dpkg_free DEBIAN_FRONTEND=noninteractive apt-get -y $@ @@ -92,6 +100,8 @@ ynh_apt() { # Update package index files # # usage: ynh_package_update +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_update() { ynh_apt update } @@ -100,6 +110,8 @@ ynh_package_update() { # # usage: ynh_package_install name [name [...]] # | arg: name - the package name to install +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_install() { ynh_apt --no-remove -o Dpkg::Options::=--force-confdef \ -o Dpkg::Options::=--force-confold install $@ @@ -109,6 +121,8 @@ ynh_package_install() { # # usage: ynh_package_remove name [name [...]] # | arg: name - the package name to remove +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_remove() { ynh_apt remove $@ } @@ -117,6 +131,8 @@ ynh_package_remove() { # # usage: ynh_package_autoremove name [name [...]] # | arg: name - the package name to remove +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_autoremove() { ynh_apt autoremove $@ } @@ -125,6 +141,8 @@ ynh_package_autoremove() { # # usage: ynh_package_autopurge name [name [...]] # | arg: name - the package name to autoremove and purge +# +# Requires YunoHost version 2.7.2 or higher. ynh_package_autopurge() { ynh_apt autoremove --purge $@ } @@ -139,6 +157,8 @@ ynh_package_autopurge() { # # usage: ynh_package_install_from_equivs controlfile # | arg: controlfile - path of the equivs control file +# +# Requires YunoHost version 2.2.4 or higher. ynh_package_install_from_equivs () { 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" # Example : ynh_install_app_dependencies 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 () { local dependencies=$@ local dependencies=${dependencies// /, } @@ -217,6 +239,8 @@ EOF # Dependencies will removed only if no other package need them. # # usage: ynh_remove_app_dependencies +# +# Requires YunoHost version 2.6.4 or higher. ynh_remove_app_dependencies () { 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. diff --git a/data/helpers.d/print b/data/helpers.d/print index 7f37021ae..6e7b2b1d7 100644 --- a/data/helpers.d/print +++ b/data/helpers.d/print @@ -2,6 +2,8 @@ # Print a message to stderr and exit # usage: ynh_die --message=MSG [--ret_code=RETCODE] +# +# Requires YunoHost version 2.4.0 or higher. ynh_die() { # Declare an array to define the options of this helper. local legacy_args=mc @@ -18,6 +20,8 @@ ynh_die() { # Display a message in the 'INFO' logging category # # usage: ynh_print_info --message="Some message" +# +# Requires YunoHost version 3.2.0 or higher. ynh_print_info() { # Declare an array to define the options of this helper. 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 # It's a very badly hack... +# +# Requires YunoHost version 2.6.4 or higher. ynh_no_log() { local ynh_cli_log=/var/log/yunohost/yunohost-cli.log sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move @@ -50,6 +56,7 @@ ynh_no_log() { # # [internal] # +# Requires YunoHost version 3.2.0 or higher. ynh_print_log () { echo -e "${1}" } @@ -58,6 +65,8 @@ ynh_print_log () { # # usage: ynh_print_warn --message="Text to print" # | arg: -m, --message - The text to print +# +# Requires YunoHost version 3.2.0 or higher. ynh_print_warn () { # Declare an array to define the options of this helper. local legacy_args=m @@ -73,6 +82,8 @@ ynh_print_warn () { # # usage: ynh_print_err --message="Text to print" # | arg: -m, --message - The text to print +# +# Requires YunoHost version 3.2.0 or higher. ynh_print_err () { # Declare an array to define the options of this helper. 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.2.0 or higher. ynh_exec_err () { 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.2.0 or higher. ynh_exec_warn () { 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.2.0 or higher. ynh_exec_warn_less () { 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.2.0 or higher. ynh_exec_quiet () { 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. # # | arg: command - command to execute +# +# Requires YunoHost version 3.2.0 or higher. ynh_exec_fully_quiet () { eval $@ > /dev/null 2>&1 } @@ -143,6 +164,8 @@ ynh_exec_fully_quiet () { # # 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. +# +# Requires YunoHost version 3.2.0 or higher. ynh_print_OFF () { set +x } @@ -150,6 +173,8 @@ ynh_print_OFF () { # Restore the logging after ynh_print_OFF # # usage: ynh_print_ON +# +# Requires YunoHost version 3.2.0 or higher. ynh_print_ON () { set -x # 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: -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. +# +# Requires YunoHost version 3.?.? or higher. increment_progression=0 previous_weight=0 # Define base_time when the file is sourced diff --git a/data/helpers.d/psql b/data/helpers.d/psql index 2ef13482a..70ea58af4 100644 --- a/data/helpers.d/psql +++ b/data/helpers.d/psql @@ -2,6 +2,8 @@ # Please always call this script in install and restore scripts # # usage: ynh_psql_test_if_first_run +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_test_if_first_run() { if [ -f /etc/yunohost/psql ]; then @@ -43,6 +45,8 @@ ynh_psql_test_if_first_run() { # | arg: user - the user name to connect as # | arg: pwd - the user password # | arg: db - the database to connect to +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_connect_as() { local user="$1" local pwd="$2" @@ -54,6 +58,8 @@ ynh_psql_connect_as() { # # usage: ynh_psql_execute_as_root sql [db] # | arg: sql - the SQL command to execute +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_execute_as_root () { local sql="$1" sudo --login --user=postgres psql <<< "$sql" @@ -64,6 +70,8 @@ ynh_psql_execute_as_root () { # usage: ynh_psql_execute_file_as_root file [db] # | arg: file - the file containing SQL commands # | arg: db - the database to connect to +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_execute_file_as_root() { local file="$1" local db="$2" @@ -79,6 +87,8 @@ ynh_psql_execute_file_as_root() { # | arg: user - Owner of the database # | arg: name - Name of the database # | arg: pwd - Password of the database. If not given, a password will be generated +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_setup_db () { local db_user="$1" local db_name="$2" @@ -95,6 +105,8 @@ ynh_psql_setup_db () { # | arg: db - the database name to create # | arg: user - the user to grant privilegies # | arg: pwd - the user password +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_create_db() { local db="$1" local user="$2" @@ -108,6 +120,8 @@ ynh_psql_create_db() { # usage: ynh_psql_drop_db db # | arg: db - the database name to drop # | arg: user - the user to drop +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_remove_db() { local db="$1" local user="$2" @@ -122,6 +136,8 @@ ynh_psql_remove_db() { # usage: ynh_psql_dump_db db # | arg: db - the database name to dump # | ret: the psqldump output +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_dump_db() { local db="$1" sudo --login --user=postgres pg_dump "$db" @@ -132,6 +148,8 @@ ynh_psql_dump_db() { # # usage: ynh_psql_create_user user pwd [host] # | arg: user - the user name to create +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_create_user() { local user="$1" local pwd="$2" @@ -142,6 +160,8 @@ ynh_psql_create_user() { # # usage: ynh_psql_drop_user user # | arg: user - the user name to drop +# +# Requires YunoHost version 3.?.? or higher. ynh_psql_drop_user() { local user="$1" sudo --login --user=postgres dropuser "$user" diff --git a/data/helpers.d/setting b/data/helpers.d/setting index 6f75f6c80..0c3698061 100644 --- a/data/helpers.d/setting +++ b/data/helpers.d/setting @@ -5,6 +5,8 @@ # usage: ynh_app_setting_get --app=app --key=key # | arg: -a, --app - the application id # | arg: -k, --key - the setting to get +# +# Requires YunoHost version 2.2.4 or higher. ynh_app_setting_get() { # Declare an array to define the options of this helper. local legacy_args=ak @@ -23,6 +25,8 @@ ynh_app_setting_get() { # | arg: -a, --app - the application id # | arg: -k, --key - the setting name to set # | arg: -v, --value - the setting value to set +# +# Requires YunoHost version 2.2.4 or higher. ynh_app_setting_set() { # Declare an array to define the options of this helper. local legacy_args=akv @@ -41,6 +45,8 @@ ynh_app_setting_set() { # usage: ynh_app_setting_delete --app=app --key=key # | arg: -a, --app - the application id # | arg: -k, --key - the setting to delete +# +# Requires YunoHost version 2.2.4 or higher. ynh_app_setting_delete() { # Declare an array to define the options of this helper. local legacy_args=ak diff --git a/data/helpers.d/string b/data/helpers.d/string index 739757d43..52eede872 100644 --- a/data/helpers.d/string +++ b/data/helpers.d/string @@ -6,6 +6,8 @@ # # usage: ynh_string_random [--length=string_length] # | arg: -l, --length - the string length to generate (default: 24) +# +# Requires YunoHost version 2.2.4 or higher. ynh_string_random() { # Declare an array to define the options of this helper. local legacy_args=l @@ -30,6 +32,8 @@ ynh_string_random() { # As this helper is based on sed command, regular expressions and # references to sub-expressions can be used # (see sed manual page for more information) +# +# Requires YunoHost version 2.6.4 or higher. ynh_replace_string () { # Declare an array to define the options of this helper. local legacy_args=mrf @@ -57,6 +61,8 @@ ynh_replace_string () { # # This helper will use ynh_replace_string, but as you can use special # characters, you can't use some regular expressions and sub-expressions. +# +# Requires YunoHost version 2.7.7 or higher. ynh_replace_special_string () { # Declare an array to define the options of this helper. local legacy_args=mrf diff --git a/data/helpers.d/system b/data/helpers.d/system index 9a4219e11..fd5b21435 100644 --- a/data/helpers.d/system +++ b/data/helpers.d/system @@ -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 # +# Requires YunoHost version 2.6.4 or higher. ynh_exit_properly () { local exit_code=$? 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 # defined by your script. # +# Requires YunoHost version 2.6.4 or higher. ynh_abort_if_errors () { 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 @@ -52,6 +54,8 @@ ynh_abort_if_errors () { # # usage: ynh_get_debian_release # | ret: The Debian release codename (i.e. jessie, stretch, ...) +# +# Requires YunoHost version 2.7.12 or higher. ynh_get_debian_release () { echo $(lsb_release --codename --short) } @@ -61,6 +65,8 @@ ynh_get_debian_release () { # usage: ynh_read_manifest manifest key # | arg: -m, --manifest= - Path of the manifest to read # | arg: -k, --key= - Name of the key to find +# +# Requires YunoHost version 3.?.? or higher. ynh_read_manifest () { # Declare an array to define the options of this helper. declare -Ar args_array=( [m]=manifest= [k]=manifest_key= ) @@ -85,6 +91,8 @@ ynh_read_manifest () { # # usage: ynh_app_upstream_version [-m manifest] # | arg: -m, --manifest= - Path of the manifest to read +# +# Requires YunoHost version 3.?.? or higher. ynh_app_upstream_version () { declare -Ar args_array=( [m]=manifest= ) local manifest @@ -104,6 +112,8 @@ ynh_app_upstream_version () { # # usage: ynh_app_package_version [-m manifest] # | arg: -m, --manifest= - Path of the manifest to read +# +# Requires YunoHost version 3.?.? or higher. ynh_app_package_version () { declare -Ar args_array=( [m]=manifest= ) local manifest @@ -129,6 +139,8 @@ ynh_app_package_version () { # example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp # # usage: ynh_check_app_version_changed +# +# Requires YunoHost version 3.?.? or higher. ynh_check_app_version_changed () { local force_upgrade=${YNH_FORCE_UPGRADE:-0} local package_check=${PACKAGE_CHECK_EXEC:-0} diff --git a/data/helpers.d/user b/data/helpers.d/user index d716bf03b..f19739993 100644 --- a/data/helpers.d/user +++ b/data/helpers.d/user @@ -6,6 +6,8 @@ # # usage: ynh_user_exists --username=username # | arg: -u, --username - the username to check +# +# Requires YunoHost version 2.2.4 or higher. ynh_user_exists() { # Declare an array to define the options of this helper. local legacy_args=u @@ -25,6 +27,8 @@ ynh_user_exists() { # | arg: -u, --username - the username to retrieve info from # | arg: -k, --key - the key to retrieve # | ret: string - the key's value +# +# Requires YunoHost version 2.2.4 or higher. ynh_user_get_info() { # Declare an array to define the options of this helper. local legacy_args=uk @@ -43,6 +47,8 @@ ynh_user_get_info() { # # usage: ynh_user_list # | ret: string - one username per line +# +# Requires YunoHost version 2.4.0 or higher. ynh_user_list() { sudo yunohost user list --output-as plain --quiet \ | awk '/^##username$/{getline; print}' @@ -52,6 +58,8 @@ ynh_user_list() { # # usage: ynh_system_user_exists --username=username # | arg: -u, --username - the username to check +# +# Requires YunoHost version 2.2.4 or higher. ynh_system_user_exists() { # Declare an array to define the options of this helper. 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: -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 +# +# Requires YunoHost version 2.6.4 or higher. ynh_system_user_create () { # Declare an array to define the options of this helper. local legacy_args=uhs @@ -108,6 +118,8 @@ ynh_system_user_create () { # # usage: ynh_system_user_delete --username=user_name # | arg: -u, --username - Name of the system user that will be create +# +# Requires YunoHost version 2.6.4 or higher. ynh_system_user_delete () { # Declare an array to define the options of this helper. local legacy_args=u diff --git a/data/helpers.d/utils b/data/helpers.d/utils index 5ba2946a2..5f5e61015 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -6,6 +6,8 @@ # # usage: ynh_get_plain_key key [subkey [subsubkey ...]] # | ret: string - the key's value +# +# Requires YunoHost version 2.2.4 or higher. ynh_get_plain_key() { local prefix="#" local founded=0 @@ -36,6 +38,7 @@ ynh_get_plain_key() { # } # ynh_abort_if_errors # +# Requires YunoHost version 2.7.2 or higher. ynh_restore_upgradebackup () { echo "Upgrade failed." >&2 local app_bck=${app//_/-} # Replace all '_' by '-' @@ -67,6 +70,7 @@ ynh_restore_upgradebackup () { # } # ynh_abort_if_errors # +# Requires YunoHost version 2.7.2 or higher. ynh_backup_before_upgrade () { if [ ! -e "/etc/yunohost/apps/$app/scripts/backup" ] then @@ -150,6 +154,8 @@ ynh_backup_before_upgrade () { # usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] # | 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 +# +# Requires YunoHost version 2.6.4 or higher. ynh_setup_source () { # Declare an array to define the options of this helper. local legacy_args=ds @@ -255,6 +261,8 @@ ynh_setup_source () { # | arg: key1=value1 - (Optionnal) POST key and corresponding value # | arg: key2=value2 - (Optionnal) Another POST key and corresponding value # | arg: ... - (Optionnal) More POST keys and values +# +# Requires YunoHost version 2.6.4 or higher. ynh_local_curl () { # Define url of page to curl local local_page=$(ynh_normalize_url_path $1)