mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Clean getopts arguments
This commit is contained in:
parent
3b653994c7
commit
6fb1e62a4c
7 changed files with 36 additions and 31 deletions
|
@ -53,9 +53,9 @@ ynh_backup() {
|
||||||
local not_mandatory
|
local not_mandatory
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
local dest_path="${dest_path:-}"
|
dest_path="${dest_path:-}"
|
||||||
local is_big="${is_big:-0}"
|
is_big="${is_big:-0}"
|
||||||
local not_mandatory="${not_mandatory:-0}"
|
not_mandatory="${not_mandatory:-0}"
|
||||||
|
|
||||||
BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-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)
|
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 legacy_args=odm
|
||||||
local -A args_array=( [o]=origin_path= [d]=dest_path= [m]=not_mandatory )
|
local -A args_array=( [o]=origin_path= [d]=dest_path= [m]=not_mandatory )
|
||||||
local origin_path
|
local origin_path
|
||||||
local archive_path
|
|
||||||
local dest_path
|
local dest_path
|
||||||
local not_mandatory
|
local not_mandatory
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
local origin_path="/${origin_path#/}"
|
origin_path="/${origin_path#/}"
|
||||||
local archive_path="$YNH_CWD${origin_path}"
|
|
||||||
# Default value for dest_path = /$origin_path
|
# Default value for dest_path = /$origin_path
|
||||||
local dest_path="${dest_path:-$origin_path}"
|
dest_path="${dest_path:-$origin_path}"
|
||||||
local not_mandatory="${not_mandatory:-0}"
|
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 archive_path doesn't exist, search for a corresponding path in CSV
|
||||||
if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]
|
if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -74,9 +74,10 @@ ynh_add_fail2ban_config () {
|
||||||
local use_template
|
local use_template
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
use_template="${use_template:-0}"
|
|
||||||
max_retry=${max_retry:-3}
|
max_retry=${max_retry:-3}
|
||||||
ports=${ports:-http,https}
|
ports=${ports:-http,https}
|
||||||
|
others_var=${others_var:-}
|
||||||
|
use_template="${use_template:-0}"
|
||||||
|
|
||||||
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
|
||||||
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
|
||||||
|
@ -96,7 +97,7 @@ ynh_add_fail2ban_config () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Replace all other variable given as arguments
|
# Replace all other variable given as arguments
|
||||||
for var_to_replace in ${others_var:-}
|
for var_to_replace in $others_var
|
||||||
do
|
do
|
||||||
# ${var_to_replace^^} make the content of the variable on upper-cases
|
# ${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
|
# ${!var_to_replace} get the content of the variable named $var_to_replace
|
||||||
|
|
|
@ -15,9 +15,10 @@ ynh_die() {
|
||||||
local ret_code
|
local ret_code
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
ret_code=${ret_code:-1}
|
||||||
|
|
||||||
echo "$message" 1>&2
|
echo "$message" 1>&2
|
||||||
exit "${ret_code:-1}"
|
exit "$ret_code"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display a message in the 'INFO' logging category
|
# Display a message in the 'INFO' logging category
|
||||||
|
|
|
@ -26,9 +26,9 @@ ynh_use_logrotate () {
|
||||||
local specific_user
|
local specific_user
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
local logfile="${logfile:-}"
|
logfile="${logfile:-}"
|
||||||
local nonappend="${nonappend:-0}"
|
nonappend="${nonappend:-0}"
|
||||||
local specific_user="${specific_user:-}"
|
specific_user="${specific_user:-}"
|
||||||
|
|
||||||
# LEGACY CODE - PRE GETOPTS
|
# LEGACY CODE - PRE GETOPTS
|
||||||
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]
|
if [ $# -gt 0 ] && [ "$1" == "--non-append" ]
|
||||||
|
|
|
@ -185,19 +185,21 @@ ynh_permission_create() {
|
||||||
local url
|
local url
|
||||||
local allowed
|
local allowed
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
url=${url:-}
|
||||||
|
allowed=${allowed:-}
|
||||||
|
|
||||||
if [[ -n ${url:-} ]]
|
if [[ -n $url ]]
|
||||||
then
|
then
|
||||||
url="'$url'"
|
url="'$url'"
|
||||||
else
|
else
|
||||||
url="None"
|
url="None"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${allowed:-} ]]; then
|
if [[ -n $allowed ]]; then
|
||||||
allowed=",allowed=['${allowed//';'/"','"}']"
|
allowed=",allowed=['${allowed//';'/"','"}']"
|
||||||
fi
|
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)
|
# 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 permission
|
||||||
local url
|
local url
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
url=${url:-}
|
||||||
|
|
||||||
if [[ -n ${url:-} ]]
|
if [[ -n $url ]]
|
||||||
then
|
then
|
||||||
url="'$url'"
|
url="'$url'"
|
||||||
else
|
else
|
||||||
|
@ -279,15 +282,17 @@ ynh_permission_update() {
|
||||||
local add
|
local add
|
||||||
local remove
|
local remove
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
add=${add:-}
|
||||||
|
remove=${remove:-}
|
||||||
|
|
||||||
if [[ -n ${add:-} ]]; then
|
if [[ -n $add ]]; then
|
||||||
add="--add ${add//';'/" "}"
|
add="--add ${add//';'/" "}"
|
||||||
fi
|
fi
|
||||||
if [[ -n ${remove:-} ]]; then
|
if [[ -n $remove ]]; then
|
||||||
remove="--remove ${remove//';'/" "} "
|
remove="--remove ${remove//';'/" "} "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yunohost user permission update "$app.$permission" ${add:-} ${remove:-}
|
yunohost user permission update "$app.$permission" $add $remove
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if a permission has an user
|
# Check if a permission has an user
|
||||||
|
|
|
@ -89,18 +89,17 @@ ynh_systemd_action() {
|
||||||
local length
|
local length
|
||||||
local log_path
|
local log_path
|
||||||
local timeout
|
local timeout
|
||||||
|
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
service_name="${service_name:-$app}"
|
||||||
local service_name="${service_name:-$app}"
|
action=${action:-start}
|
||||||
local action=${action:-start}
|
line_match=${line_match:-}
|
||||||
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
length=${length:-20}
|
||||||
local length=${length:-20}
|
log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
||||||
local timeout=${timeout:-300}
|
timeout=${timeout:-300}
|
||||||
|
|
||||||
# Start to read the log
|
# Start to read the log
|
||||||
if [[ -n "${line_match:-}" ]]
|
if [[ -n "$line_match" ]]
|
||||||
then
|
then
|
||||||
local templog="$(mktemp)"
|
local templog="$(mktemp)"
|
||||||
# Following the starting of the app in its log
|
# Following the starting of the app in its log
|
||||||
|
|
|
@ -426,8 +426,8 @@ ynh_app_upstream_version () {
|
||||||
local manifest
|
local manifest
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
manifest="${manifest:-../manifest.json}"
|
manifest="${manifest:-../manifest.json}"
|
||||||
|
|
||||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||||
echo "${version_key/~ynh*/}"
|
echo "${version_key/~ynh*/}"
|
||||||
}
|
}
|
||||||
|
@ -451,8 +451,8 @@ ynh_app_package_version () {
|
||||||
local manifest
|
local manifest
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
manifest="${manifest:-../manifest.json}"
|
manifest="${manifest:-../manifest.json}"
|
||||||
|
|
||||||
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
version_key=$(ynh_read_manifest --manifest="$manifest" --manifest_key="version")
|
||||||
echo "${version_key/*~ynh/}"
|
echo "${version_key/*~ynh/}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue