Remove getopts from ynh_exec_as

This commit is contained in:
Alexandre Aubin 2021-02-03 16:50:04 +01:00
parent adc83b4c9c
commit 6efbc03d43

View file

@ -166,24 +166,16 @@ ynh_system_user_delete () {
# 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
# usage: ynh_exec_as $USER COMMAND [ARG ...]
#
# 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 "$@"
ynh_exec_as() {
local user=$1
shift 1
if [[ $user = $(whoami) ]]; then
eval "$command"
eval "$@"
else
sudo -u "$user" "$command"
sudo -u "$user" "$@"
fi
}