mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Remove getopts from ynh_exec_as
This commit is contained in:
parent
adc83b4c9c
commit
6efbc03d43
1 changed files with 6 additions and 14 deletions
|
@ -166,24 +166,16 @@ ynh_system_user_delete () {
|
||||||
|
|
||||||
# Execute a command as another user
|
# Execute a command as another user
|
||||||
#
|
#
|
||||||
# usage: ynh_exec_as --user=USER --command=COMMAND [ARG ...]
|
# usage: ynh_exec_as $USER 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.
|
# Requires YunoHost version 4.1.7 or higher.
|
||||||
ynh_exec_as()
|
ynh_exec_as() {
|
||||||
{
|
local user=$1
|
||||||
# Declare an array to define the options of this helper.
|
shift 1
|
||||||
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
|
if [[ $user = $(whoami) ]]; then
|
||||||
eval "$command"
|
eval "$@"
|
||||||
else
|
else
|
||||||
sudo -u "$user" "$command"
|
sudo -u "$user" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue