diff --git a/helpers/helpers.v2.1.d/apps b/helpers/helpers.v2.1.d/apps index 2c6e95b37..e4d7f90ca 100644 --- a/helpers/helpers.v2.1.d/apps +++ b/helpers/helpers.v2.1.d/apps @@ -7,11 +7,11 @@ # # Requires YunoHost version *.*.* or higher. ynh_install_apps() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([a]=apps=) local apps - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Split the list of apps in an array local apps_list=($(echo $apps | tr " " "\n")) @@ -125,11 +125,11 @@ ynh_remove_apps() { # from the app's service configuration file (defaults to $app.service, overridable by the packager with `service` setting). # 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. + # ============ Argument parsing ============= local -A args_array=([a]=app=) local app - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Force Bash to be used to run this helper if [[ ! $0 =~ \/?bash$ ]] diff --git a/helpers/helpers.v2.1.d/apt b/helpers/helpers.v2.1.d/apt index ca792979d..2553cdc03 100644 --- a/helpers/helpers.v2.1.d/apt +++ b/helpers/helpers.v2.1.d/apt @@ -68,11 +68,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([p]=package=) local package - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ynh_package_is_installed "$package"; then dpkg-query --show --showformat='${Version}' "$package" 2>/dev/null @@ -344,11 +344,11 @@ EOF # # Requires YunoHost version 3.8.1 or higher. ynh_add_app_dependencies() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=package= [r]=replace) local package - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_print_warn --message="Packagers: ynh_add_app_dependencies is deprecated and is now only an alias to ynh_install_app_dependencies" ynh_install_app_dependencies "${package}" @@ -400,16 +400,16 @@ 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. + # ============ Argument parsing ============= local -A args_array=([r]=repo= [p]=package= [k]=key= [n]=name=) local repo local package local key local name - # Manage arguments with getopts ynh_handle_getopts_args "$@" name="${name:-$app}" key=${key:-} + # =========================================== # Set a key only if asked if [ -n "$key" ]; then @@ -444,19 +444,19 @@ 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. + # ============ Argument parsing ============= local -A args_array=([r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append) local repo local key local priority local name local append - # Manage arguments with getopts ynh_handle_getopts_args "$@" name="${name:-$app}" append=${append:-0} key=${key:-} priority=${priority:-} + # =========================================== if [ $append -eq 1 ]; then append="--append" @@ -512,12 +512,12 @@ 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. + # ============ Argument parsing ============= local -A args_array=([n]=name=) local name - # Manage arguments with getopts ynh_handle_getopts_args "$@" name="${name:-$app}" + # =========================================== ynh_secure_remove --file="/etc/apt/sources.list.d/$name.list" # Sury pinning is managed by the regenconf in the core... @@ -552,17 +552,17 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append) local uri local suite local component local name local append - # Manage arguments with getopts ynh_handle_getopts_args "$@" name="${name:-$app}" append=${append:-0} + # =========================================== if [ $append -eq 1 ]; then append="tee --append" @@ -591,19 +591,19 @@ ynh_add_repo() { # # Requires YunoHost version 3.8.1 or higher. ynh_pin_repo() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append) local package local pin local priority local name local append - # Manage arguments with getopts ynh_handle_getopts_args "$@" package="${package:-*}" priority=${priority:-50} name="${name:-$app}" append=${append:-0} + # =========================================== if [ $append -eq 1 ]; then append="tee --append" diff --git a/helpers/helpers.v2.1.d/backup b/helpers/helpers.v2.1.d/backup index b3834963f..820a2562d 100644 --- a/helpers/helpers.v2.1.d/backup +++ b/helpers/helpers.v2.1.d/backup @@ -64,17 +64,17 @@ CAN_BIND=${CAN_BIND:-1} ynh_backup() { # TODO find a way to avoid injection by file strange naming ! - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([s]=src_path= [d]=dest_path= [b]=is_big [m]=not_mandatory) local src_path local dest_path local is_big local not_mandatory - # Manage arguments with getopts ynh_handle_getopts_args "$@" dest_path="${dest_path:-}" is_big="${is_big:-0}" not_mandatory="${not_mandatory:-0}" + # =========================================== BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-0} test -n "${app:-}" && do_not_backup_data=$(ynh_app_setting_get --key=do_not_backup_data) @@ -235,17 +235,17 @@ with open(sys.argv[1], 'r') as backup_file: # Requires YunoHost version 2.6.4 or higher. # 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. + # ============ Argument parsing ============= local -A args_array=([o]=origin_path= [d]=dest_path= [m]=not_mandatory) local origin_path local dest_path local not_mandatory - # Manage arguments with getopts ynh_handle_getopts_args "$@" origin_path="/${origin_path#/}" # Default value for dest_path = /$origin_path dest_path="${dest_path:-$origin_path}" not_mandatory="${not_mandatory:-0}" + # =========================================== local archive_path="$YNH_CWD${origin_path}" # If archive_path doesn't exist, search for a corresponding path in CSV @@ -302,14 +302,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file= [u]=update_only) local file local update_only update_only="${update_only:-0}" - - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' @@ -352,11 +351,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file=) local file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' local checksum_value=$(ynh_app_setting_get --key=$checksum_setting_name) @@ -391,11 +390,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file=) local file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete --key=$checksum_setting_name diff --git a/helpers/helpers.v2.1.d/fail2ban b/helpers/helpers.v2.1.d/fail2ban index 9343d2bea..12c579db6 100644 --- a/helpers/helpers.v2.1.d/fail2ban +++ b/helpers/helpers.v2.1.d/fail2ban @@ -58,18 +58,18 @@ # # Requires YunoHost version 4.1.0 or higher. ynh_add_fail2ban_config() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([l]=logpath= [r]=failregex= [m]=max_retry= [p]=ports= [t]=use_template) local logpath local failregex local max_retry local ports local use_template - # Manage arguments with getopts ynh_handle_getopts_args "$@" max_retry=${max_retry:-3} ports=${ports:-http,https} use_template="${use_template:-0}" + # =========================================== if [ "$use_template" -ne 1 ]; then # Usage 1, no template. Build a config file from scratch. diff --git a/helpers/helpers.v2.1.d/go b/helpers/helpers.v2.1.d/go index 370f5541b..cf8290390 100644 --- a/helpers/helpers.v2.1.d/go +++ b/helpers/helpers.v2.1.d/go @@ -94,11 +94,11 @@ ynh_use_go () { # # Requires YunoHost version 3.2.2 or higher. ynh_install_go () { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [v]=go_version= ) local go_version - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Load goenv path in PATH local CLEAR_PATH="$goenv_install_dir/bin:$PATH" diff --git a/helpers/helpers.v2.1.d/hardware b/helpers/helpers.v2.1.d/hardware index aed1a18ba..678f381b1 100644 --- a/helpers/helpers.v2.1.d/hardware +++ b/helpers/helpers.v2.1.d/hardware @@ -13,18 +13,18 @@ # # Requires YunoHost version 3.8.1 or higher. ynh_get_ram() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([f]=free [t]=total [s]=ignore_swap [o]=only_swap) local free local total local ignore_swap local only_swap - # Manage arguments with getopts ynh_handle_getopts_args "$@" ignore_swap=${ignore_swap:-0} only_swap=${only_swap:-0} free=${free:-0} total=${total:-0} + # =========================================== if [ $free -eq $total ]; then ynh_print_warn --message="You have to choose --free or --total when using ynh_get_ram" @@ -76,14 +76,13 @@ ynh_get_ram() { # # Requires YunoHost version 3.8.1 or higher. ynh_require_ram() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([r]=required= [f]=free [t]=total [s]=ignore_swap [o]=only_swap) local required local free local total local ignore_swap local only_swap - # Manage arguments with getopts ynh_handle_getopts_args "$@" # Dunno if that's the right way to do, but that's some black magic to be able to # forward the bool args to ynh_get_ram easily? @@ -92,6 +91,7 @@ ynh_require_ram() { total=${total:+--total} ignore_swap=${ignore_swap:+--ignore_swap} only_swap=${only_swap:+--only_swap} + # =========================================== local ram=$(ynh_get_ram $free $total $ignore_swap $only_swap) diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index d761a20e5..1e4b15871 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -8,13 +8,13 @@ # # Requires YunoHost version 2.4.0 or higher. ynh_die() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=message= [c]=ret_code=) local message local ret_code - # Manage arguments with getopts ynh_handle_getopts_args "$@" ret_code=${ret_code:-1} + # =========================================== echo "$message" 1>&2 exit "$ret_code" @@ -27,11 +27,11 @@ ynh_die() { # # Requires YunoHost version 3.2.0 or higher. ynh_print_info() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=message=) local message - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== echo "$message" >&$YNH_STDINFO } @@ -52,11 +52,11 @@ ynh_print_log() { # # Requires YunoHost version 3.2.0 or higher. ynh_print_warn() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=message=) local message - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_print_log "${message}" >&2 } @@ -68,11 +68,11 @@ ynh_print_warn() { # # Requires YunoHost version 3.2.0 or higher. ynh_print_err() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=message=) local message - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_print_log "[Error] ${message}" >&2 } @@ -252,17 +252,19 @@ base_time=$(date +%s) # Requires YunoHost version 3.5.0 or higher. ynh_script_progression() { set +o xtrace # set +x - # Declare an array to define the options of this helper. + + # ============ Argument parsing ============= local -A args_array=([m]=message= [w]=weight= [t]=time [l]=last) local message local weight local time local last - # Manage arguments with getopts ynh_handle_getopts_args "$@" + weight=${weight:-1} + # =========================================== + # Re-disable xtrace, ynh_handle_getopts_args set it back set +o xtrace # set +x - weight=${weight:-1} # Always activate time when running inside CI tests if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then diff --git a/helpers/helpers.v2.1.d/logrotate b/helpers/helpers.v2.1.d/logrotate index 4f5cb69e9..970377acf 100644 --- a/helpers/helpers.v2.1.d/logrotate +++ b/helpers/helpers.v2.1.d/logrotate @@ -26,13 +26,14 @@ ynh_use_logrotate() { done set -- "${all_args[@]}" - # Argument parsing + # ============ Argument parsing ============= local -A args_array=([l]=logfile= [u]=specific_user=) local logfile local specific_user ynh_handle_getopts_args "$@" logfile="${logfile:-}" specific_user="${specific_user:-}" + # =========================================== set -o noglob if [[ -z "$logfile" ]]; then diff --git a/helpers/helpers.v2.1.d/mongodb b/helpers/helpers.v2.1.d/mongodb index b81050462..c86369590 100644 --- a/helpers/helpers.v2.1.d/mongodb +++ b/helpers/helpers.v2.1.d/mongodb @@ -17,7 +17,7 @@ # # ynh_mongo_exec() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval ) local user local password @@ -27,7 +27,6 @@ ynh_mongo_exec() { local port local command local eval - # Manage arguments with getopts ynh_handle_getopts_args "$@" user="${user:-}" password="${password:-}" @@ -36,6 +35,7 @@ ynh_mongo_exec() { host="${host:-}" port="${port:-}" eval=${eval:-0} + # =========================================== # If user is provided if [ -n "$user" ] @@ -113,11 +113,11 @@ EOF # # ynh_mongo_drop_db() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [d]=database= ) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_mongo_exec --database="$database" --command='db.runCommand({dropDatabase: 1})' } @@ -132,11 +132,11 @@ ynh_mongo_drop_db() { # # ynh_mongo_dump_db() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [d]=database= ) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== mongodump --quiet --db="$database" --archive } @@ -152,13 +152,13 @@ ynh_mongo_dump_db() { # # ynh_mongo_create_user() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) local db_user local db_name local db_pwd - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Create the user and set the user as admin of the db ynh_mongo_exec --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' @@ -175,11 +175,11 @@ ynh_mongo_create_user() { # # ynh_mongo_database_exists() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([d]=database=) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ] then @@ -198,11 +198,11 @@ ynh_mongo_database_exists() { # # ynh_mongo_restore_db() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [d]=database= ) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== mongorestore --quiet --db="$database" --archive } @@ -217,12 +217,12 @@ ynh_mongo_restore_db() { # # ynh_mongo_drop_user() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [u]=db_user= [n]=db_name= ) local db_user local db_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_mongo_exec --database="$db_name" --command='db.dropUser("'$db_user'", {w: "majority", wtimeout: 5000})' } @@ -239,13 +239,13 @@ ynh_mongo_drop_user() { # # ynh_mongo_setup_db() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) local db_user local db_name db_pwd="" - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== local new_db_pwd=$(ynh_string_random) # Generate a random password # If $db_pwd is not provided, use new_db_pwd instead for db_pwd @@ -266,12 +266,12 @@ ynh_mongo_setup_db() { # # ynh_mongo_remove_db() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [u]=db_user= [n]=db_name= ) local db_user local db_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ynh_mongo_database_exists --database=$db_name; then # Check if the database exists ynh_mongo_drop_db --database=$db_name # Remove the database @@ -290,12 +290,12 @@ ynh_mongo_remove_db() { # # ynh_install_mongo() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=mongo_version=) local mongo_version - # Manage arguments with getopts ynh_handle_getopts_args "$@" mongo_version="${mongo_version:-$YNH_MONGO_VERSION}" + # =========================================== ynh_print_info --message="Installing MongoDB Community Edition ..." local mongo_debian_release=$(ynh_get_debian_release) diff --git a/helpers/helpers.v2.1.d/multimedia b/helpers/helpers.v2.1.d/multimedia index b1d8a526e..16f085468 100644 --- a/helpers/helpers.v2.1.d/multimedia +++ b/helpers/helpers.v2.1.d/multimedia @@ -63,12 +63,12 @@ ynh_multimedia_build_main_dir() { # Requires YunoHost version 4.2 or higher. ynh_multimedia_addfolder() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([s]=source_dir= [d]=dest_dir=) local source_dir local dest_dir - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Ajout d'un lien symbolique vers le dossier à partager ln -sfn "$source_dir" "$MEDIA_DIRECTORY/$dest_dir" @@ -90,11 +90,12 @@ ynh_multimedia_addfolder() { # # Requires YunoHost version 4.2 or higher. ynh_multimedia_addaccess() { - # Declare an array to define the options of this helper. - declare -Ar args_array=([u]=user_name=) + + # ============ Argument parsing ============= + local -A args_array=([u]=user_name=) local user_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== groupadd -f multimedia usermod -a -G multimedia $user_name diff --git a/helpers/helpers.v2.1.d/mysql b/helpers/helpers.v2.1.d/mysql index 373bc6559..1f91735ed 100644 --- a/helpers/helpers.v2.1.d/mysql +++ b/helpers/helpers.v2.1.d/mysql @@ -13,14 +13,14 @@ # # Requires YunoHost version 2.2.4 or higher. ynh_mysql_connect_as() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([u]=user= [p]=password= [d]=database=) local user local password local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== mysql --user="$user" --password="$password" --batch "$database" } @@ -33,13 +33,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([s]=sql= [d]=database=) local sql local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== if [ -n "$database" ]; then database="--database=$database" @@ -56,13 +56,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file= [d]=database=) local file local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== if [ -n "$database" ]; then database="--database=$database" @@ -123,11 +123,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([d]=database=) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== mysqldump --single-transaction --skip-dump-date --routines "$database" } @@ -156,11 +156,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=user=) local user - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if [[ -z $(ynh_mysql_execute_as_root --sql="SELECT User from mysql.user WHERE User = '$user';") ]]; then return 1 @@ -195,13 +195,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=) local db_user local db_name db_pwd="" - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Generate a random password local new_db_pwd=$(ynh_string_random) @@ -225,12 +225,12 @@ 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. + # ============ Argument parsing ============= local -Ar args_array=([u]=db_user= [n]=db_name=) local db_user local db_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if mysqlshow | grep -q "^| $db_name "; then ynh_mysql_drop_db $db_name diff --git a/helpers/helpers.v2.1.d/network b/helpers/helpers.v2.1.d/network index c407af512..c7acf2cce 100644 --- a/helpers/helpers.v2.1.d/network +++ b/helpers/helpers.v2.1.d/network @@ -12,11 +12,11 @@ # # Requires YunoHost version 2.6.4 or higher. ynh_find_port() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=port=) local port - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== test -n "$port" || ynh_die --message="The argument of ynh_find_port must be a valid port." while ! ynh_port_available --port=$port; do @@ -37,11 +37,11 @@ ynh_find_port() { # # Requires YunoHost version 3.8.0 or higher. ynh_port_available() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=port=) local port - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Check if the port is free if ss --numeric --listening --tcp --udp | awk '{print$5}' | grep --quiet --extended-regexp ":$port$"; then @@ -67,12 +67,12 @@ ynh_port_available() { 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. + # ============ Argument parsing ============= local -A args_array=([f]=family= [i]=ip_address=) local family local ip_address - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== [ "$family" == "4" ] || [ "$family" == "6" ] || return 1 @@ -98,11 +98,11 @@ EOF # # Requires YunoHost version 2.2.4 or higher. ynh_validate_ip4() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([i]=ip_address=) local ip_address - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_validate_ip --family=4 --ip_address=$ip_address } @@ -117,11 +117,11 @@ ynh_validate_ip4() { # # Requires YunoHost version 2.2.4 or higher. ynh_validate_ip6() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([i]=ip_address=) local ip_address - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== ynh_validate_ip --family=6 --ip_address=$ip_address } diff --git a/helpers/helpers.v2.1.d/nodejs b/helpers/helpers.v2.1.d/nodejs index e158affec..74491a590 100644 --- a/helpers/helpers.v2.1.d/nodejs +++ b/helpers/helpers.v2.1.d/nodejs @@ -94,11 +94,11 @@ ynh_use_nodejs() { 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. + # ============ Argument parsing ============= local -A args_array=([n]=nodejs_version=) local nodejs_version - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Create $n_install_dir mkdir --parents "$n_install_dir" diff --git a/helpers/helpers.v2.1.d/permission b/helpers/helpers.v2.1.d/permission index bf2ca86ed..28847cd08 100644 --- a/helpers/helpers.v2.1.d/permission +++ b/helpers/helpers.v2.1.d/permission @@ -66,7 +66,7 @@ # # Requires YunoHost version 3.7.0 or higher. ynh_permission_create() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= 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 @@ -84,6 +84,7 @@ ynh_permission_create() { label=${label:-} show_tile=${show_tile:-} protected=${protected:-} + # =========================================== if [[ -n $url ]]; then url=",url='$url'" @@ -153,10 +154,11 @@ ynh_permission_create() { # # Requires YunoHost version 3.7.0 or higher. ynh_permission_delete() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=permission=) local permission ynh_handle_getopts_args "$@" + # =========================================== yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$app.$permission')" } @@ -171,10 +173,11 @@ ynh_permission_delete() { # # Requires YunoHost version 3.7.0 or higher. ynh_permission_exists() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=permission=) local permission ynh_handle_getopts_args "$@" + # =========================================== yunohost user permission list "$app" --output-as json --quiet \ | jq -e --arg perm "$app.$permission" '.permissions[$perm]' >/dev/null @@ -195,7 +198,7 @@ ynh_permission_exists() { # # Requires YunoHost version 3.7.0 or higher. ynh_permission_url() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=permission= [u]=url= [a]=add_url= [r]=remove_url= [h]=auth_header= [c]=clear_urls) local permission local url @@ -209,6 +212,7 @@ ynh_permission_url() { remove_url=${remove_url:-} auth_header=${auth_header:-} clear_urls=${clear_urls:-} + # =========================================== if [[ -n $url ]]; then url=",url='$url'" @@ -264,7 +268,7 @@ ynh_permission_url() { # # Requires YunoHost version 3.7.0 or higher. ynh_permission_update() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=permission= [a]=add= [r]=remove= [l]=label= [t]=show_tile= [P]=protected=) local permission local add @@ -278,6 +282,7 @@ ynh_permission_update() { label=${label:-} show_tile=${show_tile:-} protected=${protected:-} + # =========================================== if [[ -n $add ]]; then # Convert a list from getopts to python list @@ -332,12 +337,12 @@ ynh_permission_update() { # # Requires YunoHost version 3.7.1 or higher. ynh_permission_has_user() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([p]=permission= [u]=user=) local permission local user - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ! ynh_permission_exists --permission=$permission; then return 1 diff --git a/helpers/helpers.v2.1.d/php b/helpers/helpers.v2.1.d/php index fa1d3a4c2..d32e69392 100644 --- a/helpers/helpers.v2.1.d/php +++ b/helpers/helpers.v2.1.d/php @@ -68,16 +68,16 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION} # # Requires YunoHost version 4.1.0 or higher. ynh_add_fpm_config() { + # ============ Argument parsing ============= local _globalphpversion=${phpversion-:} - # Declare an array to define the options of this helper. local -A args_array=([v]=phpversion= [u]=usage= [f]=footprint= [g]=group=) local group local phpversion local usage local footprint - # Manage arguments with getopts ynh_handle_getopts_args "$@" group=${group:-} + # =========================================== # The default behaviour is to use the template. local autogenconf=false @@ -242,12 +242,11 @@ ynh_remove_fpm_config() { # # | arg: -p, --print - Print the result (intended for debug purpose only when packaging the app) ynh_get_scalable_phpfpm() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([u]=usage= [f]=footprint= [p]=print) local usage local footprint local print - # Manage arguments with getopts ynh_handle_getopts_args "$@" # Set all characters as lowercase footprint=${footprint,,} @@ -372,13 +371,12 @@ YNH_COMPOSER_VERSION=${YNH_COMPOSER_VERSION:-$YNH_DEFAULT_COMPOSER_VERSION} # # Requires YunoHost version 4.2 or higher. ynh_composer_exec() { + # ============ Argument parsing ============= local _globalphpversion=${phpversion-:} - # Declare an array to define the options of this helper. - declare -Ar args_array=([v]=phpversion= [w]=workdir= [c]=commands=) + local -A args_array=([v]=phpversion= [w]=workdir= [c]=commands=) local phpversion local workdir local commands - # Manage arguments with getopts ynh_handle_getopts_args "$@" workdir="${workdir:-${install_dir:-$final_path}}" @@ -403,15 +401,16 @@ ynh_composer_exec() { # # Requires YunoHost version 4.2 or higher. ynh_install_composer() { + # ============ Argument parsing ============= local _globalphpversion=${phpversion-:} - # Declare an array to define the options of this helper. - declare -Ar args_array=([v]=phpversion= [w]=workdir= [a]=install_args= [c]=composerversion=) + local -A args_array=([v]=phpversion= [w]=workdir= [a]=install_args= [c]=composerversion=) local phpversion local workdir local install_args local composerversion - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== + if dpkg --compare-versions ${YNH_APP_PACKAGING_FORMAT:-0} lt 2; then workdir="${workdir:-$final_path}" else diff --git a/helpers/helpers.v2.1.d/postgresql b/helpers/helpers.v2.1.d/postgresql index d3a80021a..b28e11e38 100644 --- a/helpers/helpers.v2.1.d/postgresql +++ b/helpers/helpers.v2.1.d/postgresql @@ -16,14 +16,14 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=user= [p]=password= [d]=database=) local user local password local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$password" psql "$database" } @@ -36,13 +36,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([s]=sql= [d]=database=) local sql local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== if [ -n "$database" ]; then database="--database=$database" @@ -60,13 +60,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file= [d]=database=) local file local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" database="${database:-}" + # =========================================== if [ -n "$database" ]; then database="--database=$database" @@ -130,11 +130,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([d]=database=) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== sudo --login --user=postgres pg_dump "$database" } @@ -164,11 +164,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=user=) local user - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT rolname FROM pg_roles WHERE rolname='$user';" | grep --quiet "$user"; then return 1 @@ -185,11 +185,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([d]=database=) local database - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # if psql is not there, we cannot check the db # though it could exists. @@ -230,13 +230,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=) local db_user local db_name db_pwd="" - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ! ynh_psql_user_exists --user=$db_user; then local new_db_pwd=$(ynh_string_random) # Generate a random password @@ -262,12 +262,12 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=db_user= [n]=db_name=) local db_user local db_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if ynh_psql_database_exists --database=$db_name; then # Check if the database exists ynh_psql_drop_db $db_name # Remove the database diff --git a/helpers/helpers.v2.1.d/ruby b/helpers/helpers.v2.1.d/ruby index 2b10ec618..99fa6f016 100644 --- a/helpers/helpers.v2.1.d/ruby +++ b/helpers/helpers.v2.1.d/ruby @@ -96,11 +96,11 @@ ynh_use_ruby () { # # Requires YunoHost version 3.2.2 or higher. ynh_install_ruby () { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=( [v]=ruby_version= ) local ruby_version - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Load rbenv path in PATH local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" diff --git a/helpers/helpers.v2.1.d/setting b/helpers/helpers.v2.1.d/setting index bd9aa2ab4..67c4d5f0d 100644 --- a/helpers/helpers.v2.1.d/setting +++ b/helpers/helpers.v2.1.d/setting @@ -8,14 +8,14 @@ # # Requires YunoHost version 2.2.4 or higher. ynh_app_setting_get() { + # ============ Argument parsing ============= local _globalapp=${app-:} - # Declare an array to define the options of this helper. local -A args_array=([a]=app= [k]=key=) local app local key - # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" + # =========================================== ynh_app_setting "get" "$app" "$key" } @@ -29,15 +29,15 @@ ynh_app_setting_get() { # # Requires YunoHost version 2.2.4 or higher. ynh_app_setting_set() { + # ============ Argument parsing ============= local _globalapp=${app-:} - # Declare an array to define the options of this helper. local -A args_array=([a]=app= [k]=key= [v]=value=) local app local key local value - # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" + # =========================================== ynh_app_setting "set" "$app" "$key" "$value" } @@ -50,14 +50,14 @@ ynh_app_setting_set() { # # Requires YunoHost version 2.2.4 or higher. ynh_app_setting_delete() { + # ============ Argument parsing ============= local _globalapp=${app-:} - # Declare an array to define the options of this helper. local -A args_array=([a]=app= [k]=key=) local app local key - # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" + # =========================================== ynh_app_setting "delete" "$app" "$key" } @@ -108,12 +108,12 @@ EOF # # Requires YunoHost version 2.6.4 or higher. ynh_webpath_available() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([d]=domain= [p]=path_url=) local domain local path_url - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== yunohost domain url-available $domain $path_url } @@ -131,13 +131,13 @@ ynh_webpath_available() { # # Requires YunoHost version 2.6.4 or higher. ynh_webpath_register() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([a]=app= [d]=domain= [p]=path_url=) local app local domain local path_url - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== yunohost app register-url $app $domain $path_url } diff --git a/helpers/helpers.v2.1.d/string b/helpers/helpers.v2.1.d/string index f022deab2..398facec2 100644 --- a/helpers/helpers.v2.1.d/string +++ b/helpers/helpers.v2.1.d/string @@ -11,14 +11,14 @@ # # Requires YunoHost version 2.2.4 or higher. ynh_string_random() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([l]=length= [f]=filter=) local length local filter - # Manage arguments with getopts ynh_handle_getopts_args "$@" length=${length:-24} filter=${filter:-'A-Za-z0-9'} + # =========================================== dd if=/dev/urandom bs=1 count=1000 2>/dev/null \ | tr --complement --delete "$filter" \ @@ -37,13 +37,13 @@ ynh_string_random() { # # Requires YunoHost version 2.6.4 or higher. ynh_replace_string() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=match_string= [r]=replace_string= [f]=target_file=) local match_string local replace_string local target_file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== set +o xtrace # set +x local delimit=$'\001' @@ -67,13 +67,13 @@ 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. + # ============ Argument parsing ============= local -A args_array=([m]=match_string= [r]=replace_string= [f]=target_file=) local match_string local replace_string local target_file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Escape any backslash to preserve them as simple backslash. match_string=${match_string//\\/"\\\\"} @@ -100,11 +100,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([n]=db_name=) local db_name - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # We should avoid having - and . in the name of databases. They are replaced by _ echo ${db_name//[-.]/_} @@ -129,11 +129,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([p]=path_url=) local path_url - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== test -n "$path_url" || ynh_die --message="ynh_normalize_url_path expect a URL path as first argument and received nothing." if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a / diff --git a/helpers/helpers.v2.1.d/systemd b/helpers/helpers.v2.1.d/systemd index 57d6b3802..d1742c23e 100644 --- a/helpers/helpers.v2.1.d/systemd +++ b/helpers/helpers.v2.1.d/systemd @@ -13,14 +13,14 @@ # # Requires YunoHost version 4.1.0 or higher. ynh_add_systemd_config() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([s]=service= [t]=template=) local service local template - # Manage arguments with getopts ynh_handle_getopts_args "$@" service="${service:-$app}" template="${template:-systemd.service}" + # =========================================== ynh_add_config --template="$template" --destination="/etc/systemd/system/$service.service" @@ -35,12 +35,12 @@ 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. + # ============ Argument parsing ============= local -A args_array=([s]=service=) local service - # Manage arguments with getopts ynh_handle_getopts_args "$@" local service="${service:-$app}" + # =========================================== local finalsystemdconf="/etc/systemd/system/$service.service" if [ -e "$finalsystemdconf" ]; then @@ -63,7 +63,7 @@ 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. + # ============ Argument parsing ============= local -A args_array=([n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length=) local service_name local action @@ -71,7 +71,6 @@ ynh_systemd_action() { local length local log_path local timeout - # Manage arguments with getopts ynh_handle_getopts_args "$@" service_name="${service_name:-$app}" action=${action:-start} @@ -79,6 +78,7 @@ ynh_systemd_action() { length=${length:-20} log_path="${log_path:-/var/log/$service_name/$service_name.log}" timeout=${timeout:-300} + # =========================================== # Manage case of service already stopped if [ "$action" == "stop" ] && ! systemctl is-active --quiet $service_name; then diff --git a/helpers/helpers.v2.1.d/user b/helpers/helpers.v2.1.d/user index 14a8e32b5..7ab2301fa 100644 --- a/helpers/helpers.v2.1.d/user +++ b/helpers/helpers.v2.1.d/user @@ -10,11 +10,11 @@ # # Requires YunoHost version 2.2.4 or higher. ynh_user_exists() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([u]=username=) local username - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== yunohost user list --output-as json --quiet | jq -e ".users.\"${username}\"" >/dev/null } @@ -30,12 +30,12 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=username= [k]=key=) local username local key - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== yunohost user info "$username" --output-as json --quiet | jq -r ".$key" } @@ -62,11 +62,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=username=) local username - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== getent passwd "$username" &>/dev/null } @@ -81,11 +81,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([g]=group=) local group - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== getent group "$group" &>/dev/null } @@ -111,18 +111,17 @@ 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. + # ============ Argument parsing ============= local -A args_array=([u]=username= [h]=home_dir= [s]=use_shell [g]=groups=) local username local home_dir local use_shell local groups - - # Manage arguments with getopts ynh_handle_getopts_args "$@" use_shell="${use_shell:-0}" home_dir="${home_dir:-}" groups="${groups:-}" + # =========================================== if ! ynh_system_user_exists --username="$username"; then # Check if the user exists on the system # If the user doesn't exist @@ -154,11 +153,11 @@ 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. + # ============ Argument parsing ============= 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="$username"; then diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index 4605a8dc2..627124bb6 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -137,18 +137,18 @@ fi # # Requires YunoHost version 2.6.4 or higher. ynh_setup_source() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=) local dest_dir local source_id local keep local full_replace - # Manage arguments with getopts ynh_handle_getopts_args "$@" keep="${keep:-}" full_replace="${full_replace:-0}" - source_id="${source_id:-main}" + # =========================================== + local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]") if jq -re ".url" <<< "$sources_json" then @@ -448,13 +448,13 @@ ynh_local_curl() { # # Requires YunoHost version 4.1.0 or higher. ynh_add_config() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([t]=template= [d]=destination=) local template local destination - # Manage arguments with getopts ynh_handle_getopts_args "$@" local template_path + # =========================================== if [ -f "$YNH_APP_BASEDIR/conf/$template" ]; then template_path="$YNH_APP_BASEDIR/conf/$template" @@ -506,11 +506,11 @@ ynh_add_config() { # # Requires YunoHost version 4.1.0 or higher. ynh_replace_vars() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([f]=file=) local file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== # Replace specific YunoHost variables if test -n "${path_url:-}"; then @@ -591,14 +591,14 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file= [k]=key= [a]=after=) local file local key local after - # Manage arguments with getopts ynh_handle_getopts_args "$@" after="${after:-}" + # =========================================== [[ -f $file ]] || ynh_die --message="File $file does not exists" @@ -668,15 +668,15 @@ 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. + # ============ Argument parsing ============= local -A args_array=([f]=file= [k]=key= [v]=value= [a]=after=) local file local key local value local after - # Manage arguments with getopts ynh_handle_getopts_args "$@" after="${after:-}" + # =========================================== [[ -f $file ]] || ynh_die --message="File $file does not exists" @@ -815,11 +815,11 @@ _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. + # ============ Argument parsing ============= local -A args_array=([f]=file=) local file - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== set +o xtrace # set +x if [ $# -ge 2 ]; then @@ -848,12 +848,12 @@ ynh_secure_remove() { # # Requires YunoHost version 3.5.0 or higher. ynh_read_manifest() { - # Declare an array to define the options of this helper. + # ============ Argument parsing ============= local -A args_array=([m]=manifest= [k]=manifest_key=) local manifest local manifest_key - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== if [ ! -e "${manifest:-}" ]; then # If the manifest isn't found, try the common place for backup and restore script. @@ -890,12 +890,12 @@ 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. + # ============ Argument parsing ============= local -A args_array=([m]=manifest=) local manifest - # Manage arguments with getopts ynh_handle_getopts_args "$@" manifest="${manifest:-}" + # =========================================== if [[ "$manifest" != "" ]] && [[ -e "$manifest" ]]; then version_key_=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version") @@ -920,11 +920,11 @@ 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. + # ============ Argument parsing ============= local -A args_array=([m]=manifest=) local manifest - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== version_key_=$YNH_APP_MANIFEST_VERSION echo "${version_key_/*~ynh/}" @@ -970,11 +970,12 @@ ynh_check_app_version_changed() { # # Requires YunoHost version 3.8.0 or higher. ynh_compare_current_package_version() { - declare -Ar args_array=([c]=comparison= [v]=version=) + # ============ Argument parsing ============= + local -A args_array=([c]=comparison= [v]=version=) local version local comparison - # Manage arguments with getopts ynh_handle_getopts_args "$@" + # =========================================== local current_version=$YNH_APP_CURRENT_VERSION