From 3ca92dc581a9725f116821a873358fd7e701eb03 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Thu, 3 Jun 2021 14:48:24 +0200 Subject: [PATCH] ynh_exec_as --- scripts/_common.sh | 13 ------------- scripts/install | 7 +++---- scripts/upgrade | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 303a1ae..8834c3a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,19 +21,6 @@ exec_login_as() { exec_as $user --login "$@" } -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -exec_as() { - local user=$1 - shift 1 - - if [[ $user = $(whoami) ]]; then - eval "$@" - else - sudo -u "$user" "$@" - fi -} - # Returns true if a swap partition is enabled, false otherwise # usage: is_swap_present is_swap_present() { diff --git a/scripts/install b/scripts/install index 1cc4b68..b1667a9 100644 --- a/scripts/install +++ b/scripts/install @@ -72,11 +72,10 @@ ynh_script_progression --message="Creating a PostgreSQL database..." db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name # Set extensions ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name @@ -169,7 +168,7 @@ pushd "$final_path" # Install bundler, a gems installer gem install bundler # Install without documentation - exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" popd # Specific actions on ARM architecture diff --git a/scripts/upgrade b/scripts/upgrade index fd92a58..1536959 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -247,7 +247,7 @@ then # Install bundler, a gems installer gem install bundler # Install without documentation - exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" ) # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then