From 6fb1e62a4c79035c7a0a7d67b985386bad543373 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 20 Apr 2020 21:00:45 +0200 Subject: [PATCH] Clean getopts arguments --- data/helpers.d/backup | 15 +++++++-------- data/helpers.d/fail2ban | 5 +++-- data/helpers.d/logging | 3 ++- data/helpers.d/logrotate | 6 +++--- data/helpers.d/setting | 19 ++++++++++++------- data/helpers.d/systemd | 15 +++++++-------- data/helpers.d/utils | 4 ++-- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/data/helpers.d/backup b/data/helpers.d/backup index 2fae73ba0..9603ba525 100644 --- a/data/helpers.d/backup +++ b/data/helpers.d/backup @@ -53,9 +53,9 @@ ynh_backup() { local not_mandatory # Manage arguments with getopts ynh_handle_getopts_args "$@" - local dest_path="${dest_path:-}" - local is_big="${is_big:-0}" - local not_mandatory="${not_mandatory:-0}" + 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 --app=$app --key=do_not_backup_data) @@ -229,17 +229,16 @@ ynh_restore_file () { local legacy_args=odm local -A args_array=( [o]=origin_path= [d]=dest_path= [m]=not_mandatory ) local origin_path - local archive_path local dest_path local not_mandatory # Manage arguments with getopts ynh_handle_getopts_args "$@" - local origin_path="/${origin_path#/}" - local archive_path="$YNH_CWD${origin_path}" + origin_path="/${origin_path#/}" # Default value for dest_path = /$origin_path - local dest_path="${dest_path:-$origin_path}" - local not_mandatory="${not_mandatory:-0}" + 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 if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ] then diff --git a/data/helpers.d/fail2ban b/data/helpers.d/fail2ban index 1eef67f5c..54581483d 100644 --- a/data/helpers.d/fail2ban +++ b/data/helpers.d/fail2ban @@ -74,9 +74,10 @@ ynh_add_fail2ban_config () { local use_template # Manage arguments with getopts ynh_handle_getopts_args "$@" - use_template="${use_template:-0}" max_retry=${max_retry:-3} ports=${ports:-http,https} + others_var=${others_var:-} + use_template="${use_template:-0}" finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf" finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf" @@ -96,7 +97,7 @@ ynh_add_fail2ban_config () { fi # Replace all other variable given as arguments - for var_to_replace in ${others_var:-} + for var_to_replace in $others_var do # ${var_to_replace^^} make the content of the variable on upper-cases # ${!var_to_replace} get the content of the variable named $var_to_replace diff --git a/data/helpers.d/logging b/data/helpers.d/logging index 49374ec1e..37dfd286c 100644 --- a/data/helpers.d/logging +++ b/data/helpers.d/logging @@ -15,9 +15,10 @@ ynh_die() { local ret_code # Manage arguments with getopts ynh_handle_getopts_args "$@" + ret_code=${ret_code:-1} echo "$message" 1>&2 - exit "${ret_code:-1}" + exit "$ret_code" } # Display a message in the 'INFO' logging category diff --git a/data/helpers.d/logrotate b/data/helpers.d/logrotate index 0fcc63009..7df954c15 100644 --- a/data/helpers.d/logrotate +++ b/data/helpers.d/logrotate @@ -26,9 +26,9 @@ ynh_use_logrotate () { local specific_user # Manage arguments with getopts ynh_handle_getopts_args "$@" - local logfile="${logfile:-}" - local nonappend="${nonappend:-0}" - local specific_user="${specific_user:-}" + logfile="${logfile:-}" + nonappend="${nonappend:-0}" + specific_user="${specific_user:-}" # LEGACY CODE - PRE GETOPTS if [ $# -gt 0 ] && [ "$1" == "--non-append" ] diff --git a/data/helpers.d/setting b/data/helpers.d/setting index 00a2a5188..61397151b 100644 --- a/data/helpers.d/setting +++ b/data/helpers.d/setting @@ -185,19 +185,21 @@ ynh_permission_create() { local url local allowed ynh_handle_getopts_args "$@" + url=${url:-} + allowed=${allowed:-} - if [[ -n ${url:-} ]] + if [[ -n $url ]] then url="'$url'" else url="None" fi - if [[ -n ${allowed:-} ]]; then + if [[ -n $allowed ]]; then allowed=",allowed=['${allowed//';'/"','"}']" fi - yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url ${allowed:-} , sync_perm=False)" + yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$app.$permission', url=$url $allowed , sync_perm=False)" } # Remove a permission for the app (note that when the app is removed all permission is automatically removed) @@ -249,8 +251,9 @@ ynh_permission_url() { local permission local url ynh_handle_getopts_args "$@" + url=${url:-} - if [[ -n ${url:-} ]] + if [[ -n $url ]] then url="'$url'" else @@ -279,15 +282,17 @@ ynh_permission_update() { local add local remove ynh_handle_getopts_args "$@" + add=${add:-} + remove=${remove:-} - if [[ -n ${add:-} ]]; then + if [[ -n $add ]]; then add="--add ${add//';'/" "}" fi - if [[ -n ${remove:-} ]]; then + if [[ -n $remove ]]; then remove="--remove ${remove//';'/" "} " fi - yunohost user permission update "$app.$permission" ${add:-} ${remove:-} + yunohost user permission update "$app.$permission" $add $remove } # Check if a permission has an user diff --git a/data/helpers.d/systemd b/data/helpers.d/systemd index 5117aeb99..c718e50c2 100644 --- a/data/helpers.d/systemd +++ b/data/helpers.d/systemd @@ -89,18 +89,17 @@ ynh_systemd_action() { local length local log_path local timeout - # Manage arguments with getopts ynh_handle_getopts_args "$@" - - local service_name="${service_name:-$app}" - local action=${action:-start} - local log_path="${log_path:-/var/log/$service_name/$service_name.log}" - local length=${length:-20} - local timeout=${timeout:-300} + service_name="${service_name:-$app}" + action=${action:-start} + line_match=${line_match:-} + length=${length:-20} + log_path="${log_path:-/var/log/$service_name/$service_name.log}" + timeout=${timeout:-300} # Start to read the log - if [[ -n "${line_match:-}" ]] + if [[ -n "$line_match" ]] then local templog="$(mktemp)" # Following the starting of the app in its log diff --git a/data/helpers.d/utils b/data/helpers.d/utils index 46242e634..13d3a5dcd 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -426,8 +426,8 @@ ynh_app_upstream_version () { local manifest # Manage arguments with getopts ynh_handle_getopts_args "$@" - manifest="${manifest:-../manifest.json}" + version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version") echo "${version_key/~ynh*/}" } @@ -451,8 +451,8 @@ ynh_app_package_version () { local manifest # Manage arguments with getopts ynh_handle_getopts_args "$@" - manifest="${manifest:-../manifest.json}" + version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version") echo "${version_key/*~ynh/}" }