From 96689d7a4446e0110cf20b1858f3921e11ff46f4 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 17 Sep 2020 10:25:34 +0200 Subject: [PATCH] fix --- scripts/_common.sh | 13 +++++++++++++ scripts/install | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index e6b8b7b..ee07fd7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -24,3 +24,16 @@ extra_php_dependencies="php${YNH_PHP_VERSION}-fpm php${YNH_PHP_VERSION}-curl php #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# 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/install b/scripts/install index 2f9579c..c06b45c 100644 --- a/scripts/install +++ b/scripts/install @@ -183,7 +183,7 @@ ynh_add_systemd_config # Set-up database and configuration #================================================= cd "$final_path" -php"${phpversion}" composer.phar $app:migrate +ynh_exec_as $app php"${phpversion}" composer.phar $app:migrate # ( # cd "$final_path"