helpers 2.1: drop support for 'legacy args' (positionals) in helpers

This commit is contained in:
Alexandre Aubin 2024-05-27 18:31:57 +02:00
parent 084ecd6578
commit b914ad9093
24 changed files with 152 additions and 285 deletions

View file

@ -8,7 +8,6 @@
# Requires YunoHost version *.*.* or higher.
ynh_install_apps() {
# Declare an array to define the options of this helper.
local legacy_args=a
local -A args_array=([a]=apps=)
local apps
# Manage arguments with getopts
@ -127,7 +126,6 @@ ynh_remove_apps() {
# If the app relies on a specific PHP version, then `php` will be aliased that version. The PHP command will also be appended with the `phpflags` settings.
ynh_spawn_app_shell() {
# Declare an array to define the options of this helper.
local legacy_args=a
local -A args_array=([a]=app=)
local app
# Manage arguments with getopts

View file

@ -28,7 +28,7 @@ ynh_wait_dpkg_free() {
# Check if the name of this file contains only numbers.
if echo "$dpkg_file" | grep --perl-regexp --quiet "^[[:digit:]]+$"; then
# If so, that a remaining of dpkg.
ynh_print_err "dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem."
ynh_print_err --message="dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem."
set -o xtrace # set -x
return 1
fi
@ -43,21 +43,15 @@ ynh_wait_dpkg_free() {
# Check either a package is installed or not
#
# example: ynh_package_is_installed --package=yunohost && echo "installed"
# example: ynh_package_is_installed foobar && echo "installed"
#
# usage: ynh_package_is_installed --package=name
# | arg: -p, --package= - the package name to check
# usage: ynh_package_is_installed name
# | arg: name - the package name to check
# | ret: 0 if the package is installed, 1 else.
#
# 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
local -A args_array=([p]=package=)
local package
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local package=$1
dpkg-query --show --showformat='${Status}' "$package" 2>/dev/null \
| grep --count "ok installed" &>/dev/null
}
@ -75,7 +69,6 @@ ynh_package_is_installed() {
# 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
local -A args_array=([p]=package=)
local package
# Manage arguments with getopts
@ -310,7 +303,7 @@ ynh_install_app_dependencies() {
YNH_INSTALL_APP_DEPENDENCIES_REPLACE="false"
else
local current_dependencies=""
if ynh_package_is_installed --package="${dep_app}-ynh-deps"
if ynh_package_is_installed "${dep_app}-ynh-deps"
then
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
current_dependencies=${current_dependencies// | /|}
@ -352,7 +345,6 @@ EOF
# Requires YunoHost version 3.8.1 or higher.
ynh_add_app_dependencies() {
# Declare an array to define the options of this helper.
local legacy_args=pr
local -A args_array=([p]=package= [r]=replace)
local package
# Manage arguments with getopts
@ -375,7 +367,7 @@ ynh_remove_app_dependencies() {
local dep_app=${app//_/-} # Replace all '_' by '-'
local current_dependencies=""
if ynh_package_is_installed --package="${dep_app}-ynh-deps"; then
if ynh_package_is_installed "${dep_app}-ynh-deps"; then
current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) "
current_dependencies=${current_dependencies// | /|}
fi
@ -409,7 +401,6 @@ ynh_remove_app_dependencies() {
# Requires YunoHost version 3.8.1 or higher.
ynh_install_extra_app_dependencies() {
# Declare an array to define the options of this helper.
local legacy_args=rpkn
local -A args_array=([r]=repo= [p]=package= [k]=key= [n]=name=)
local repo
local package
@ -454,7 +445,6 @@ ynh_install_extra_app_dependencies() {
# Requires YunoHost version 3.8.1 or higher.
ynh_install_extra_repo() {
# Declare an array to define the options of this helper.
local legacy_args=rkpna
local -A args_array=([r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append)
local repo
local key
@ -523,7 +513,6 @@ ynh_install_extra_repo() {
# Requires YunoHost version 3.8.1 or higher.
ynh_remove_extra_repo() {
# Declare an array to define the options of this helper.
local legacy_args=n
local -A args_array=([n]=name=)
local name
# Manage arguments with getopts
@ -532,7 +521,7 @@ ynh_remove_extra_repo() {
ynh_secure_remove --file="/etc/apt/sources.list.d/$name.list"
# Sury pinning is managed by the regenconf in the core...
[[ "$name" == "extra_php_version" ]] || ynh_secure_remove "/etc/apt/preferences.d/$name"
[[ "$name" == "extra_php_version" ]] || ynh_secure_remove --file="/etc/apt/preferences.d/$name"
if [ -e /etc/apt/trusted.gpg.d/$name.gpg ]; then
ynh_secure_remove --file="/etc/apt/trusted.gpg.d/$name.gpg"
fi
@ -564,7 +553,6 @@ ynh_remove_extra_repo() {
# Requires YunoHost version 3.8.1 or higher.
ynh_add_repo() {
# Declare an array to define the options of this helper.
local legacy_args=uscna
local -A args_array=([u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append)
local uri
local suite
@ -604,7 +592,6 @@ ynh_add_repo() {
# Requires YunoHost version 3.8.1 or higher.
ynh_pin_repo() {
# Declare an array to define the options of this helper.
local legacy_args=pirna
local -A args_array=([p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append)
local package
local pin

View file

@ -65,7 +65,6 @@ ynh_backup() {
# TODO find a way to avoid injection by file strange naming !
# Declare an array to define the options of this helper.
local legacy_args=sdbm
local -A args_array=([s]=src_path= [d]=dest_path= [b]=is_big [m]=not_mandatory)
local src_path
local dest_path
@ -237,7 +236,6 @@ with open(sys.argv[1], 'r') as backup_file:
# Requires YunoHost version 3.5.0 or higher for the argument --not_mandatory
ynh_restore_file() {
# Declare an array to define the options of this helper.
local legacy_args=odm
local -A args_array=([o]=origin_path= [d]=dest_path= [m]=not_mandatory)
local origin_path
local dest_path
@ -305,7 +303,6 @@ ynh_restore_file() {
# 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
local -A args_array=([f]=file= [u]=update_only)
local file
local update_only
@ -356,7 +353,6 @@ ynh_store_file_checksum() {
# 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
local -A args_array=([f]=file=)
local file
# Manage arguments with getopts
@ -372,13 +368,13 @@ ynh_backup_if_checksum_is_different() {
backup_file_checksum="/var/cache/yunohost/appconfbackup/$file.backup.$(date '+%Y%m%d.%H%M%S')"
mkdir --parents "$(dirname "$backup_file_checksum")"
cp --archive "$file" "$backup_file_checksum" # Backup the current file
ynh_print_warn "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum"
ynh_print_warn --message="File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum"
echo "$backup_file_checksum" # Return the name of the backup file
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
local file_path_base64=$(echo "$file" | base64 -w0)
if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64}
then
ynh_print_warn "Diff with the original file:"
ynh_print_warn --message="Diff with the original file:"
diff --report-identical-files --unified --color=always /var/cache/yunohost/appconfbackup/original_${file_path_base64} $file >&2 || true
fi
fi
@ -396,7 +392,6 @@ ynh_backup_if_checksum_is_different() {
# 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
local -A args_array=([f]=file=)
local file
# Manage arguments with getopts

View file

@ -320,7 +320,7 @@ ynh_app_action_run() {
#ynh_return "result:"
#ynh_return "$(echo "${result}" | sed 's/^/ /g')"
else
ynh_die "No handler defined in app's script for action $1. If you are the maintainer of this app, you should define '$runner'"
ynh_die --message="No handler defined in app's script for action $1. If you are the maintainer of this app, you should define '$runner'"
fi
}

View file

@ -59,7 +59,6 @@
# Requires YunoHost version 4.1.0 or higher.
ynh_add_fail2ban_config() {
# Declare an array to define the options of this helper.
local legacy_args=lrmptv
local -A args_array=([l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template)
local logpath
local failregex

View file

@ -48,7 +48,11 @@
ynh_handle_getopts_args() {
# Manage arguments only if there's some provided
set +o xtrace # set +x
if [ $# -ne 0 ]; then
if [ $# -eq 0 ]; then
set -o xtrace # set -x
return
fi
# Store arguments in an array to keep each argument separated
local arguments=("$@")
@ -174,42 +178,8 @@ ynh_handle_getopts_args() {
done
}
# LEGACY MODE
# Check if there's getopts arguments
if [ "${arguments[0]:0:1}" != "-" ]; then
# If not, enter in legacy mode and manage the arguments as positionnal ones..
# Dot not echo, to prevent to go through a helper output. But print only in the log.
set -x
echo "! Helper used in legacy mode !" >/dev/null
set +x
local i
for i in $(seq 0 $((${#arguments[@]} - 1))); do
# Try to use legacy_args as a list of option_flag of the array args_array
# Otherwise, fallback to getopts_parameters to get the option_flag. But an associative arrays isn't always sorted in the correct order...
# Remove all ':' in getopts_parameters
getopts_parameters=${legacy_args:-${getopts_parameters//:/}}
# Get the option_flag from getopts_parameters, by using the option_flag according to the position of the argument.
option_flag=${getopts_parameters:$i:1}
if [ -z "$option_flag" ]; then
ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
continue
fi
# Use the long option, corresponding to the option_flag, as a variable
# (e.g. for [u]=user, 'user' will be used as a variable)
# Also, remove '=' at the end of the long option
# The variable name will be stored in 'option_var'
local option_var="${args_array[$option_flag]%=}"
# Store each value given as argument in the corresponding variable
# The values will be stored in the same order than $args_array
eval ${option_var}+='"${arguments[$i]}"'
done
unset legacy_args
else
# END LEGACY MODE
# Call parse_arg and pass the modified list of args as an array of arguments.
parse_arg "${arguments[@]}"
fi
fi
set -o xtrace # set -x
}

View file

@ -95,7 +95,6 @@ ynh_use_go () {
# Requires YunoHost version 3.2.2 or higher.
ynh_install_go () {
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=go_version= )
local go_version
# Manage arguments with getopts

View file

@ -14,7 +14,6 @@
# Requires YunoHost version 3.8.1 or higher.
ynh_get_ram() {
# Declare an array to define the options of this helper.
local legacy_args=ftso
local -A args_array=([f]=free [t]=total [s]=ignore_swap [o]=only_swap)
local free
local total
@ -78,7 +77,6 @@ ynh_get_ram() {
# Requires YunoHost version 3.8.1 or higher.
ynh_require_ram() {
# Declare an array to define the options of this helper.
local legacy_args=rftso
local -A args_array=([r]=required= [f]=free [t]=total [s]=ignore_swap [o]=only_swap)
local required
local free

View file

@ -9,7 +9,6 @@
# Requires YunoHost version 2.4.0 or higher.
ynh_die() {
# Declare an array to define the options of this helper.
local legacy_args=mc
local -A args_array=([m]=message= [c]=ret_code=)
local message
local ret_code
@ -29,7 +28,6 @@ ynh_die() {
# 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
local -A args_array=([m]=message=)
local message
# Manage arguments with getopts
@ -55,7 +53,6 @@ ynh_print_log() {
# 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
local -A args_array=([m]=message=)
local message
# Manage arguments with getopts
@ -72,7 +69,6 @@ ynh_print_warn() {
# 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
local -A args_array=([m]=message=)
local message
# Manage arguments with getopts
@ -201,7 +197,7 @@ ynh_exec_and_print_stderr_only_if_error() {
"$@" 2> "$logfile" || rc="$?"
if (( rc != 0 )); then
ynh_exec_warn cat "$logfile"
ynh_secure_remove "$logfile"
ynh_secure_remove --file="$logfile"
return "$rc"
fi
}
@ -257,7 +253,6 @@ base_time=$(date +%s)
ynh_script_progression() {
set +o xtrace # set +x
# Declare an array to define the options of this helper.
local legacy_args=mwtl
local -A args_array=([m]=message= [w]=weight= [t]=time [l]=last)
local message
local weight
@ -332,7 +327,7 @@ ynh_script_progression() {
print_exec_time=" [$(bc <<< "scale=1; $exec_time / 60" ) minutes]"
fi
ynh_print_info "[$progression_bar] > ${message}${print_exec_time}"
echo "[$progression_bar] > ${message}${print_exec_time}" >&$YNH_STDINFO
set -o xtrace # set -x
}

View file

@ -27,7 +27,6 @@ ynh_use_logrotate() {
set -- "${all_args[@]}"
# Argument parsing
local legacy_args=lu
local -A args_array=([l]=logfile= [u]=specific_user=)
local logfile
local specific_user

View file

@ -18,7 +18,6 @@
#
ynh_mongo_exec() {
# Declare an array to define the options of this helper.
local legacy_args=upadhPce
local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval )
local user
local password
@ -115,7 +114,6 @@ EOF
#
ynh_mongo_drop_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
@ -135,7 +133,6 @@ ynh_mongo_drop_db() {
#
ynh_mongo_dump_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
@ -156,7 +153,6 @@ ynh_mongo_dump_db() {
#
ynh_mongo_create_user() {
# Declare an array to define the options of this helper.
local legacy_args=unp
local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
local db_user
local db_name
@ -180,7 +176,6 @@ ynh_mongo_create_user() {
#
ynh_mongo_database_exists() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=([d]=database=)
local database
# Manage arguments with getopts
@ -204,7 +199,6 @@ ynh_mongo_database_exists() {
#
ynh_mongo_restore_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=( [d]=database= )
local database
# Manage arguments with getopts
@ -224,7 +218,6 @@ ynh_mongo_restore_db() {
#
ynh_mongo_drop_user() {
# Declare an array to define the options of this helper.
local legacy_args=un
local -A args_array=( [u]=db_user= [n]=db_name= )
local db_user
local db_name
@ -247,7 +240,6 @@ ynh_mongo_drop_user() {
#
ynh_mongo_setup_db() {
# Declare an array to define the options of this helper.
local legacy_args=unp
local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= )
local db_user
local db_name
@ -275,7 +267,6 @@ ynh_mongo_setup_db() {
#
ynh_mongo_remove_db() {
# Declare an array to define the options of this helper.
local legacy_args=un
local -A args_array=( [u]=db_user= [n]=db_name= )
local db_user
local db_name
@ -300,7 +291,6 @@ ynh_mongo_remove_db() {
#
ynh_install_mongo() {
# Declare an array to define the options of this helper.
local legacy_args=m
local -A args_array=([m]=mongo_version=)
local mongo_version
# Manage arguments with getopts
@ -343,7 +333,7 @@ ynh_install_mongo() {
#
ynh_remove_mongo() {
# Only remove the mongodb service if it is not installed.
if ! ynh_package_is_installed --package="mongodb*"
if ! ynh_package_is_installed "mongodb*"
then
ynh_print_info --message="Removing MongoDB service..."
mongodb_servicename=mongod

View file

@ -64,7 +64,6 @@ ynh_multimedia_build_main_dir() {
ynh_multimedia_addfolder() {
# Declare an array to define the options of this helper.
local legacy_args=sd
local -A args_array=([s]=source_dir= [d]=dest_dir=)
local source_dir
local dest_dir
@ -92,7 +91,6 @@ ynh_multimedia_addfolder() {
# Requires YunoHost version 4.2 or higher.
ynh_multimedia_addaccess() {
# Declare an array to define the options of this helper.
local legacy_args=u
declare -Ar args_array=([u]=user_name=)
local user_name
# Manage arguments with getopts

View file

@ -14,7 +14,6 @@
# 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
local -A args_array=([u]=user= [p]=password= [d]=database=)
local user
local password
@ -35,7 +34,6 @@ ynh_mysql_connect_as() {
# 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
local -A args_array=([s]=sql= [d]=database=)
local sql
local database
@ -59,7 +57,6 @@ ynh_mysql_execute_as_root() {
# 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
local -A args_array=([f]=file= [d]=database=)
local file
local database
@ -127,7 +124,6 @@ ynh_mysql_drop_db() {
# 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
local -A args_array=([d]=database=)
local database
# Manage arguments with getopts
@ -161,7 +157,6 @@ ynh_mysql_create_user() {
# Requires YunoHost version 2.2.4 or higher.
ynh_mysql_user_exists() {
# Declare an array to define the options of this helper.
local legacy_args=u
local -A args_array=([u]=user=)
local user
# Manage arguments with getopts
@ -201,7 +196,6 @@ ynh_mysql_drop_user() {
# 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
local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=)
local db_user
local db_name
@ -215,7 +209,7 @@ ynh_mysql_setup_db() {
db_pwd="${db_pwd:-$new_db_pwd}"
# Dirty patch for super-legacy apps
dpkg --list | grep -q "^ii mariadb-server" || { ynh_print_warn "Packager: you called ynh_mysql_setup_db without declaring a dependency to mariadb-server. Please add it to your apt dependencies !"; ynh_apt install mariadb-server; }
dpkg --list | grep -q "^ii mariadb-server" || { ynh_print_warn --message="Packager: you called ynh_mysql_setup_db without declaring a dependency to mariadb-server. Please add it to your apt dependencies !"; ynh_apt install mariadb-server; }
ynh_mysql_create_db "$db_name" "$db_user" "$db_pwd"
ynh_app_setting_set --app=$app --key=mysqlpwd --value=$db_pwd
@ -232,7 +226,6 @@ ynh_mysql_setup_db() {
# 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
local -Ar args_array=([u]=db_user= [n]=db_name=)
local db_user
local db_name

View file

@ -13,7 +13,6 @@
# 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
local -A args_array=([p]=port=)
local port
# Manage arguments with getopts
@ -39,7 +38,6 @@ ynh_find_port() {
# Requires YunoHost version 3.8.0 or higher.
ynh_port_available() {
# Declare an array to define the options of this helper.
local legacy_args=p
local -A args_array=([p]=port=)
local port
# Manage arguments with getopts
@ -70,7 +68,6 @@ ynh_validate_ip() {
# http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298
# Declare an array to define the options of this helper.
local legacy_args=fi
local -A args_array=([f]=family= [i]=ip_address=)
local family
local ip_address
@ -102,7 +99,6 @@ EOF
# Requires YunoHost version 2.2.4 or higher.
ynh_validate_ip4() {
# Declare an array to define the options of this helper.
local legacy_args=i
local -A args_array=([i]=ip_address=)
local ip_address
# Manage arguments with getopts
@ -122,7 +118,6 @@ ynh_validate_ip4() {
# Requires YunoHost version 2.2.4 or higher.
ynh_validate_ip6() {
# Declare an array to define the options of this helper.
local legacy_args=i
local -A args_array=([i]=ip_address=)
local ip_address
# Manage arguments with getopts

View file

@ -95,7 +95,6 @@ ynh_install_nodejs() {
# Use n, https://github.com/tj/n to manage the nodejs versions
# Declare an array to define the options of this helper.
local legacy_args=n
local -A args_array=([n]=nodejs_version=)
local nodejs_version
# Manage arguments with getopts

View file

@ -67,7 +67,6 @@
# Requires YunoHost version 3.7.0 or higher.
ynh_permission_create() {
# Declare an array to define the options of this helper.
local legacy_args=puAhaltP
local -A args_array=([p]=permission= [u]=url= [A]=additional_urls= [h]=auth_header= [a]=allowed= [l]=label= [t]=show_tile= [P]=protected=)
local permission
local url
@ -155,7 +154,6 @@ ynh_permission_create() {
# Requires YunoHost version 3.7.0 or higher.
ynh_permission_delete() {
# Declare an array to define the options of this helper.
local legacy_args=p
local -A args_array=([p]=permission=)
local permission
ynh_handle_getopts_args "$@"
@ -174,7 +172,6 @@ ynh_permission_delete() {
# Requires YunoHost version 3.7.0 or higher.
ynh_permission_exists() {
# Declare an array to define the options of this helper.
local legacy_args=p
local -A args_array=([p]=permission=)
local permission
ynh_handle_getopts_args "$@"
@ -199,7 +196,6 @@ ynh_permission_exists() {
# Requires YunoHost version 3.7.0 or higher.
ynh_permission_url() {
# Declare an array to define the options of this helper.
local legacy_args=puarhc
local -A args_array=([p]=permission= [u]=url= [a]=add_url= [r]=remove_url= [h]=auth_header= [c]=clear_urls)
local permission
local url
@ -269,7 +265,6 @@ ynh_permission_url() {
# Requires YunoHost version 3.7.0 or higher.
ynh_permission_update() {
# Declare an array to define the options of this helper.
local legacy_args=parltP
local -A args_array=([p]=permission= [a]=add= [r]=remove= [l]=label= [t]=show_tile= [P]=protected=)
local permission
local add
@ -337,7 +332,6 @@ ynh_permission_update() {
#
# Requires YunoHost version 3.7.1 or higher.
ynh_permission_has_user() {
local legacy_args=pu
# Declare an array to define the options of this helper.
local -A args_array=([p]=permission= [u]=user=)
local permission

View file

@ -70,7 +70,6 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION}
ynh_add_fpm_config() {
local _globalphpversion=${phpversion-:}
# Declare an array to define the options of this helper.
local legacy_args=vufg
local -A args_array=([v]=phpversion= [u]=usage= [f]=footprint= [g]=group=)
local group
local phpversion
@ -243,7 +242,6 @@ ynh_remove_fpm_config() {
#
# | arg: -p, --print - Print the result (intended for debug purpose only when packaging the app)
ynh_get_scalable_phpfpm() {
local legacy_args=ufp
# Declare an array to define the options of this helper.
local -A args_array=([u]=usage= [f]=footprint= [p]=print)
local usage
@ -376,7 +374,6 @@ YNH_COMPOSER_VERSION=${YNH_COMPOSER_VERSION:-$YNH_DEFAULT_COMPOSER_VERSION}
ynh_composer_exec() {
local _globalphpversion=${phpversion-:}
# Declare an array to define the options of this helper.
local legacy_args=vwc
declare -Ar args_array=([v]=phpversion= [w]=workdir= [c]=commands=)
local phpversion
local workdir
@ -408,7 +405,6 @@ ynh_composer_exec() {
ynh_install_composer() {
local _globalphpversion=${phpversion-:}
# Declare an array to define the options of this helper.
local legacy_args=vwac
declare -Ar args_array=([v]=phpversion= [w]=workdir= [a]=install_args= [c]=composerversion=)
local phpversion
local workdir

View file

@ -17,7 +17,6 @@ PSQL_VERSION=13
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_connect_as() {
# Declare an array to define the options of this helper.
local legacy_args=upd
local -A args_array=([u]=user= [p]=password= [d]=database=)
local user
local password
@ -38,7 +37,6 @@ ynh_psql_connect_as() {
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_execute_as_root() {
# Declare an array to define the options of this helper.
local legacy_args=sd
local -A args_array=([s]=sql= [d]=database=)
local sql
local database
@ -63,7 +61,6 @@ ynh_psql_execute_as_root() {
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_execute_file_as_root() {
# Declare an array to define the options of this helper.
local legacy_args=fd
local -A args_array=([f]=file= [d]=database=)
local file
local database
@ -134,7 +131,6 @@ ynh_psql_drop_db() {
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_dump_db() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=([d]=database=)
local database
# Manage arguments with getopts
@ -169,7 +165,6 @@ ynh_psql_create_user() {
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_user_exists() {
# Declare an array to define the options of this helper.
local legacy_args=u
local -A args_array=([u]=user=)
local user
# Manage arguments with getopts
@ -191,7 +186,6 @@ ynh_psql_user_exists() {
# Requires YunoHost version 3.5.0 or higher.
ynh_psql_database_exists() {
# Declare an array to define the options of this helper.
local legacy_args=d
local -A args_array=([d]=database=)
local database
# Manage arguments with getopts
@ -201,7 +195,7 @@ ynh_psql_database_exists() {
# though it could exists.
if ! command -v psql
then
ynh_print_err -m "PostgreSQL is not installed, impossible to check for db existence."
ynh_print_err --message="PostgreSQL is not installed, impossible to check for db existence."
return 1
elif ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"; then
return 1
@ -237,7 +231,6 @@ ynh_psql_drop_user() {
# Requires YunoHost version 2.7.13 or higher.
ynh_psql_setup_db() {
# Declare an array to define the options of this helper.
local legacy_args=unp
local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=)
local db_user
local db_name
@ -270,7 +263,6 @@ ynh_psql_setup_db() {
# Requires YunoHost version 2.7.13 or higher.
ynh_psql_remove_db() {
# Declare an array to define the options of this helper.
local legacy_args=un
local -A args_array=([u]=db_user= [n]=db_name=)
local db_user
local db_name

View file

@ -97,7 +97,6 @@ ynh_use_ruby () {
# Requires YunoHost version 3.2.2 or higher.
ynh_install_ruby () {
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=ruby_version= )
local ruby_version
# Manage arguments with getopts

View file

@ -10,7 +10,6 @@
ynh_app_setting_get() {
local _globalapp=${app-:}
# Declare an array to define the options of this helper.
local legacy_args=ak
local -A args_array=([a]=app= [k]=key=)
local app
local key
@ -32,7 +31,6 @@ ynh_app_setting_get() {
ynh_app_setting_set() {
local _globalapp=${app-:}
# Declare an array to define the options of this helper.
local legacy_args=akv
local -A args_array=([a]=app= [k]=key= [v]=value=)
local app
local key
@ -54,7 +52,6 @@ ynh_app_setting_set() {
ynh_app_setting_delete() {
local _globalapp=${app-:}
# Declare an array to define the options of this helper.
local legacy_args=ak
local -A args_array=([a]=app= [k]=key=)
local app
local key
@ -112,7 +109,6 @@ EOF
# 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
local -A args_array=([d]=domain= [p]=path_url=)
local domain
local path_url
@ -136,7 +132,6 @@ ynh_webpath_available() {
# 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
local -A args_array=([a]=app= [d]=domain= [p]=path_url=)
local app
local domain

View file

@ -12,7 +12,6 @@
# Requires YunoHost version 2.2.4 or higher.
ynh_string_random() {
# Declare an array to define the options of this helper.
local legacy_args=lf
local -A args_array=([l]=length= [f]=filter=)
local length
local filter
@ -39,7 +38,6 @@ ynh_string_random() {
# 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
local -A args_array=([m]=match_string= [r]=replace_string= [f]=target_file=)
local match_string
local replace_string
@ -70,7 +68,6 @@ ynh_replace_string() {
# 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
local -A args_array=([m]=match_string= [r]=replace_string= [f]=target_file=)
local match_string
local replace_string
@ -104,7 +101,6 @@ ynh_replace_special_string() {
# 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
local -A args_array=([n]=db_name=)
local db_name
# Manage arguments with getopts
@ -134,7 +130,6 @@ ynh_sanitize_dbid() {
# 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
local -A args_array=([p]=path_url=)
local path_url
# Manage arguments with getopts

View file

@ -14,7 +14,6 @@
# Requires YunoHost version 4.1.0 or higher.
ynh_add_systemd_config() {
# Declare an array to define the options of this helper.
local legacy_args=stv
local -A args_array=([s]=service= [t]=template=)
local service
local template
@ -37,7 +36,6 @@ ynh_add_systemd_config() {
# 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
local -A args_array=([s]=service=)
local service
# Manage arguments with getopts
@ -66,7 +64,6 @@ ynh_remove_systemd_config() {
# Requires YunoHost version 3.5.0 or higher.
ynh_systemd_action() {
# Declare an array to define the options of this helper.
local legacy_args=nalpte
local -A args_array=([n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length=)
local service_name
local action

View file

@ -11,7 +11,6 @@
# 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
local -A args_array=([u]=username=)
local username
# Manage arguments with getopts
@ -32,7 +31,6 @@ ynh_user_exists() {
# 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
local -A args_array=([u]=username= [k]=key=)
local username
local key
@ -65,7 +63,6 @@ ynh_user_list() {
# 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
local -A args_array=([u]=username=)
local username
# Manage arguments with getopts
@ -85,7 +82,6 @@ ynh_system_user_exists() {
# Requires YunoHost version 3.5.0.2 or higher.
ynh_system_group_exists() {
# Declare an array to define the options of this helper.
local legacy_args=g
local -A args_array=([g]=group=)
local group
# Manage arguments with getopts
@ -116,7 +112,6 @@ ynh_system_group_exists() {
# 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
local -A args_array=([u]=username= [h]=home_dir= [s]=use_shell [g]=groups=)
local username
local home_dir
@ -129,7 +124,7 @@ ynh_system_user_create() {
home_dir="${home_dir:-}"
groups="${groups:-}"
if ! ynh_system_user_exists "$username"; then # Check if the user exists on the system
if ! ynh_system_user_exists --username="$username"; then # Check if the user exists on the system
# If the user doesn't exist
if [ -n "$home_dir" ]; then # If a home dir is mentioned
local user_home_dir="--home-dir $home_dir"
@ -160,21 +155,20 @@ ynh_system_user_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
local -A args_array=([u]=username=)
local username
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Check if the user exists on the system
if ynh_system_user_exists "$username"; then
if ynh_system_user_exists --username="$username"; then
deluser $username
else
ynh_print_warn --message="The user $username was not found"
fi
# Check if the group exists on the system
if ynh_system_group_exists "$username"; then
if ynh_system_group_exists --group="$username"; then
delgroup $username
fi
}

View file

@ -155,7 +155,6 @@ fi
# Requires YunoHost version 2.6.4 or higher.
ynh_setup_source() {
# Declare an array to define the options of this helper.
local legacy_args=dsk
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=)
local dest_dir
local source_id
@ -186,8 +185,8 @@ ynh_setup_source() {
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
[[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?"
[[ -n "$src_url" ]] || ynh_die --message="No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die --message="No sha256 sum defined for source $source_id$arch_prefix ?"
if [[ -z "$src_format" ]]
then
@ -233,7 +232,7 @@ ynh_setup_source() {
if [[ "$src_extract" != "true" ]] && [[ "$src_extract" != "false" ]]
then
ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter"
ynh_die --message="For source $source_id, expected either 'true' or 'false' for the extract parameter"
fi
@ -251,7 +250,7 @@ ynh_setup_source() {
cp $local_src $src_filename
fi
[ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?"
[ -n "$src_url" ] || ynh_die --message="Couldn't parse SOURCE_URL from $src_file_path ?"
# If the file was prefetched but somehow doesn't match the sum, rm and redownload it
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
@ -436,14 +435,14 @@ ynh_local_curl() {
# Temporarily enable visitors if needed...
local visitors_enabled=$(ynh_permission_has_user "main" "visitors" && echo yes || echo no)
if [[ $visitors_enabled == "no" ]]; then
ynh_permission_update --permission "main" --add "visitors"
ynh_permission_update --permission="main" --add="visitors"
fi
# Curl the URL
curl --silent --show-error --insecure --location --header "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile
if [[ $visitors_enabled == "no" ]]; then
ynh_permission_update --permission "main" --remove "visitors"
ynh_permission_update --permission="main" --remove="visitors"
fi
}
@ -489,7 +488,6 @@ ynh_local_curl() {
# Requires YunoHost version 4.1.0 or higher.
ynh_add_config() {
# Declare an array to define the options of this helper.
local legacy_args=tdv
local -A args_array=([t]=template= [d]=destination=)
local template
local destination
@ -550,7 +548,6 @@ ynh_add_config() {
# Requires YunoHost version 4.1.0 or higher.
ynh_replace_vars() {
# Declare an array to define the options of this helper.
local legacy_args=f
local -A args_array=([f]=file=)
local file
# Manage arguments with getopts
@ -647,7 +644,6 @@ ynh_replace_vars() {
# Requires YunoHost version 4.3 or higher.
ynh_read_var_in_file() {
# Declare an array to define the options of this helper.
local legacy_args=fka
local -A args_array=([f]=file= [k]=key= [a]=after=)
local file
local key
@ -725,7 +721,6 @@ ynh_read_var_in_file() {
# Requires YunoHost version 4.3 or higher.
ynh_write_var_in_file() {
# Declare an array to define the options of this helper.
local legacy_args=fkva
local -A args_array=([f]=file= [k]=key= [v]=value= [a]=after=)
local file
local key
@ -873,7 +868,6 @@ _acceptable_path_to_delete() {
# 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
local -A args_array=([f]=file=)
local file
# Manage arguments with getopts
@ -907,7 +901,6 @@ ynh_secure_remove() {
# Requires YunoHost version 3.5.0 or higher.
ynh_read_manifest() {
# Declare an array to define the options of this helper.
local legacy_args=mk
local -A args_array=([m]=manifest= [k]=manifest_key=)
local manifest
local manifest_key
@ -923,7 +916,7 @@ ynh_read_manifest() {
then
manifest="$YNH_APP_BASEDIR/manifest.toml"
else
ynh_die --message "No manifest found !?"
ynh_die --message="No manifest found !?"
fi
fi
@ -950,7 +943,6 @@ ynh_read_manifest() {
# Requires YunoHost version 3.5.0 or higher.
ynh_app_upstream_version() {
# Declare an array to define the options of this helper.
local legacy_args=m
local -A args_array=([m]=manifest=)
local manifest
# Manage arguments with getopts
@ -981,7 +973,6 @@ ynh_app_upstream_version() {
# Requires YunoHost version 3.5.0 or higher.
ynh_app_package_version() {
# Declare an array to define the options of this helper.
local legacy_args=m
local -A args_array=([m]=manifest=)
local manifest
# Manage arguments with getopts
@ -1031,7 +1022,6 @@ ynh_check_app_version_changed() {
#
# Requires YunoHost version 3.8.0 or higher.
ynh_compare_current_package_version() {
local legacy_args=cv
declare -Ar args_array=([c]=comparison= [v]=version=)
local version
local comparison
@ -1077,7 +1067,7 @@ _ynh_apply_default_permissions() {
chmod o-rwx $target
chmod g-w $target
chown -R root:root $target
if ynh_system_user_exists $app; then
if ynh_system_user_exists --username=$app; then
chown $app:$app $target
fi