mirror of
https://github.com/YunoHost-Apps/mastodon_ynh.git
synced 2024-09-03 19:46:02 +02:00
commit
0337521cde
6 changed files with 275 additions and 164 deletions
|
@ -10,7 +10,7 @@ pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git
|
||||||
MEMORY_NEEDED="2560"
|
MEMORY_NEEDED="2560"
|
||||||
|
|
||||||
RUBY_VERSION="2.7.2"
|
RUBY_VERSION="2.7.2"
|
||||||
BUNDLER_VERSION="1.17.3"
|
|
||||||
NODEJS_VERSION="12"
|
NODEJS_VERSION="12"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -75,9 +75,10 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing dependencies..."
|
ynh_script_progression --message="Installing dependencies..."
|
||||||
|
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
|
||||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||||
|
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A POSTGRESQL DATABASE
|
# CREATE A POSTGRESQL DATABASE
|
||||||
|
@ -124,7 +125,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD SWAP IF NEEDED
|
# ADD SWAP IF NEEDED
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Adding swap is needed..."
|
ynh_script_progression --message="Adding swap if needed..."
|
||||||
|
|
||||||
total_memory=$(ynh_get_ram --total)
|
total_memory=$(ynh_get_ram --total)
|
||||||
swap_needed=0
|
swap_needed=0
|
||||||
|
@ -142,10 +143,10 @@ ynh_add_swap --size=$swap_needed
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
ynh_script_progression --message="Installing Ruby..."
|
||||||
|
|
||||||
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
pushd "$final_path/live"
|
pushd "$final_path/live"
|
||||||
$RBENV_ROOT/versions/$app/bin/gem update --system
|
ynh_use_ruby
|
||||||
$RBENV_ROOT/versions/$app/bin/gem install bundler:$BUNDLER_VERSION --no-document
|
ynh_gem update --system
|
||||||
|
ynh_gem install bundler --no-document
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -181,17 +182,17 @@ ynh_script_progression --message="Installing Mastodon..."
|
||||||
chown -R "$app": "$final_path"
|
chown -R "$app": "$final_path"
|
||||||
|
|
||||||
pushd "$final_path/live"
|
pushd "$final_path/live"
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true'
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test'
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
||||||
ynh_use_nodejs
|
ynh_use_nodejs
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true'
|
sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config without 'development test'
|
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
|
||||||
sudo -u $app PATH=$PATH yarn install --pure-lockfile
|
|
||||||
echo "SAFETY_ASSURED=1">> $config
|
echo "SAFETY_ASSURED=1">> $config
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails db:setup --quiet
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:setup --quiet
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:precompile --quiet
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl accounts modify "$admin" --approve
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl accounts modify "$admin" --approve
|
||||||
popd
|
popd
|
||||||
|
|
||||||
vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt")
|
vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt")
|
||||||
|
@ -253,7 +254,7 @@ yunohost service add "$app-streaming" --description "$app streaming service"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..."
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp"
|
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||||
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,8 @@ ynh_script_progression --message="Removing dependencies..."
|
||||||
|
|
||||||
# Remove metapackage and its dependencies
|
# Remove metapackage and its dependencies
|
||||||
ynh_remove_ruby
|
ynh_remove_ruby
|
||||||
ynh_remove_app_dependencies
|
|
||||||
ynh_remove_nodejs
|
ynh_remove_nodejs
|
||||||
|
ynh_remove_app_dependencies
|
||||||
ynh_remove_extra_repo
|
ynh_remove_extra_repo
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -101,19 +101,20 @@ ynh_add_swap --size=$swap_needed
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Reinstalling dependencies..."
|
ynh_script_progression --message="Reinstalling dependencies..."
|
||||||
|
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
|
||||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||||
|
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALLING RUBY AND BUNDLER
|
# INSTALLING RUBY AND BUNDLER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
ynh_script_progression --message="Installing Ruby..."
|
||||||
|
|
||||||
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
pushd "$final_path/live"
|
pushd "$final_path/live"
|
||||||
gem update --system
|
ynh_use_ruby
|
||||||
gem install bundler:$BUNDLER_VERSION --no-document
|
ynh_gem update --system
|
||||||
|
ynh_gem install bundler --no-document
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -150,7 +151,7 @@ yunohost service add "$app-streaming" --description "$app streaming service"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..."
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp"
|
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||||
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
||||||
|
|
||||||
|
|
|
@ -184,10 +184,10 @@ ynh_add_nginx_config 'port_web port_stream'
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading dependencies..."
|
ynh_script_progression --message="Upgrading dependencies..."
|
||||||
|
|
||||||
ynh_remove_nodejs
|
|
||||||
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
||||||
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||||
|
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# CREATE DEDICATED USER
|
||||||
|
@ -220,10 +220,10 @@ ynh_add_swap --size=$swap_needed
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
ynh_script_progression --message="Installing Ruby..."
|
||||||
|
|
||||||
ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
pushd "$final_path/live"
|
pushd "$final_path/live"
|
||||||
gem update --system
|
ynh_use_ruby
|
||||||
gem install bundler:$BUNDLER_VERSION --no-document
|
ynh_gem update --system
|
||||||
|
ynh_gem install bundler --no-document
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -243,15 +243,15 @@ ynh_script_progression --message="Upgrading Mastodon..."
|
||||||
chown -R "$app": "$final_path"
|
chown -R "$app": "$final_path"
|
||||||
|
|
||||||
pushd "$final_path/live"
|
pushd "$final_path/live"
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true'
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test'
|
||||||
|
sudo -u $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
||||||
ynh_use_nodejs
|
ynh_use_nodejs
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true'
|
sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config without 'development test'
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:clean
|
||||||
sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile
|
||||||
sudo -u $app PATH=$PATH yarn install --pure-lockfile
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:clean
|
sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl cache clear
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:precompile
|
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails db:migrate
|
|
||||||
sudo -u $app RAILS_ENV=production PATH=$PATH bin/tootctl cache clear
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -295,7 +295,7 @@ yunohost service add "$app-streaming" --description "$app streaming service"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..."
|
ynh_script_progression --message="Starting a systemd service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on tcp"
|
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||||
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
|
||||||
|
|
||||||
|
|
|
@ -1,59 +1,89 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
|
ynh_ruby_try_bash_extension() {
|
||||||
|
if [ -x src/configure ]; then
|
||||||
|
src/configure && make -C src || {
|
||||||
|
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
rbenv_version=1.1.2
|
|
||||||
rbenv_rubybuild_version=20201225
|
|
||||||
rbenv_aliases_version=1.1.0
|
|
||||||
rbenv_install_dir="/opt/rbenv"
|
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.
|
# 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"
|
||||||
|
|
||||||
# Install Ruby Version Management
|
# Load the version of Ruby for an app, and set variables.
|
||||||
#
|
#
|
||||||
# [internal]
|
# 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.
|
||||||
#
|
#
|
||||||
# usage: ynh_install_rbenv
|
# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby`
|
||||||
ynh_install_rbenv () {
|
# Those alias will use the correct version installed for the app
|
||||||
ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${rbenv_rubybuild_version}"
|
# 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 3.2.2 or higher.
|
||||||
|
ynh_use_ruby () {
|
||||||
|
ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version)
|
||||||
|
|
||||||
# Build an app.src for rbenv
|
# Get the absolute path of this version of Ruby
|
||||||
mkdir -p "../conf"
|
ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin"
|
||||||
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
|
# Allow alias to be used into bash script
|
||||||
mkdir -p "../conf"
|
shopt -s expand_aliases
|
||||||
echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v${rbenv_rubybuild_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 ruby-build
|
# Create an alias for the specific version of Ruby and a variable as fallback
|
||||||
mkdir -p "../conf"
|
ynh_ruby="$ruby_path/ruby"
|
||||||
echo "SOURCE_URL=https://github.com/tpope/rbenv-aliases/archive/v${rbenv_aliases_version}.tar.gz
|
alias ynh_ruby="$ynh_ruby"
|
||||||
SOURCE_SUM=12e89bc4499e85d8babac2b02bc8b66ceb0aa3f8047b26728a3eca8a6030273d" > "../conf/rbenv-aliases.src"
|
# And gem
|
||||||
# Download and extract ruby-build
|
ynh_gem="$ruby_path/gem"
|
||||||
ynh_setup_source --dest_dir="$rbenv_install_dir/plugins/rbenv-aliases" --source_id=rbenv-aliases
|
alias ynh_gem="$ynh_gem"
|
||||||
|
|
||||||
(cd $rbenv_install_dir
|
# Load the path of this version of Ruby in $PATH
|
||||||
./src/configure && make -C src)
|
if [[ :$PATH: != *":$ruby_path"* ]]; then
|
||||||
|
PATH="$ruby_path:$PATH"
|
||||||
|
fi
|
||||||
|
# Create an alias to easily load the PATH
|
||||||
|
ynh_ruby_load_path="PATH=$PATH"
|
||||||
|
|
||||||
# Create shims directory if needed
|
# Sets the local application-specific Ruby version
|
||||||
if [ ! -d $rbenv_install_dir/shims ] ; then
|
pushd $final_path
|
||||||
mkdir $rbenv_install_dir/shims
|
$rbenv_install_dir/bin/rbenv local $ruby_version
|
||||||
fi
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install a specific version of Ruby
|
# Install a specific version of Ruby
|
||||||
#
|
#
|
||||||
# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv.
|
# 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 <version>)
|
|
||||||
# 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
|
# 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)
|
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
|
||||||
#
|
#
|
||||||
|
@ -64,132 +94,211 @@ fi
|
||||||
#
|
#
|
||||||
# usage: ynh_install_ruby --ruby_version=ruby_version
|
# usage: ynh_install_ruby --ruby_version=ruby_version
|
||||||
# | arg: -v, --ruby_version= - Version of ruby to install.
|
# | arg: -v, --ruby_version= - Version of ruby to install.
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 3.2.2 or higher.
|
||||||
ynh_install_ruby () {
|
ynh_install_ruby () {
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
declare -Ar args_array=( [v]=ruby_version= )
|
local legacy_args=v
|
||||||
local ruby_version
|
local -A args_array=( [v]=ruby_version= )
|
||||||
# Manage arguments with getopts
|
local ruby_version
|
||||||
ynh_handle_getopts_args "$@"
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
# Store ruby_version into the config of this app
|
# Load rbenv path in PATH
|
||||||
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$ruby_version
|
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
||||||
|
|
||||||
# Create $rbenv_install_dir if doesn't exist already
|
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
||||||
mkdir -p "$rbenv_install_dir/plugins/ruby-build"
|
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||||
|
|
||||||
# Create the file if doesn't exist already
|
# Move an existing Ruby binary, to avoid to block rbenv
|
||||||
touch "$rbenv_install_dir/ynh_app_version"
|
test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
|
||||||
|
|
||||||
# Load rbenv path in PATH
|
# Install or update rbenv
|
||||||
CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
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 "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
|
||||||
|
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
|
||||||
|
|
||||||
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)"
|
||||||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
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 "https://github.com/rbenv/ruby-build.git"; 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
|
||||||
|
|
||||||
# Move an existing Ruby binary, to avoid to block rbenv
|
rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)"
|
||||||
test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
|
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 "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
|
||||||
|
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
|
||||||
|
|
||||||
# If rbenv is not previously setup, install it
|
rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)"
|
||||||
if ! type rbenv > /dev/null 2>&1
|
if [ -n "$rbenv_latest" ]; then
|
||||||
then
|
ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'."
|
||||||
ynh_install_rbenv
|
pushd "${rbenv_latest%/*/*}"
|
||||||
elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt ${rbenv_version}
|
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
|
||||||
then
|
ynh_print_info --message="Trying to update xxenv-latest with git..."
|
||||||
ynh_install_rbenv
|
git pull -q origin master
|
||||||
elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt ${rbenv_rubybuild_version}
|
fi
|
||||||
then
|
popd
|
||||||
ynh_install_rbenv
|
else
|
||||||
fi
|
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
|
||||||
|
|
||||||
# Restore /usr/local/bin in PATH (if needed)
|
# Enable caching
|
||||||
PATH=$CLEAR_PATH
|
mkdir -p "${rbenv_install_dir}/cache"
|
||||||
|
|
||||||
# And replace the old Ruby binary
|
# Create shims directory if needed
|
||||||
test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
|
mkdir -p "${rbenv_install_dir}/shims"
|
||||||
|
|
||||||
# Install the requested version of Ruby
|
# Restore /usr/local/bin in PATH
|
||||||
ynh_print_info --message="Installation of Ruby-"$ruby_version
|
PATH=$CLEAR_PATH
|
||||||
CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version
|
|
||||||
|
|
||||||
# Do not add twice the same line
|
# And replace the old Ruby binary
|
||||||
if ! grep --quiet "$YNH_APP_INSTANCE_NAME:$ruby_version" "$rbenv_install_dir/ynh_app_version"
|
test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
|
||||||
then
|
|
||||||
|
|
||||||
# Remove previous version
|
# Install the requested version of Ruby
|
||||||
if grep --quiet "$YNH_APP_INSTANCE_NAME:" "$rbenv_install_dir/ynh_app_version"
|
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
|
||||||
|
|
||||||
|
# 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`
|
||||||
then
|
then
|
||||||
if grep --quiet "$YNH_APP_INSTANCE_NAME" $(rbenv alias --list)
|
|
||||||
then
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
||||||
fi
|
|
||||||
sed --in-place "/$YNH_APP_INSTANCE_NAME:/d" "$rbenv_install_dir/ynh_app_version"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Store the ID of this app and the version of Ruby requested for it
|
# Create app virtualenv
|
||||||
echo "$YNH_APP_INSTANCE_NAME:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version"
|
rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove no more needed Ruby version
|
# Cleanup Ruby versions
|
||||||
installed_ruby_version=$(rbenv versions --bare --skip-aliases | grep -Ev '/')
|
ynh_cleanup_ruby
|
||||||
for installed_version in $installed_ruby_version
|
|
||||||
do
|
|
||||||
if ! grep --quiet "$installed_version" "$rbenv_install_dir/ynh_app_version"
|
|
||||||
then
|
|
||||||
ynh_print_info --message="Removing of ruby-"$installed_version
|
|
||||||
$rbenv_install_dir/bin/rbenv uninstall --force $installed_version
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Set environment for Ruby users
|
# Set environment for Ruby users
|
||||||
echo "#rbenv
|
echo "#rbenv
|
||||||
export RBENV_ROOT=$rbenv_install_dir
|
export RBENV_ROOT=$rbenv_install_dir
|
||||||
export PATH=\"$rbenv_install_dir/bin:$PATH\"
|
export PATH=\"$rbenv_install_dir/bin:$PATH\"
|
||||||
eval \"\$(rbenv init -)\"
|
eval \"\$(rbenv init -)\"
|
||||||
#rbenv" > /etc/profile.d/rbenv.sh
|
#rbenv" > /etc/profile.d/rbenv.sh
|
||||||
|
|
||||||
# Load the environment
|
# Load the environment
|
||||||
eval "$(rbenv init -)"
|
eval "$(rbenv init -)"
|
||||||
|
|
||||||
(cd $final_path
|
|
||||||
rbenv local $ruby_version)
|
|
||||||
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME $ruby_version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the version of Ruby used by the app.
|
# Remove the version of Ruby used by the app.
|
||||||
#
|
#
|
||||||
# This helper will check if another app uses the same version of Ruby,
|
# This helper will also cleanup Ruby versions
|
||||||
# if not, this version of Ruby will be removed.
|
|
||||||
# If no other app uses Ruby, rbenv will be also removed.
|
|
||||||
#
|
#
|
||||||
# usage: ynh_remove_ruby
|
# usage: ynh_remove_ruby
|
||||||
ynh_remove_ruby () {
|
ynh_remove_ruby () {
|
||||||
local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version)
|
local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version)
|
||||||
|
|
||||||
# Load rbenv path in PATH
|
# Load rbenv path in PATH
|
||||||
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
|
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
||||||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||||
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
||||||
|
|
||||||
# Remove the line for this app
|
# Remove the line for this app
|
||||||
sed --in-place "/$YNH_APP_INSTANCE_NAME:$ruby_version/d" "$rbenv_install_dir/ynh_app_version"
|
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version
|
||||||
|
|
||||||
# If no other app uses this version of Ruby, remove it.
|
# Cleanup Ruby versions
|
||||||
if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version"
|
ynh_cleanup_ruby
|
||||||
then
|
}
|
||||||
ynh_print_info --message="Removing of Ruby-"$ruby_version
|
|
||||||
$rbenv_install_dir/bin/rbenv uninstall --force $ruby_version
|
# Remove no more needed versions of Ruby used by the app.
|
||||||
fi
|
#
|
||||||
|
# This helper will check what Ruby version are no more required,
|
||||||
# If no other app uses rbenv, remove rbenv and dedicated group
|
# and uninstall them
|
||||||
if [ ! -s "$rbenv_install_dir/ynh_app_version" ]
|
# If no app uses Ruby, rbenv will be also removed.
|
||||||
then
|
#
|
||||||
ynh_print_info --message="Removing of rbenv"
|
# usage: ynh_cleanup_ruby
|
||||||
ynh_secure_remove --file="$rbenv_install_dir"
|
ynh_cleanup_ruby () {
|
||||||
# Remove rbenv environment configuration
|
|
||||||
rm /etc/profile.d/rbenv.sh
|
# List required Ruby versions
|
||||||
fi
|
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=$(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}"
|
||||||
|
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
|
||||||
|
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"
|
||||||
|
ynh_secure_remove --file="/etc/profile.d/rbenv.sh"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue