diff --git a/scripts/_common.sh b/scripts/_common.sh index 7912aa4..d7982dd 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,3 +17,16 @@ nodejs_version=14 #================================================= # 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 9ef0498..6c61460 100755 --- a/scripts/install +++ b/scripts/install @@ -87,7 +87,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user ..." --weight=1 +ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user ynh_system_user_create --username=$app --home_dir=$final_path @@ -99,7 +99,7 @@ ynh_script_progression --message="tiddlywiki..." --weight=2 pushd $final_path #$nodejs_path/node $final_path/tiddlywiki mywiki --init server - ynh_exec_as $app env "$ynh_node_load_PATH" $final_path/ mywiki --init server + ynh_exec_as $app env "$ynh_node_load_PATH" $final_path/tiddlywiki mywiki --init server popd #=================================================