From 51d1011c476a3d5d452b915e52fb1f053f103bbd Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 10 Jun 2024 18:00:20 +0200 Subject: [PATCH] helpers2.1: Remove the --foo_version arg for go, mongodb, nodejs, php, ruby helpers. Just use the global $foo_version which should be defined as global --- helpers/helpers.v2.1.d/go | 18 ++++++++---------- helpers/helpers.v2.1.d/mongodb | 26 +++++++++++--------------- helpers/helpers.v2.1.d/nodejs | 20 ++++++++------------ helpers/helpers.v2.1.d/php | 2 ++ helpers/helpers.v2.1.d/ruby | 20 +++++++++----------- 5 files changed, 38 insertions(+), 48 deletions(-) diff --git a/helpers/helpers.v2.1.d/go b/helpers/helpers.v2.1.d/go index d6b74aaf9..98def7f3f 100644 --- a/helpers/helpers.v2.1.d/go +++ b/helpers/helpers.v2.1.d/go @@ -52,7 +52,8 @@ export GOENV_ROOT="$goenv_install_dir" # # Requires YunoHost version 3.2.2 or higher. ynh_use_go () { - go_version=$(ynh_app_setting_get --key=go_version) + + [[ -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 go_path="$go_version_path/$go_version/bin" @@ -77,9 +78,9 @@ ynh_use_go () { popd } -# Install a specific version of Go +# Install a specific version of Go using goenv # -# ynh_install_go will install the version of Go provided as argument by using goenv. +# The installed version is defined by $nodejs_version which should be defined as global prior to calling this helper # # This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv # for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) @@ -89,16 +90,12 @@ ynh_use_go () { # When not possible (e.g. in systemd service definition), please use direct path # to goenv shims (e.g. $goenv_ROOT/shims/bundle) # -# usage: ynh_install_go --go_version=go_version -# | arg: -v, --go_version= - Version of go to install. +# usage: ynh_install_go # # Requires YunoHost version 3.2.2 or higher. ynh_install_go () { - # ============ Argument parsing ============= - local -A args_array=( [v]=go_version= ) - local go_version - ynh_handle_getopts_args "$@" - # =========================================== + + [[ -n "${go_version:-}" ]] || ynh_die --message="\$go_version should be defined prior to calling ynh_install_go" # Load goenv path in PATH local CLEAR_PATH="$goenv_install_dir/bin:$PATH" @@ -160,6 +157,7 @@ ynh_install_go () { # Store go_version into the config of this app ynh_app_setting_set --app="$app" --key="go_version" --value="$final_go_version" + go_version=$final_go_version # Cleanup Go versions ynh_cleanup_go diff --git a/helpers/helpers.v2.1.d/mongodb b/helpers/helpers.v2.1.d/mongodb index 1626c27d2..226c21084 100644 --- a/helpers/helpers.v2.1.d/mongodb +++ b/helpers/helpers.v2.1.d/mongodb @@ -215,29 +215,25 @@ ynh_mongo_remove_db() { # Install MongoDB and integrate MongoDB service in YunoHost # -# usage: ynh_install_mongo [--mongo_version=mongo_version] -# | arg: -m, --mongo_version= - Version of MongoDB to install +# The installed version is defined by $mongo_version which should be defined as global prior to calling this helper # +# usage: ynh_install_mongo # ynh_install_mongo() { - # ============ Argument parsing ============= - local -A args_array=([m]=mongo_version=) - local mongo_version - ynh_handle_getopts_args "$@" - mongo_version="${mongo_version:-$YNH_MONGO_VERSION}" - # =========================================== + + [[ -n "${mongo_version:-}" ]] || ynh_die --message="\$mongo_version should be defined prior to calling ynh_install_mongo" ynh_print_info --message="Installing MongoDB Community Edition ..." local mongo_debian_release=$(ynh_get_debian_release) if [[ $(cat /proc/cpuinfo) != *"avx"* && "$mongo_version" != "4.4" ]]; then - ynh_print_warn --message="Installing Mongo 4.4 as $mongo_version is not compatible with your cpu (see https://docs.mongodb.com/manual/administration/production-notes/#x86_64)." - mongo_version="4.4" - fi - if [[ "$mongo_version" == "4.4" ]]; then - ynh_print_warn --message="Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release." - mongo_debian_release=buster - fi + ynh_print_warn --message="Installing Mongo 4.4 as $mongo_version is not compatible with your cpu (see https://docs.mongodb.com/manual/administration/production-notes/#x86_64)." + mongo_version="4.4" + fi + if [[ "$mongo_version" == "4.4" ]]; then + ynh_print_warn --message="Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release." + mongo_debian_release=buster + fi ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" --package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" --key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc" mongodb_servicename=mongod diff --git a/helpers/helpers.v2.1.d/nodejs b/helpers/helpers.v2.1.d/nodejs index d2ae2c1cc..a151a54d8 100644 --- a/helpers/helpers.v2.1.d/nodejs +++ b/helpers/helpers.v2.1.d/nodejs @@ -46,11 +46,11 @@ export N_PREFIX="$n_install_dir" # # 2 other variables are also available # - $nodejs_path: The absolute path to node binaries for the chosen version. -# - $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml. # # Requires YunoHost version 2.7.12 or higher. ynh_use_nodejs() { - nodejs_version=$(ynh_app_setting_get --key=nodejs_version) + + [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" # Get the absolute path of this version of node nodejs_path="$node_version_path/$nodejs_version/bin" @@ -78,12 +78,11 @@ ynh_use_nodejs() { export COREPACK_ENABLE_DOWNLOAD_PROMPT=0 } -# Install a specific version of nodejs +# Install a specific version of nodejs, using 'n' # -# ynh_install_nodejs will install the version of node provided as argument by using n. +# The installed version is defined by $nodejs_version which should be defined as global prior to calling this helper # -# usage: ynh_install_nodejs --nodejs_version=nodejs_version -# | arg: -n, --nodejs_version= - Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed. +# usage: ynh_install_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 @@ -94,11 +93,7 @@ ynh_use_nodejs() { ynh_install_nodejs() { # Use n, https://github.com/tj/n to manage the nodejs versions - # ============ Argument parsing ============= - local -A args_array=([n]=nodejs_version=) - local nodejs_version - ynh_handle_getopts_args "$@" - # =========================================== + [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" # Create $n_install_dir mkdir --parents "$n_install_dir" @@ -164,7 +159,8 @@ ynh_install_nodejs() { # # Requires YunoHost version 2.7.12 or higher. ynh_remove_nodejs() { - nodejs_version=$(ynh_app_setting_get --key=nodejs_version) + + [[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_install_nodejs" # Remove the line for this app sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version" diff --git a/helpers/helpers.v2.1.d/php b/helpers/helpers.v2.1.d/php index 08850b2cc..e09a2dc4f 100644 --- a/helpers/helpers.v2.1.d/php +++ b/helpers/helpers.v2.1.d/php @@ -304,6 +304,8 @@ ynh_composer_exec() { # Install and initialize Composer in the given directory # +# The installed version is defined by $composer_version which should be defined as global prior to calling this helper +# # usage: ynh_install_composer [--workdir=$install_dir] [--install_args="--optimize-autoloader"] # | arg: -w, --workdir - The directory from where the command will be executed. Default $install_dir. # | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include diff --git a/helpers/helpers.v2.1.d/ruby b/helpers/helpers.v2.1.d/ruby index 1a03d1d2e..f2092f070 100644 --- a/helpers/helpers.v2.1.d/ruby +++ b/helpers/helpers.v2.1.d/ruby @@ -51,7 +51,8 @@ fi # # Requires YunoHost version 3.2.2 or higher. ynh_use_ruby () { - ruby_version=$(ynh_app_setting_get --key=ruby_version) + + [[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_use_ruby" # Get the absolute path of this version of Ruby ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin" @@ -79,9 +80,9 @@ ynh_use_ruby () { popd } -# Install a specific version of Ruby +# Install a specific version of Ruby using rbenv # -# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv. +# The installed version is defined by $ruby_version which should be defined as global prior to calling this helper # # 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) @@ -91,16 +92,12 @@ ynh_use_ruby () { # When not possible (e.g. in systemd service definition), please use direct path # to rbenv shims (e.g. $RBENV_ROOT/shims/bundle) # -# usage: ynh_install_ruby --ruby_version=ruby_version -# | arg: -v, --ruby_version= - Version of ruby to install. +# usage: ynh_install_ruby # # Requires YunoHost version 3.2.2 or higher. ynh_install_ruby () { - # ============ Argument parsing ============= - local -A args_array=( [v]=ruby_version= ) - local ruby_version - ynh_handle_getopts_args "$@" - # =========================================== + + [[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_install_ruby" # Load rbenv path in PATH local CLEAR_PATH="$rbenv_install_dir/bin:$PATH" @@ -207,6 +204,7 @@ ynh_install_ruby () { # Store ruby_version into the config of this app ynh_app_setting_set --key=ruby_version --value=$final_ruby_version + ruby_version=$final_ruby_version # Remove app virtualenv if rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " @@ -274,7 +272,7 @@ ynh_cleanup_ruby () { required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" fi done - + # 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