Clean getopts arguments

This commit is contained in:
Maniack Crudelis 2020-04-20 21:00:45 +02:00
parent 3b653994c7
commit 6fb1e62a4c
7 changed files with 36 additions and 31 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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" ]

View file

@ -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

View file

@ -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

View file

@ -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/}"
}