#!/bin/bash # Get an application setting # # usage: ynh_app_setting_get --app=app --key=key # | arg: -a, --app= - the application id # | arg: -k, --key= - the setting to get # # Requires YunoHost version 2.2.4 or higher. 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 # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" if [[ $key =~ (unprotected|protected|skipped)_ ]]; then yunohost app setting $app $key else ynh_app_setting "get" "$app" "$key" fi } # Set an application setting # # usage: ynh_app_setting_set --app=app --key=key --value=value # | arg: -a, --app= - the application id # | arg: -k, --key= - the setting name to set # | arg: -v, --value= - the setting value to set # # Requires YunoHost version 2.2.4 or higher. 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 local value # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" if [[ $key =~ (unprotected|protected|skipped)_ ]]; then yunohost app setting $app $key -v $value else ynh_app_setting "set" "$app" "$key" "$value" fi } # Set an application setting but only if the "$key" variable ain't set yet # # Note that it doesn't just define the setting but ALSO define the $foobar variable # # Hence it's meant as a replacement for this legacy overly complex syntax: # # if [ -z "${foo:-}" ] # then # foo="bar" # ynh_app_setting_set --key="foo" --value="$foo" # fi # # usage: ynh_app_setting_set_default --app=app --key=key --value=value # | arg: -a, --app= - the application id # | arg: -k, --key= - the setting name to set # | arg: -v, --value= - the default setting value to set # # Requires YunoHost version 11.1.16 or higher. ynh_app_setting_set_default() { 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 local value # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" if [ -z "${!key:-}" ]; then eval $key=\$value ynh_app_setting "set" "$app" "$key" "$value" fi } # Delete an application setting # # usage: ynh_app_setting_delete --app=app --key=key # | arg: -a, --app= - the application id # | arg: -k, --key= - the setting to delete # # Requires YunoHost version 2.2.4 or higher. 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 # Manage arguments with getopts ynh_handle_getopts_args "$@" app="${app:-$_globalapp}" if [[ "$key" =~ (unprotected|skipped|protected)_ ]]; then yunohost app setting $app $key -d else ynh_app_setting "delete" "$app" "$key" fi } # Small "hard-coded" interface to avoid calling "yunohost app" directly each # time dealing with a setting is needed (which may be so slow on ARM boards) # # [internal] # ynh_app_setting() { set +o xtrace # set +x ACTION="$1" APP="$2" KEY="$3" VALUE="${4:-}" python3 - <