From 43f121baede5d56f6811bcad731ab0533a30a738 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 28 Jan 2021 08:07:53 +0100 Subject: [PATCH] Move ynh_exec_as helper to user section --- data/helpers.d/logging | 24 ------------------------ data/helpers.d/user | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/data/helpers.d/logging b/data/helpers.d/logging index e5d208a0f..dc32ecba9 100644 --- a/data/helpers.d/logging +++ b/data/helpers.d/logging @@ -100,30 +100,6 @@ ynh_print_err () { ynh_print_log "[Error] ${message}" >&2 } -# Execute a command as another user -# -# usage: ynh_exec_as --user=USER --command=COMMAND [ARG ...] -# | arg: -u, --user= - the user that will execute the command -# | arg: -n, --command= - the command to be executed -# -# Requires YunoHost version 4.1.7 or higher. -ynh_exec_as() -{ - # Declare an array to define the options of this helper. - local legacy_args=uc - local -A args_array=( [u]=user= [c]=command= ) - local user - local command - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - if [[ $user = $(whoami) ]]; then - eval "$command" - else - sudo -u "$user" "$command" - fi -} - # Execute a command and print the result as an error # # usage: ynh_exec_err your_command diff --git a/data/helpers.d/user b/data/helpers.d/user index aeac3a9c5..f5d4b1680 100644 --- a/data/helpers.d/user +++ b/data/helpers.d/user @@ -163,3 +163,27 @@ ynh_system_user_delete () { delgroup $username fi } + +# Execute a command as another user +# +# usage: ynh_exec_as --user=USER --command=COMMAND [ARG ...] +# | arg: -u, --user= - the user that will execute the command +# | arg: -n, --command= - the command to be executed +# +# Requires YunoHost version 4.1.7 or higher. +ynh_exec_as() +{ + # Declare an array to define the options of this helper. + local legacy_args=uc + local -A args_array=( [u]=user= [c]=command= ) + local user + local command + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + if [[ $user = $(whoami) ]]; then + eval "$command" + else + sudo -u "$user" "$command" + fi +}