From fa3621426efb5a6eea4b26177ecd2988172a2e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 20 May 2024 23:55:21 +0200 Subject: [PATCH] Use standard ynh_exec_as helper for login shell too --- scripts/_common.sh | 9 --------- scripts/change_url | 6 +++--- scripts/install | 14 +++++++------- scripts/upgrade | 14 +++++++------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 2df3209..b9a1bbc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,15 +17,6 @@ nodejs_version="16" # PERSONAL HELPERS #================================================= -# Execute a command as another user with login -# (hence in user home dir, with prior loading of .profile, etc.) -# usage: exec_login_as USER COMMAND [ARG ...] -exec_login_as() { - local user=$1 - shift 1 - ynh_exec_as $user --login "$@" -} - # Returns true if a swap partition is enabled, false otherwise # usage: is_swap_present is_swap_present() { diff --git a/scripts/change_url b/scripts/change_url index a04cb6f..0da2928 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -134,14 +134,14 @@ UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url ynh_use_ruby # Remap URLs in forum posts -exec_login_as $app RAILS_ENV=production bin/bundle exec script/discourse remap ${old_path%/}/uploads ${new_path%/}/uploads <<< "YES +ynh_exec_as $app --login RAILS_ENV=production bin/bundle exec script/discourse remap ${old_path%/}/uploads ${new_path%/}/uploads <<< "YES # " # Regenerate assets -ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake assets:precompile +ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/rake assets:precompile # Regenerate all forum posts -ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake posts:rebake +ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/rake posts:rebake #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 9509e6c..d2a5c84 100644 --- a/scripts/install +++ b/scripts/install @@ -172,13 +172,13 @@ popd if [ -n "$(uname -m | grep arm)" ] ; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bin/bundle config specific_platform arm-linux + ynh_exec_as $app --login bin/bundle config specific_platform arm-linux fi # Install dependencies -exec_login_as $app bin/bundle config set path 'vendor/bundle' -exec_login_as $app bin/bundle config set with 'development' -exec_login_as $app MAKEFLAGS=-j2 bin/bundle install --jobs 2 +ynh_exec_as $app --login bin/bundle config set path 'vendor/bundle' +ynh_exec_as $app --login bin/bundle config set with 'development' +ynh_exec_as $app --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible @@ -201,8 +201,8 @@ popd #================================================= ynh_script_progression --message="Preparing the database..." -ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/bundle exec rake db:migrate -ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile +ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/bundle exec rake db:migrate +ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_package_autoremove @@ -234,7 +234,7 @@ ynh_script_progression --message="Creating Discourse admin user..." # Create a random password admin_pwd=$(ynh_string_random) -exec_login_as $app RAILS_ENV=production bin/rake admin:create <<< "$admin_mail +ynh_exec_as $app --login RAILS_ENV=production bin/rake admin:create <<< "$admin_mail $admin_pwd $admin_pwd y diff --git a/scripts/upgrade b/scripts/upgrade index a0853c8..bab4c14 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -251,17 +251,17 @@ then # Install without documentation ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" popd - + # Specific actions on ARM architecture if [ -n "$(uname -m | grep arm)" ] ; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - exec_login_as $app bin/bundle config specific_platform arm-linux + ynh_exec_as $app --login bin/bundle config specific_platform arm-linux fi # Install dependencies - exec_login_as $app bin/bundle config set path 'vendor/bundle' - exec_login_as $app bin/bundle config set with 'development' - exec_login_as $app MAKEFLAGS=-j2 bin/bundle install --jobs 2 + ynh_exec_as $app --login bin/bundle config set path 'vendor/bundle' + ynh_exec_as $app --login bin/bundle config set with 'development' + ynh_exec_as $app --login MAKEFLAGS=-j2 bin/bundle install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible @@ -290,8 +290,8 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Preparing the database..." - ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/bundle exec rake db:migrate - ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile + ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/bundle exec rake db:migrate + ynh_exec_warn_less ynh_exec_as $app --login RAILS_ENV=production bin/bundle exec rake themes:update assets:precompile fi ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies