From 5ce2a24649e12a087ce2a424d418262b1425ffb5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:10:38 +0100 Subject: ynh_ruby_3 --- scripts/ynh_install_ruby__2 | 342 +++++++++++++++++++++++++++----------------- 1 file changed, 208 insertions(+), 134 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 1d9bf8d..b8de713 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -1,11 +1,10 @@ #!/bin/bash -# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args - rbenv_version=1.1.2 -rbenv_rubybuild_version=20201225 +ruby_build_version=20201225 rbenv_aliases_version=1.1.0 rbenv_install_dir="/opt/rbenv" +ruby_version_path="$rbenv_install_dir/versions" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. export RBENV_ROOT="$rbenv_install_dir" @@ -14,37 +13,104 @@ export RBENV_ROOT="$rbenv_install_dir" # [internal] # # usage: ynh_install_rbenv +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_rbenv () { - ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${rbenv_rubybuild_version}" + ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${ruby_build_version}" - # Build an app.src for rbenv - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v${rbenv_version}.tar.gz + # Build an app.src for rbenv + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v${rbenv_version}.tar.gz SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "../conf/rbenv.src" - # Download and extract rbenv - ynh_setup_source --dest_dir="$rbenv_install_dir" --source_id=rbenv + # Download and extract rbenv + ynh_setup_source --dest_dir="$rbenv_install_dir" --source_id=rbenv - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${rbenv_rubybuild_version}.tar.gz + # Build an app.src for ruby-build + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${ruby_build_version}.tar.gz SOURCE_SUM=54cae123c2758e7714c66aca7ef8bc7f29cda8583891191ceb3053c6d098ecf1" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/ruby-build" --source_id=ruby-build + # Download and extract ruby-build + ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/ruby-build" --source_id=ruby-build - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz + # Build an app.src for rbenv-aliases + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > "../conf/rbenv-aliases.src" - # Download and extract ruby-build - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases + # Download and extract rbenv-aliases + ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases - (cd $rbenv_install_dir - ./src/configure && make -C src) + (cd $rbenv_install_dir + ./src/configure && make -C src) -# Create shims directory if needed -if [ ! -d $rbenv_install_dir/shims ] ; then - mkdir $rbenv_install_dir/shims -fi + # Create shims directory if needed + if [ ! -d $rbenv_install_dir/shims ] ; then + mkdir $rbenv_install_dir/shims + fi +} + +# Load the version of Ruby for an app, and set variables. +# +# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. +# This helper will provide alias and variables to use in your scripts. +# +# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby` +# Those alias will use the correct version installed for the app +# For example: use `ynh_gem install` instead of `gem install` +# +# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_ruby` +# And propagate $PATH to sudo with $ynh_ruby_load_path +# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install` +# +# $PATH contains the path of the requested version of Ruby. +# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH +# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version +# in $PATH for an usage into a separate script. +# Exemple: $ynh_ruby_load_path $final_path/script_that_use_gem.sh` +# +# +# Finally, to start a Ruby service with the correct version, 2 solutions +# Either the app is dependent of Ruby or gem, but does not called it directly. +# In such situation, you need to load PATH +# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"` +# `ExecStart=__FINALPATH__/my_app` +# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path +# +# Or Ruby start the app directly, then you don't need to load the PATH variable +# `ExecStart=__YNH_RUBY__ my_app run` +# You will replace __YNH_RUBY__ with $ynh_ruby +# +# +# one other variable is also available +# - $ruby_path: The absolute path to Ruby binaries for the chosen version. +# +# usage: ynh_use_ruby +# +# Requires YunoHost version 2.7.12 or higher. +ynh_use_ruby () { + # Get the absolute path of this version of Ruby + ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of Ruby and a variable as fallback + ynh_ruby="$ruby_path/ruby" + alias ynh_ruby="$ynh_ruby" + # And gem + ynh_gem="$ruby_path/gem" + alias ynh_gem="$ynh_gem" + + # Load the path of this version of Ruby in $PATH + if [[ :$PATH: != *":$ruby_path"* ]]; then + PATH="$ruby_path:$PATH" + fi + ruby_path="$PATH" + # Create an alias to easily load the PATH + ynh_ruby_load_path="PATH=$ruby_path" + + # Sets the local application-specific Ruby version + (cd $final_path + rbenv local $ruby_version) } # Install a specific version of Ruby @@ -64,132 +130,140 @@ fi # # usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. +# +# Requires YunoHost version 2.7.12 or higher. ynh_install_ruby () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [v]=ruby_version= ) - local ruby_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version - - # Create $rbenv_install_dir if doesn't exist already - mkdir -p "$rbenv_install_dir/plugins/ruby-build" - - # Create the file if doesn't exist already - touch "$rbenv_install_dir/ynh_app_version" - - # Load rbenv path in PATH - CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing Ruby binary, to avoid to block rbenv - test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv - - # If rbenv is not previously setup, install it - if ! type rbenv > /dev/null 2>&1 - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt ${rbenv_version} - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt ${rbenv_rubybuild_version} - then - ynh_install_rbenv - fi - - # Restore /usr/local/bin in PATH (if needed) - PATH=$CLEAR_PATH - - # And replace the old Ruby binary - test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby - - # Install the requested version of Ruby - ynh_print_info --message="Installation of Ruby-"$ruby_version - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version - - # Do not add twice the same line - if ! grep --quiet "$YNH_APP_INSTANCE_NAME:$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - - # Remove previous version - if grep --quiet "$YNH_APP_INSTANCE_NAME:" "$rbenv_install_dir/ynh_app_version" + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=ruby_version= ) + local ruby_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version + + # Create $rbenv_install_dir if doesn't exist already + mkdir -p "$rbenv_install_dir/plugins/ruby-build" + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing Ruby binary, to avoid to block rbenv + test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv + + # If rbenv is not previously setup, install it + if ! type rbenv > /dev/null 2>&1 then - if grep --quiet "$YNH_APP_INSTANCE_NAME" $(rbenv alias --list) - then - rbenv alias $YNH_APP_INSTANCE_NAME --remove - fi - sed --in-place "/$YNH_APP_INSTANCE_NAME:/d" "$rbenv_install_dir/ynh_app_version" + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt $rbenv_version + then + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt $ruby_build_version + then + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/plugins/rbenv-aliases/bin/rbenv-aliases --version | cut -d" " -f2)" lt $rbenv_aliases_version + then + ynh_install_rbenv fi - # Store the ID of this app and the version of Ruby requested for it - echo "$YNH_APP_INSTANCE_NAME:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version" - fi + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH - # Remove no more needed Ruby version - installed_ruby_version=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_version in $installed_ruby_version - do - if ! grep --quiet "$installed_version" "$rbenv_install_dir/ynh_app_version" + # And replace the old Ruby binary + test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby + + # Install the requested version of Ruby + ynh_print_info --message="Installation of Ruby-"$ruby_version + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + + # Remove app virtualenv + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1` then - ynh_print_info --message="Removing of ruby-"$installed_version - $rbenv_install_dir/bin/rbenv uninstall --force $installed_version + rbenv alias $YNH_APP_INSTANCE_NAME --remove fi - done - # Set environment for Ruby users - echo "#rbenv + # Create app virtualenv + rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby + + # Set environment for Ruby users + echo "#rbenv export RBENV_ROOT=$rbenv_install_dir export PATH=\"$rbenv_install_dir/bin:$PATH\" eval \"\$(rbenv init -)\" -#rbenv" > /etc/profile.d/rbenv.sh - - # Load the environment - eval "$(rbenv init -)" + #rbenv" > /etc/profile.d/rbenv.sh - (cd $final_path - rbenv local $ruby_version) - - rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + # Load the environment + eval "$(rbenv init -)" } # Remove the version of Ruby used by the app. # -# This helper will check if another app uses the same version of Ruby, -# if not, this version of Ruby will be removed. -# If no other app uses Ruby, rbenv will be also removed. +# This helper will also cleanup Ruby versions # # usage: ynh_remove_ruby ynh_remove_ruby () { - local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) - - # Load rbenv path in PATH - CLEAR_PATH="$rbenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Ruby prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - -rbenv alias $YNH_APP_INSTANCE_NAME --remove - - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$ruby_version/d" "$rbenv_install_dir/ynh_app_version" - - # If no other app uses this version of Ruby, remove it. - if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version" - then - ynh_print_info --message="Removing of Ruby-"$ruby_version - $rbenv_install_dir/bin/rbenv uninstall --force $ruby_version - fi - - # If no other app uses rbenv, remove rbenv and dedicated group - if [ ! -s "$rbenv_install_dir/ynh_app_version" ] - then - ynh_print_info --message="Removing of rbenv" - ynh_secure_remove --file="$rbenv_install_dir" - # Remove rbenv environment configuration - rm /etc/profile.d/rbenv.sh - fi + local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version) + + # Load rbenv path in PATH + local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Ruby prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + rbenv alias $YNH_APP_INSTANCE_NAME --remove + + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version + + # Cleanup Ruby versions + ynh_cleanup_ruby } + +# Remove no more needed versions of Ruby used by the app. +# +# This helper will check what Ruby version are no more required, +# and uninstall them +# If no app uses Ruby, rbenv will be also removed. +# +# usage: ynh_cleanup_ruby +ynh_cleanup_ruby () { + + # List required Ruby version + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_ruby_versions="" + for installed_app in $installed_apps + do + local installed_app_ruby_version=$(yunohost app setting $installed_app ruby_version) + if [[ $installed_app_ruby_version ]] + then + required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" + fi + done + + # Remove no more needed Ruby version + local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') + for installed_ruby_version in $installed_ruby_versions + do + if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Ruby-"$installed_ruby_version + $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + fi + done + + # If none Ruby version is required + if [[ ! $required_ruby_versions ]] + then + # Remove rbenv environment configuration + ynh_print_info --message="Removing of rbenv-"$rbenv_version + ynh_secure_remove --file="$rbenv_install_dir" + rm /etc/profile.d/rbenv.sh + fi +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 9d612530cae529c94281cc089f13e5cf8eb56719 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:37:12 +0100 Subject: Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b8de713..0488d3c 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -87,6 +87,7 @@ SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > " # # Requires YunoHost version 2.7.12 or higher. ynh_use_ruby () { + ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) # Get the absolute path of this version of Ruby ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" -- cgit v1.2.3-70-g09d2 From 05e04a31490bb0ce04b0ad2d0d9133c83614650d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Mar 2021 01:52:48 +0100 Subject: Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 0488d3c..78f65ad 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -105,9 +105,8 @@ ynh_use_ruby () { if [[ :$PATH: != *":$ruby_path"* ]]; then PATH="$ruby_path:$PATH" fi - ruby_path="$PATH" # Create an alias to easily load the PATH - ynh_ruby_load_path="PATH=$ruby_path" + ynh_ruby_load_path="PATH=$PATH" # Sets the local application-specific Ruby version (cd $final_path -- cgit v1.2.3-70-g09d2 From 0fbd6a19a1f413cfa05480cf44f33f4edff0f655 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 7 Mar 2021 18:44:44 +0100 Subject: Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 78f65ad..b517fd3 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -163,9 +163,6 @@ ynh_install_ruby () { then ynh_install_rbenv elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt $ruby_build_version - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/rbenv-aliases/bin/rbenv-aliases --version | cut -d" " -f2)" lt $rbenv_aliases_version then ynh_install_rbenv fi @@ -266,4 +263,4 @@ ynh_cleanup_ruby () { ynh_secure_remove --file="$rbenv_install_dir" rm /etc/profile.d/rbenv.sh fi -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2 From a8cc57fe43d0de1e021fd22504cd28e0bd91a462 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 8 Mar 2021 21:38:00 +0100 Subject: spacing --- scripts/ynh_install_ruby__2 | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b517fd3..1f965e3 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -88,6 +88,7 @@ SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > " # Requires YunoHost version 2.7.12 or higher. ynh_use_ruby () { ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) + # Get the absolute path of this version of Ruby ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" -- cgit v1.2.3-70-g09d2 From c4d58a6ba36fecffc7f5a0340ef969ffa3334adb Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 22:51:42 +0100 Subject: Switch to git --- scripts/ynh_install_ruby__2 | 167 +++++++++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 70 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 1f965e3..b3e3922 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -1,53 +1,18 @@ #!/bin/bash -rbenv_version=1.1.2 -ruby_build_version=20201225 -rbenv_aliases_version=1.1.0 +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." + } + fi +} + rbenv_install_dir="/opt/rbenv" ruby_version_path="$rbenv_install_dir/versions" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. export RBENV_ROOT="$rbenv_install_dir" -# Install Ruby Version Management -# -# [internal] -# -# usage: ynh_install_rbenv -# -# Requires YunoHost version 2.7.12 or higher. -ynh_install_rbenv () { - ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${ruby_build_version}" - - # Build an app.src for rbenv - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v${rbenv_version}.tar.gz -SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > "../conf/rbenv.src" - # Download and extract rbenv - ynh_setup_source --dest_dir="$rbenv_install_dir" --source_id=rbenv - - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${ruby_build_version}.tar.gz -SOURCE_SUM=54cae123c2758e7714c66aca7ef8bc7f29cda8583891191ceb3053c6d098ecf1" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/ruby-build" --source_id=ruby-build - - # Build an app.src for rbenv-aliases - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz -SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > "../conf/rbenv-aliases.src" - # Download and extract rbenv-aliases - ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases - - (cd $rbenv_install_dir - ./src/configure && make -C src) - - # Create shims directory if needed - if [ ! -d $rbenv_install_dir/shims ] ; then - mkdir $rbenv_install_dir/shims - fi -} - # Load the version of Ruby for an app, and set variables. # # ynh_use_ruby has to be used in any app scripts before using Ruby for the first time. @@ -110,8 +75,9 @@ ynh_use_ruby () { ynh_ruby_load_path="PATH=$PATH" # Sets the local application-specific Ruby version - (cd $final_path - rbenv local $ruby_version) + pushd $final_path + $rbenv_install_dir/bin/rbenv local $ruby_version + popd } # Install a specific version of Ruby @@ -141,12 +107,6 @@ ynh_install_ruby () { # Manage arguments with getopts ynh_handle_getopts_args "$@" - # Store ruby_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version - - # Create $rbenv_install_dir if doesn't exist already - mkdir -p "$rbenv_install_dir/plugins/ruby-build" - # Load rbenv path in PATH local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" @@ -156,18 +116,81 @@ 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 - # If rbenv is not previously setup, install it - if ! type rbenv > /dev/null 2>&1 - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt $rbenv_version - then - ynh_install_rbenv - elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt $ruby_build_version - then - ynh_install_rbenv + # Instal or update rbenv + rbenv="$(command -v rbenv $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..." + git pull -q --tags origin master + cd .. + ynh_ruby_try_bash_extension + fi + popd + else + ynh_print_info --message="Installing rbenv with git..." + mkdir -p $rbenv_install_dir + pushd $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 + popd + fi + + ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" + if [ -n "$ruby_build" ]; then + ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." + pushd "${ruby_build%/*/*}" + if git remote -v 2>/dev/null | grep -q ruby-build; then + ynh_print_info --message="Trying to update rbenv with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing ruby-build with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" + fi + + rb_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rb_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rb_alias'." + pushd "${rb_alias%/*/*}" + if git remote -v 2>/dev/null | grep -q rbenv-aliases; then + ynh_print_info --message="Trying to update rbenv-aliases with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing rbenv-aliases with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" fi + rb_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rb_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rb_latest'." + pushd "${rb_latest%/*/*}" + if git remote -v 2>/dev/null | grep -q xxenv-latest; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${rbenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" + fi + + # Enable caching + mkdir -p "${rbenv_install_dir}/cache" + + # Create shims directory if needed + mkdir -p "${rbenv_install_dir}/shims" + # Restore /usr/local/bin in PATH PATH=$CLEAR_PATH @@ -175,17 +198,21 @@ ynh_install_ruby () { test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby # Install the requested version of Ruby - ynh_print_info --message="Installation of Ruby-"$ruby_version - CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + local final_ruby_version=$(rbenv latest --print $ruby_version) + ynh_print_info --message="Installing Ruby-$final_ruby_version" + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 + + # Store ruby_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version # Remove app virtualenv - if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME" 1>/dev/null 2>&1` + if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` then rbenv alias $YNH_APP_INSTANCE_NAME --remove fi # Create app virtualenv - rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version + rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version # Cleanup Ruby versions ynh_cleanup_ruby @@ -233,7 +260,7 @@ ynh_remove_ruby () { # usage: ynh_cleanup_ruby ynh_cleanup_ruby () { - # List required Ruby version + # List required Ruby versions local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local required_ruby_versions="" for installed_app in $installed_apps @@ -245,13 +272,13 @@ ynh_cleanup_ruby () { fi done - # Remove no more needed Ruby version + # Remove no more needed Ruby versions local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') for installed_ruby_version in $installed_ruby_versions do if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1` then - ynh_print_info --message="Removing of Ruby-"$installed_ruby_version + ynh_print_info --message="Removing of Ruby-$installed_ruby_version" $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version fi done @@ -260,8 +287,8 @@ ynh_cleanup_ruby () { if [[ ! $required_ruby_versions ]] then # Remove rbenv environment configuration - ynh_print_info --message="Removing of rbenv-"$rbenv_version + ynh_print_info --message="Removing of rbenv-$rbenv_version" ynh_secure_remove --file="$rbenv_install_dir" - rm /etc/profile.d/rbenv.sh + ynh_secure_remove --file="/etc/profile.d/rbenv.sh" fi } -- cgit v1.2.3-70-g09d2 From 05b6dc21ffacec0e7b97270bf80cc6a8a1753f65 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 12 Mar 2021 23:41:08 +0100 Subject: Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index b3e3922..89fbd05 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -155,10 +155,10 @@ ynh_install_ruby () { git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" fi - rb_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" - if [ -n "$rb_alias" ]; then - ynh_print_info --message="\`rbenv alias' command already available in \`$rb_alias'." - pushd "${rb_alias%/*/*}" + rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + if [ -n "$rbenv_alias" ]; then + ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." + pushd "${rbenv_alias%/*/*}" if git remote -v 2>/dev/null | grep -q rbenv-aliases; then ynh_print_info --message="Trying to update rbenv-aliases with git..." git pull -q origin master @@ -170,10 +170,10 @@ ynh_install_ruby () { git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" fi - rb_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" - if [ -n "$rb_latest" ]; then - ynh_print_info --message="\`rbenv latest' command already available in \`$rb_latest'." - pushd "${rb_latest%/*/*}" + rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + if [ -n "$rbenv_latest" ]; then + ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." + pushd "${rbenv_latest%/*/*}" if git remote -v 2>/dev/null | grep -q xxenv-latest; then ynh_print_info --message="Trying to update xxenv-latest with git..." git pull -q origin master @@ -222,7 +222,7 @@ ynh_install_ruby () { export RBENV_ROOT=$rbenv_install_dir export PATH=\"$rbenv_install_dir/bin:$PATH\" eval \"\$(rbenv init -)\" - #rbenv" > /etc/profile.d/rbenv.sh +#rbenv" > /etc/profile.d/rbenv.sh # Load the environment eval "$(rbenv init -)" -- cgit v1.2.3-70-g09d2 From 3fa6a835b570b181a2b5a95ac98c3b38f5738c3d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 13:00:18 +0100 Subject: Manage previous rbenv installation --- scripts/ynh_install_ruby__2 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 89fbd05..7afe7b5 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -3,7 +3,7 @@ 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 } @@ -84,9 +84,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) # @@ -116,16 +113,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 + 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 -- cgit v1.2.3-70-g09d2 From 9588b8da9393f874f8678b2aa56cdfea8da794a7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 13 Mar 2021 15:05:48 +0100 Subject: Fix new rbenv install --list-all --- scripts/ynh_install_ruby__2 | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 7afe7b5..f9cc22a 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -206,6 +206,9 @@ ynh_install_ruby () { # Install the requested version of Ruby local final_ruby_version=$(rbenv latest --print $ruby_version) + if ! [ -n "$final_ruby_version" ]; then + final_ruby_version=$ruby_version + fi ynh_print_info --message="Installing Ruby-$final_ruby_version" CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1 -- cgit v1.2.3-70-g09d2 From 5ce2de89b9f32a0bd18efbc498c94af3f9d64d84 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 00:48:54 +0100 Subject: Do not use 'yunohost app setting' --- scripts/ynh_install_ruby__2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index f9cc22a..9a63c67 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -275,7 +275,7 @@ ynh_cleanup_ruby () { local required_ruby_versions="" for installed_app in $installed_apps do - local installed_app_ruby_version=$(yunohost app setting $installed_app ruby_version) + local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") if [[ $installed_app_ruby_version ]] then required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" -- cgit v1.2.3-70-g09d2 From 2c6c2c02a131700dd1a243e6c94af7d78274174a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 14 Mar 2021 06:00:31 +0100 Subject: Fix repository detection --- scripts/ynh_install_ruby__2 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index 9a63c67..a946903 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -118,7 +118,7 @@ ynh_install_ruby () { 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 "origin https://github.com/rbenv/rbenv.git"; then + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then ynh_print_info --message="Trying to update with git..." git pull -q --tags origin master ynh_ruby_try_bash_extension @@ -151,7 +151,7 @@ ynh_install_ruby () { if [ -n "$ruby_build" ]; then ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'." pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep -q ruby-build; then + if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then ynh_print_info --message="Trying to update rbenv with git..." git pull -q origin master fi @@ -166,7 +166,7 @@ ynh_install_ruby () { if [ -n "$rbenv_alias" ]; then ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'." pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep -q rbenv-aliases; then + if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then ynh_print_info --message="Trying to update rbenv-aliases with git..." git pull -q origin master fi @@ -181,7 +181,7 @@ ynh_install_ruby () { if [ -n "$rbenv_latest" ]; then ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'." pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep -q xxenv-latest; then + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then ynh_print_info --message="Trying to update xxenv-latest with git..." git pull -q origin master fi -- cgit v1.2.3-70-g09d2 From b01227d32602fe2239f1c74fa8ac06940230c52e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 22 Mar 2021 20:54:09 +0100 Subject: Update ynh_install_ruby__2 --- scripts/ynh_install_ruby__2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/ynh_install_ruby__2') diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index a946903..fae1755 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -50,7 +50,7 @@ export RBENV_ROOT="$rbenv_install_dir" # # usage: ynh_use_ruby # -# Requires YunoHost version 2.7.12 or higher. +# Requires YunoHost version 3.2.2 or higher. ynh_use_ruby () { ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) @@ -95,7 +95,7 @@ ynh_use_ruby () { # usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. # -# Requires YunoHost version 2.7.12 or higher. +# Requires YunoHost version 3.2.2 or higher. ynh_install_ruby () { # Declare an array to define the options of this helper. local legacy_args=v -- cgit v1.2.3-70-g09d2