diff --git a/scripts/_common.sh b/scripts/_common.sh index 179e4f2..64d5b69 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,4 +16,18 @@ nodejs_version="12" #================================================= # FUTURE OFFICIAL HELPERS -#================================================= \ No newline at end of file +#================================================= + + +# Execute a command as another user +# usage: ynh_exec_as USER COMMAND [ARG ...] +ynh_exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo -u "$USER" "$@" + fi +} \ No newline at end of file