diff --git a/helpers/helpers.v2.1.d/go b/helpers/helpers.v2.1.d/go index ba729314f..12c089744 100644 --- a/helpers/helpers.v2.1.d/go +++ b/helpers/helpers.v2.1.d/go @@ -13,67 +13,25 @@ go_version_path="$goenv_install_dir/versions" # goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable. export GOENV_ROOT="$goenv_install_dir" -# Load the version of Go for an app, and set variables. -# -# ynh_use_go has to be used in any app scripts before using Go for the first time. -# This helper will provide alias and variables to use in your scripts. -# -# To use gem or Go, use the alias `ynh_gem` and `ynh_go` -# 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_go` -# And propagate $PATH to sudo with $ynh_go_load_path -# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install` -# -# $PATH contains the path of the requested version of Go. -# However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH -# You can use the variable `$ynh_go_load_path` to quickly load your Go version -# in $PATH for an usage into a separate script. -# Exemple: `$ynh_go_load_path $install_dir/script_that_use_gem.sh` -# -# -# Finally, to start a Go service with the correct version, 2 solutions -# Either the app is dependent of Go or gem, but does not called it directly. -# In such situation, you need to load PATH -# `Environment="__YNH_GO_LOAD_PATH__"` -# `ExecStart=__INSTALL_DIR__/my_app` -# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path -# -# Or Go start the app directly, then you don't need to load the PATH variable -# `ExecStart=__YNH_GO__ my_app run` -# You will replace __YNH_GO__ with $ynh_go -# -# -# one other variable is also available -# - $go_path: The absolute path to Go binaries for the chosen version. -# -# usage: ynh_use_go -# -# Requires YunoHost version 3.2.2 or higher. -ynh_use_go () { +_ynh_load_go_in_path_and_other_tweaks() { - [[ -n "${go_version:-}" ]] || ynh_die --message="\$go_version should be defined prior to calling ynh_use_go" + # Get the absolute path of this version of go + local go_path="$go_version_path/$app/bin" - # Get the absolute path of this version of Go - go_path="$go_version_path/$go_version/bin" - - # Allow alias to be used into bash script - shopt -s expand_aliases - - # Create an alias for the specific version of Go and a variable as fallback - ynh_go="$go_path/go" - alias ynh_go="$ynh_go" - - # Load the path of this version of Go in $PATH + # Load the path of this version of go in $PATH if [[ :$PATH: != *":$go_path"* ]]; then PATH="$go_path:$PATH" fi - # Create an alias to easily load the PATH - ynh_go_load_path="PATH=$PATH" - # Sets the local application-specific Go version - pushd $install_dir + # Export PATH such that it's available through sudo -E / ynh_exec_as $app + export PATH + + # This is in full lowercase such that it gets replaced in templates + path_with_go="$PATH" + PATH_with_go="$PATH" + + # Sets the local application-specific go version + pushd ${install_dir} $goenv_install_dir/bin/goenv local $go_version popd } @@ -171,6 +129,8 @@ eval \"\$(goenv init -)\" # Load the environment eval "$(goenv init -)" + + _ynh_load_go_in_path_and_other_tweaks } # Remove the version of Go used by the app. diff --git a/helpers/helpers.v2.1.d/nodejs b/helpers/helpers.v2.1.d/nodejs index a475b3cd2..0b8788409 100644 --- a/helpers/helpers.v2.1.d/nodejs +++ b/helpers/helpers.v2.1.d/nodejs @@ -5,75 +5,23 @@ node_version_path="$n_install_dir/n/versions/node" # N_PREFIX is the directory of n, it needs to be loaded as a environment variable. export N_PREFIX="$n_install_dir" -# Load the version of node for an app, and set variables. -# -# usage: ynh_use_nodejs -# -# `ynh_use_nodejs` has to be used in any app scripts before using node for the first time. -# This helper will provide alias and variables to use in your scripts. -# -# To use npm or node, use the alias `ynh_npm` and `ynh_node`. -# -# Those alias will use the correct version installed for the app. -# For example: use `ynh_npm install` instead of `npm install` -# -# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_npm` and `$ynh_node` -# And propagate $PATH to sudo with $ynh_node_load_PATH -# Exemple: `ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install` -# -# $PATH contains the path of the requested version of node. -# However, $PATH is duplicated into $node_PATH to outlast any manipulation of `$PATH` -# You can use the variable `$ynh_node_load_PATH` to quickly load your node version -# in $PATH for an usage into a separate script. -# Exemple: $ynh_node_load_PATH $install_dir/script_that_use_npm.sh` -# -# -# Finally, to start a nodejs service with the correct version, 2 solutions -# Either the app is dependent of node or npm, but does not called it directly. -# In such situation, you need to load PATH : -# ``` -# Environment="__NODE_ENV_PATH__" -# ExecStart=__FINALPATH__/my_app -# ``` -# You will replace __NODE_ENV_PATH__ with $ynh_node_load_PATH. -# -# Or node start the app directly, then you don't need to load the PATH variable -# ``` -# ExecStart=__YNH_NODE__ my_app run -# ``` -# You will replace __YNH_NODE__ with $ynh_node -# -# -# 2 other variables are also available -# - $nodejs_path: The absolute path to node binaries for the chosen version. -# -# Requires YunoHost version 2.7.12 or higher. -ynh_use_nodejs() { - - [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" +_ynh_load_nodejs_in_path_and_other_tweaks() { # Get the absolute path of this version of node - nodejs_path="$node_version_path/$nodejs_version/bin" - - # Allow alias to be used into bash script - shopt -s expand_aliases - - # Create an alias for the specific version of node and a variable as fallback - ynh_node="$nodejs_path/node" - alias ynh_node="$ynh_node" - # And npm - ynh_npm="$nodejs_path/npm" - alias ynh_npm="$ynh_npm" + local nodejs_path="$node_version_path/$nodejs_version/bin" # Load the path of this version of node in $PATH if [[ :$PATH: != *":$nodejs_path"* ]]; then PATH="$nodejs_path:$PATH" fi - node_PATH="$PATH" - # Create an alias to easily load the PATH - ynh_node_load_PATH="PATH=$node_PATH" - # Same var but in lower case to be compatible with ynh_replace_vars... - ynh_node_load_path="PATH=$node_PATH" + + # Export PATH such that it's available through sudo -E / ynh_exec_as $app + export PATH + + # This is in full lowercase such that it gets replaced in templates + path_with_nodejs="$PATH" + PATH_with_nodejs="$PATH" + # Prevent yet another Node and Corepack madness, with Corepack wanting the user to confirm download of Yarn export COREPACK_ENABLE_DOWNLOAD_PROMPT=0 } @@ -87,7 +35,10 @@ ynh_use_nodejs() { # `n` (Node version management) uses the `PATH` variable to store the path of the version of node it is going to use. # That's how it changes the version # -# Refer to `ynh_use_nodejs` for more information about available commands and variables +# Adds the appropriate, specific version of nodejs to the PATH variable (which +# is also exported, to ease the use of ynh_exec_as_app). Also define variable +# PATH_with_nodejs to be used in the systemd config +# (Environment="PATH=__PATH_WITH_NODEJS__") # # Requires YunoHost version 2.7.12 or higher. ynh_install_nodejs() { @@ -146,7 +97,7 @@ ynh_install_nodejs() { # Build the update script and set the cronjob ynh_cron_upgrade_node - ynh_use_nodejs + _ynh_load_nodejs_in_path_and_other_tweaks } # Remove the version of node used by the app. diff --git a/helpers/helpers.v2.1.d/ruby b/helpers/helpers.v2.1.d/ruby index 25f203a94..acc36ac66 100644 --- a/helpers/helpers.v2.1.d/ruby +++ b/helpers/helpers.v2.1.d/ruby @@ -7,67 +7,22 @@ ruby_version_path="$rbenv_install_dir/versions" export RBENV_ROOT="$rbenv_install_dir" export rbenv_root="$rbenv_install_dir" -# 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 $install_dir/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_PATH__"` -# `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_RUBY_LOAD_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 3.2.2 or higher. -ynh_use_ruby () { - - [[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_use_ruby" +_ynh_load_ruby_in_path_and_other_tweaks() { # Get the absolute path of this version of Ruby - ruby_path="$ruby_version_path/$app/bin" + local ruby_path="$ruby_version_path/$app/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 + # Load the path of this version of ruby in $PATH if [[ :$PATH: != *":$ruby_path"* ]]; then PATH="$ruby_path:$PATH" fi - # Create an alias to easily load the PATH - ynh_ruby_load_path="PATH=$PATH" + + # Export PATH such that it's available through sudo -E / ynh_exec_as $app + export PATH + + # This is in full lowercase such that it gets replaced in templates + path_with_ruby="$PATH" + PATH_with_ruby="$PATH" # Sets the local application-specific Ruby version pushd ${install_dir} @@ -89,6 +44,11 @@ ynh_use_ruby () { # # usage: ynh_install_ruby # +# Adds the appropriate, specific version of ruby to the PATH variable (which +# is also exported, to ease the use of ynh_exec_as_app). Also define variable +# PATH_with_ruby to be used in the systemd config +# (Environment="PATH=__PATH_WITH_RUBY__") +# # Requires YunoHost version 3.2.2 or higher. ynh_install_ruby () { @@ -222,6 +182,8 @@ eval \"\$(rbenv init -)\" # Load the environment eval "$(rbenv init -)" + + _ynh_load_ruby_in_path_and_other_variable_tweaks } # Remove the version of Ruby used by the app.