diff --git a/scripts/_common.sh b/scripts/_common.sh index 179e4f2..b546e94 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,4 +16,17 @@ 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 +} diff --git a/scripts/upgrade b/scripts/upgrade index 6a281ef..6df1a11 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -86,7 +86,7 @@ then #ynh_setup_source --dest_dir="$final_path" pushd $final_path - bower update + ynh_exec_warn_less ynh_exec_as $app bower update popd fi