diff --git a/helpers/helpers.v2.1.d/go b/helpers/helpers.v2.1.d/go index 22797397e..68f5ceaad 100644 --- a/helpers/helpers.v2.1.d/go +++ b/helpers/helpers.v2.1.d/go @@ -8,19 +8,18 @@ ynh_go_try_bash_extension() { fi } -goenv_install_dir="/opt/goenv" -go_version_path="$goenv_install_dir/versions" +readonly GOENV_INSTALL_DIR="/opt/goenv" # goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable. -export GOENV_ROOT="$goenv_install_dir" +export GOENV_ROOT="$GOENV_INSTALL_DIR" _ynh_load_go_in_path_and_other_tweaks() { # Get the absolute path of this version of go - local go_path="$go_version_path/$app/bin" + go_dir="$GOENV_INSTALL_DIR/versions/$app/bin" # Load the path of this version of go in $PATH - if [[ :$PATH: != *":$go_path"* ]]; then - PATH="$go_path:$PATH" + if [[ :$PATH: != *":$go_dir"* ]]; then + PATH="$go_dir:$PATH" fi # Export PATH such that it's available through sudo -E / ynh_exec_as $app @@ -32,7 +31,7 @@ _ynh_load_go_in_path_and_other_tweaks() { # Sets the local application-specific go version pushd ${install_dir} - $goenv_install_dir/bin/goenv local $go_version + $GOENV_INSTALL_DIR/bin/goenv local $go_version popd } @@ -56,7 +55,7 @@ ynh_go_install () { [[ -n "${go_version:-}" ]] || ynh_die "\$go_version should be defined prior to calling ynh_go_install" # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + local CLEAR_PATH="$GOENV_INSTALL_DIR/bin:$PATH" # Remove /usr/local/bin in PATH in case of Go prior installation PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') @@ -65,9 +64,9 @@ ynh_go_install () { test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv # Install or update goenv - mkdir -p $goenv_install_dir - pushd "$goenv_install_dir" - if ! [ -x "$goenv_install_dir/bin/goenv" ]; then + mkdir -p $GOENV_INSTALL_DIR + pushd "$GOENV_INSTALL_DIR" + if ! [ -x "$GOENV_INSTALL_DIR/bin/goenv" ]; then ynh_print_info "Downloading goenv..." git init -q git remote add origin https://github.com/syndbg/goenv.git @@ -78,13 +77,13 @@ ynh_go_install () { local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") git checkout -q "$git_latest_tag" ynh_go_try_bash_extension - goenv=$goenv_install_dir/bin/goenv + goenv=$GOENV_INSTALL_DIR/bin/goenv popd # Install or update xxenv-latest - mkdir -p "$goenv_install_dir/plugins/xxenv-latest" - pushd "$goenv_install_dir/plugins/xxenv-latest" - if ! [ -x "$goenv_install_dir/plugins/xxenv-latest/bin/goenv-latest" ]; then + mkdir -p "$GOENV_INSTALL_DIR/plugins/xxenv-latest" + pushd "$GOENV_INSTALL_DIR/plugins/xxenv-latest" + if ! [ -x "$GOENV_INSTALL_DIR/plugins/xxenv-latest/bin/goenv-latest" ]; then ynh_print_info "Downloading xxenv-latest..." git init -q git remote add origin https://github.com/momo-lab/xxenv-latest.git @@ -97,10 +96,10 @@ ynh_go_install () { popd # Enable caching - mkdir -p "${goenv_install_dir}/cache" + mkdir -p "${GOENV_INSTALL_DIR}/cache" # Create shims directory if needed - mkdir -p "${goenv_install_dir}/shims" + mkdir -p "${GOENV_INSTALL_DIR}/shims" # Restore /usr/local/bin in PATH PATH=$CLEAR_PATH @@ -122,8 +121,8 @@ ynh_go_install () { # Set environment for Go users echo "#goenv -export GOENV_ROOT=$goenv_install_dir -export PATH=\"$goenv_install_dir/bin:$PATH\" +export GOENV_ROOT=$GOENV_INSTALL_DIR +export PATH=\"$GOENV_INSTALL_DIR/bin:$PATH\" eval \"\$(goenv init -)\" #goenv" > /etc/profile.d/goenv.sh @@ -142,7 +141,7 @@ ynh_go_remove () { local go_version=$(ynh_app_setting_get --key="go_version") # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + local CLEAR_PATH="$GOENV_INSTALL_DIR/bin:$PATH" # Remove /usr/local/bin in PATH in case of Go prior installation PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') @@ -182,7 +181,7 @@ _ynh_go_cleanup () { if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1` then ynh_print_info "Removing of Go-$installed_go_version" - $goenv_install_dir/bin/goenv uninstall --force "$installed_go_version" + $GOENV_INSTALL_DIR/bin/goenv uninstall --force "$installed_go_version" fi done @@ -191,7 +190,7 @@ _ynh_go_cleanup () { then # Remove goenv environment configuration ynh_print_info "Removing of goenv" - ynh_safe_rm "$goenv_install_dir" + ynh_safe_rm "$GOENV_INSTALL_DIR" ynh_safe_rm "/etc/profile.d/goenv.sh" fi } diff --git a/helpers/helpers.v2.1.d/nodejs b/helpers/helpers.v2.1.d/nodejs index e8eecb829..5e5b13f4e 100644 --- a/helpers/helpers.v2.1.d/nodejs +++ b/helpers/helpers.v2.1.d/nodejs @@ -1,18 +1,17 @@ #!/bin/bash -n_install_dir="/opt/node_n" -node_version_path="$n_install_dir/n/versions/node" +readonly N_INSTALL_DIR="/opt/node_n" # N_PREFIX is the directory of n, it needs to be loaded as a environment variable. -export N_PREFIX="$n_install_dir" +export N_PREFIX="$N_INSTALL_DIR" _ynh_load_nodejs_in_path_and_other_tweaks() { # Get the absolute path of this version of node - local nodejs_path="$node_version_path/$nodejs_version/bin" + nodejs_dir="$N_INSTALL_DIR/n/versions/node/$nodejs_version/bin" # Load the path of this version of node in $PATH - if [[ :$PATH: != *":$nodejs_path"* ]]; then - PATH="$nodejs_path:$PATH" + if [[ :$PATH: != *":$nodejs_dir"* ]]; then + PATH="$nodejs_dir:$PATH" fi # Export PATH such that it's available through sudo -E / ynh_exec_as $app @@ -46,11 +45,11 @@ ynh_nodejs_install() { [[ -n "${nodejs_version:-}" ]] || ynh_die "\$nodejs_version should be defined prior to calling ynh_nodejs_install" - # Create $n_install_dir - mkdir --parents "$n_install_dir" + # Create $N_INSTALL_DIR + mkdir --parents "$N_INSTALL_DIR" # Load n path in PATH - CLEAR_PATH="$n_install_dir/bin:$PATH" + CLEAR_PATH="$N_INSTALL_DIR/bin:$PATH" # Remove /usr/local/bin in PATH in case of node prior installation PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') @@ -59,10 +58,10 @@ ynh_nodejs_install() { test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n # Install (or update if YunoHost vendor/ folder updated since last install) n - mkdir -p $n_install_dir/bin/ - cp "$YNH_HELPERS_DIR/vendor/n/n" $n_install_dir/bin/n + mkdir -p $N_INSTALL_DIR/bin/ + cp "$YNH_HELPERS_DIR/vendor/n/n" $N_INSTALL_DIR/bin/n # Tweak for n to understand it's installed in $N_PREFIX - ynh_replace --match="^N_PREFIX=\${N_PREFIX-.*}$" --replace="N_PREFIX=\${N_PREFIX-$N_PREFIX}" --file="$n_install_dir/bin/n" + ynh_replace --match="^N_PREFIX=\${N_PREFIX-.*}$" --replace="N_PREFIX=\${N_PREFIX-$N_PREFIX}" --file="$N_INSTALL_DIR/bin/n" # Restore /usr/local/bin in PATH PATH=$CLEAR_PATH @@ -80,16 +79,18 @@ ynh_nodejs_install() { fi # Find the last "real" version for this major version of node. - real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) + real_nodejs_version=$(find $N_INSTALL_DIR/n/versions/node/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) real_nodejs_version=$(basename $real_nodejs_version) # Create a symbolic link for this major version if the file doesn't already exist - if [ ! -e "$node_version_path/$nodejs_version" ]; then - ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version + if [ ! -e "$N_INSTALL_DIR/n/versions/node/$nodejs_version" ]; then + ln --symbolic --force --no-target-directory \ + $N_INSTALL_DIR/n/versions/node/$real_nodejs_version \ + $N_INSTALL_DIR/n/versions/node/$nodejs_version fi # Store the ID of this app and the version of node requested for it - echo "$YNH_APP_INSTANCE_NAME:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version" + echo "$YNH_APP_INSTANCE_NAME:$nodejs_version" | tee --append "$N_INSTALL_DIR/ynh_app_version" # Store nodejs_version into the config of this app ynh_app_setting_set --key=nodejs_version --value=$nodejs_version @@ -111,17 +112,16 @@ ynh_nodejs_remove() { [[ -n "${nodejs_version:-}" ]] || ynh_die "\$nodejs_version should be defined prior to calling ynh_nodejs_remove" # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version" + sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$N_INSTALL_DIR/ynh_app_version" # If no other app uses this version of nodejs, remove it. - if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"; then - $n_install_dir/bin/n rm $nodejs_version + if ! grep --quiet "$nodejs_version" "$N_INSTALL_DIR/ynh_app_version"; then + $N_INSTALL_DIR/bin/n rm $nodejs_version fi # If no other app uses n, remove n - if [ ! -s "$n_install_dir/ynh_app_version" ]; then - ynh_safe_rm "$n_install_dir" - ynh_safe_rm "/usr/local/n" + if [ ! -s "$N_INSTALL_DIR/ynh_app_version" ]; then + ynh_safe_rm "$N_INSTALL_DIR" sed --in-place "/N_PREFIX/d" /root/.bashrc fi } diff --git a/helpers/helpers.v2.1.d/ruby b/helpers/helpers.v2.1.d/ruby index dae25c6fd..c33967a9f 100644 --- a/helpers/helpers.v2.1.d/ruby +++ b/helpers/helpers.v2.1.d/ruby @@ -1,20 +1,19 @@ #!/bin/bash -rbenv_install_dir="/opt/rbenv" -ruby_version_path="$rbenv_install_dir/versions" +readonly RBENV_INSTALL_DIR="/opt/rbenv" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. -export RBENV_ROOT="$rbenv_install_dir" -export rbenv_root="$rbenv_install_dir" +export RBENV_ROOT="$RBENV_INSTALL_DIR" +export rbenv_root="$RBENV_INSTALL_DIR" _ynh_load_ruby_in_path_and_other_tweaks() { # Get the absolute path of this version of Ruby - local ruby_path="$ruby_version_path/$app/bin" + ruby_dir="$RBENV_INSTALL_DIR/versions/$app/bin" # Load the path of this version of ruby in $PATH - if [[ :$PATH: != *":$ruby_path"* ]]; then - PATH="$ruby_path:$PATH" + if [[ :$PATH: != *":$ruby_dir"* ]]; then + PATH="$ruby_dir:$PATH" fi # Export PATH such that it's available through sudo -E / ynh_exec_as $app @@ -26,7 +25,7 @@ _ynh_load_ruby_in_path_and_other_tweaks() { # Sets the local application-specific Ruby version pushd ${install_dir} - $rbenv_install_dir/bin/rbenv local $ruby_version + $RBENV_INSTALL_DIR/bin/rbenv local $ruby_version popd } @@ -55,7 +54,7 @@ ynh_ruby_install () { [[ -n "${ruby_version:-}" ]] || ynh_die "\$ruby_version should be defined prior to calling ynh_ruby_install" # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$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:@@') @@ -64,8 +63,8 @@ ynh_ruby_install () { test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv # Install or update rbenv - mkdir -p $rbenv_install_dir - rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" + mkdir -p $RBENV_INSTALL_DIR + rbenv="$(command -v rbenv $RBENV_INSTALL_DIR/bin/rbenv | grep "$RBENV_INSTALL_DIR/bin/rbenv" | head -1)" if [ -n "$rbenv" ]; then pushd "${rbenv%/*/*}" if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then @@ -75,30 +74,30 @@ ynh_ruby_install () { else echo "Reinstalling rbenv..." cd .. - ynh_safe_rm $rbenv_install_dir - mkdir -p $rbenv_install_dir - cd $rbenv_install_dir + ynh_safe_rm $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 + rbenv=$RBENV_INSTALL_DIR/bin/rbenv fi popd else echo "Installing rbenv..." - pushd $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 + rbenv=$RBENV_INSTALL_DIR/bin/rbenv popd fi - mkdir -p "${rbenv_install_dir}/plugins" + mkdir -p "${RBENV_INSTALL_DIR}/plugins" - ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" + ruby_build="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-install rbenv-install | head -1)" if [ -n "$ruby_build" ]; then pushd "${ruby_build%/*/*}" if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then @@ -108,10 +107,10 @@ ynh_ruby_install () { popd else echo "Installing ruby-build..." - git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build" + git clone -q https://github.com/rbenv/ruby-build.git "${RBENV_INSTALL_DIR}/plugins/ruby-build" fi - rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" + rbenv_alias="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" if [ -n "$rbenv_alias" ]; then pushd "${rbenv_alias%/*/*}" if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then @@ -121,10 +120,10 @@ ynh_ruby_install () { popd else echo "Installing rbenv-aliases..." - git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase" + git clone -q https://github.com/tpope/rbenv-aliases.git "${RBENV_INSTALL_DIR}/plugins/rbenv-aliase" fi - rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" + rbenv_latest="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" if [ -n "$rbenv_latest" ]; then pushd "${rbenv_latest%/*/*}" if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then @@ -134,14 +133,14 @@ ynh_ruby_install () { popd else echo "Installing xxenv-latest..." - git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest" + 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" + mkdir -p "${RBENV_INSTALL_DIR}/cache" # Create shims directory if needed - mkdir -p "${rbenv_install_dir}/shims" + mkdir -p "${RBENV_INSTALL_DIR}/shims" # Restore /usr/local/bin in PATH PATH=$CLEAR_PATH @@ -175,8 +174,8 @@ ynh_ruby_install () { # Set environment for Ruby users echo "#rbenv -export RBENV_ROOT=$rbenv_install_dir -export PATH=\"$rbenv_install_dir/bin:$PATH\" +export RBENV_ROOT=$RBENV_INSTALL_DIR +export PATH=\"$RBENV_INSTALL_DIR/bin:$PATH\" eval \"\$(rbenv init -)\" #rbenv" > /etc/profile.d/rbenv.sh @@ -192,10 +191,11 @@ eval \"\$(rbenv init -)\" # # usage: ynh_ruby_remove ynh_ruby_remove () { - local ruby_version=$(ynh_app_setting_get --key=ruby_version) + + [[ -n "${ruby_version:-}" ]] || ynh_die "\$ruby_version should be defined prior to calling ynh_ruby_remove" # Load rbenv path in PATH - local CLEAR_PATH="$rbenv_install_dir/bin:$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:@@') @@ -235,7 +235,7 @@ _ynh_ruby_cleanup () { if ! echo ${required_ruby_versions} | grep -q "${installed_ruby_version}" then echo "Removing Ruby-$installed_ruby_version" - $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version + $RBENV_INSTALL_DIR/bin/rbenv uninstall --force $installed_ruby_version fi done @@ -244,7 +244,7 @@ _ynh_ruby_cleanup () { then # Remove rbenv environment configuration echo "Removing rbenv" - ynh_safe_rm "$rbenv_install_dir" + ynh_safe_rm "$RBENV_INSTALL_DIR" ynh_safe_rm "/etc/profile.d/rbenv.sh" fi }