From 29be65c72e86d79b690d908c4e32483e62e06084 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 13:01:36 +0100 Subject: [PATCH] manage previous rbenv instllations --- scripts/_common.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5e9924a..ea8208e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -166,7 +166,7 @@ ynh_maintenance_mode_OFF () { ynh_ruby_try_bash_extension() { if [ -x src/configure ]; then src/configure && make -C src || { - echo "Optional bash extension failed to build, but things will still work normally." + ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." } fi } @@ -247,9 +247,6 @@ ynh_use_ruby () { # # ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. # -# rbenv (Ruby Version Management) stores the target Ruby version in a .ruby_version file created in the target folder (using rbenv local ) -# It then uses that information for every Ruby user that uses rbenv provided Ruby command -# # This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv # for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) # @@ -279,16 +276,26 @@ ynh_install_ruby () { # Move an existing Ruby binary, to avoid to block rbenv test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - # Instal or update rbenv - rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | head -1)" + # Install or update rbenv + rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" if [ -n "$rbenv" ]; then ynh_print_info --message="rbenv already seems installed in \`$rbenv'." pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep -q rbenv; then - echo "Trying to update with git..." + if git remote -v 2>/dev/null | grep -q "origin https://github.com/rbenv/rbenv.git"; then + ynh_print_info --message="Trying to update with git..." git pull -q --tags origin master - cd .. ynh_ruby_try_bash_extension + else + ynh_print_info --message="Reinstalling rbenv with git..." + cd .. + ynh_secure_remove --file=$rbenv_install_dir + mkdir -p $rbenv_install_dir + cd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv fi popd else