From 36e152c159587b66a58a4853826735b158b99c4a Mon Sep 17 00:00:00 2001 From: Gofannon <17145502+Gofannon@users.noreply.github.com> Date: Wed, 8 May 2019 14:40:34 +0200 Subject: [PATCH] Add helper 'exec_as' and use it --- scripts/_common.sh | 13 +++++++++++-- scripts/upgrade | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f0851b0..c85fc0e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,9 +8,18 @@ # EXPERIMENTAL HELPERS #================================================= -# Taken from https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_read_manifest/ynh_read_manifest_2#L14-L28 -# Idea from https://forum.yunohost.org/t/upgrade-script-how-to-modify-parameter-inside-configuration-file/5352/2 +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +# Source : https://github.com/YunoHost-Apps/Experimental_helpers/tree/master/ynh_exec_as +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 f35a96b..4bf48eb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -120,6 +120,7 @@ ynh_add_fpm_config # needs to be edited with latest version # Also avoid to make file "$final_path/version.php" writable +#exec_as "$app" "/usr/bin/php $YNH_CWD/upgrade_cheky.php $final_path" #================================================= # GENERIC FINALIZATION #=================================================