mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Move ynh_exec_as helper to user section
This commit is contained in:
parent
6e9ab553b8
commit
43f121baed
2 changed files with 24 additions and 24 deletions
|
@ -100,30 +100,6 @@ ynh_print_err () {
|
||||||
ynh_print_log "[Error] ${message}" >&2
|
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
|
# Execute a command and print the result as an error
|
||||||
#
|
#
|
||||||
# usage: ynh_exec_err your_command
|
# usage: ynh_exec_err your_command
|
||||||
|
|
|
@ -163,3 +163,27 @@ ynh_system_user_delete () {
|
||||||
delgroup $username
|
delgroup $username
|
||||||
fi
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue