#!/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() { # 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 "$@" ynh_app_setting "get" "$app" "$key" } # 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() { # 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 "$@" ynh_app_setting "set" "$app" "$key" "$value" } # 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() { # 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 "$@" ynh_app_setting "delete" "$app" "$key" } # 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() { if [[ "$1" == "delete" ]] && [[ "$3" =~ ^(unprotected|skipped)_ ]] then current_value=$(ynh_app_setting_get --app=$app --key=$3) fi ACTION="$1" APP="$2" KEY="$3" VALUE="${4:-}" python2.7 - < domain.tld/app # /admin -> domain.tld/app/admin # domain.tld/app/api -> domain.tld/app/api # # 'url' can be later treated as a regex if it starts with "re:". # For example: # re:/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$ # re:domain.tld/app/api/[A-Z]*$ -> domain.tld/app/api/[A-Z]*$ # # Requires YunoHost version 3.7.0 or higher. ynh_permission_create() { # Declare an array to define the options of this helper. local legacy_args=pua local -A args_array=( [p]=permission= [u]=url= [a]=allowed= ) local permission local url local allowed ynh_handle_getopts_args "$@" url=${url:-} allowed=${allowed:-} if [[ -n $url ]] then url="'$url'" else url="None" fi 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)" } # Remove a permission for the app (note that when the app is removed all permission is automatically removed) # # example: ynh_permission_delete --permission=editors # # usage: ynh_permission_delete --permission="permission" # | arg: -p, --permission= - the name for the permission (by default a permission named "main" is removed automatically when the app is removed) # # Requires YunoHost version 3.7.0 or higher. ynh_permission_delete() { # Declare an array to define the options of this helper. local legacy_args=p 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', sync_perm=False)" } # Check if a permission exists # # usage: ynh_permission_exists --permission=permission # | arg: -p, --permission= - the permission to check # | exit: Return 1 if the permission doesn't exist, 0 otherwise # # Requires YunoHost version 3.7.0 or higher. ynh_permission_exists() { # Declare an array to define the options of this helper. local legacy_args=p local -A args_array=( [p]=permission= ) local permission ynh_handle_getopts_args "$@" yunohost user permission list --short | grep --word-regexp --quiet "$app.$permission" } # Redefine the url associated to a permission # # usage: ynh_permission_url --permission="permission" [--url="url"] # | arg: -p, --permission= - the name for the permission (by default a permission named "main" is removed automatically when the app is removed) # | arg: -u, --url= - (optional) URL for which access will be allowed/forbidden # # Requires YunoHost version 3.7.0 or higher. ynh_permission_url() { # Declare an array to define the options of this helper. local legacy_args=pu local -A args_array=([p]=permission= [u]=url=) local permission local url ynh_handle_getopts_args "$@" url=${url:-} if [[ -n $url ]] then url="'$url'" else url="None" fi yunohost tools shell -c "from yunohost.permission import permission_url; permission_url('$app.$permission', url=$url)" } # Update a permission for the app # # example: ynh_permission_update --permission admin --add=samdoe --remove=all_users # # usage: ynh_permission_update --permission="permission" [--add="group1 group2"] [--remove="group1 group2"] # | arg: -p, --permission= - the name for the permission (by default a permission named "main" already exist) # | arg: -a, --add= - the list of group or users to enable add to the permission # | arg: -r, --remove= - the list of group or users to remove from the permission # # Requires YunoHost version 3.7.0 or higher. ynh_permission_update() { # Declare an array to define the options of this helper. local legacy_args=par local -A args_array=( [p]=permission= [a]=add= [r]=remove= ) local permission local add local remove ynh_handle_getopts_args "$@" add=${add:-} remove=${remove:-} if [[ -n $add ]]; then add="--add ${add//';'/" "}" fi if [[ -n $remove ]]; then remove="--remove ${remove//';'/" "} " fi yunohost user permission update "$app.$permission" $add $remove } # Check if a permission has an user # # example: ynh_permission_has_user --permission=main --user=visitors # # usage: ynh_permission_has_user --permission=permission --user=user # | arg: -p, --permission= - the permission to check # | arg: -u, --user= - the user seek in the permission # | exit: Return 1 if the permission doesn't have that user or doesn't exist, 0 otherwise # # Requires YunoHost version 3.7.1 or higher. ynh_permission_has_user() { local legacy_args=pu # Declare an array to define the options of this helper. 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 fi yunohost user permission info "$app.$permission" | grep --word-regexp --quiet "$user" }