aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryalh76 <yalh@yahoo.com>2021-04-23 13:05:33 +0200
committerGitHub <noreply@github.com>2021-04-23 13:05:33 +0200
commit27e1471e45b09cbe188eab46ecbff2079a6ba4a0 (patch)
treeabd1fafb44d4830bb7e75da7f8a3e0fa3e19401f
parenta7eb98db3fac0697b923072dcd78c1ca04bf0a12 (diff)
parente2a23d46f649505a9ece78e1b3e4f0fd73196539 (diff)
downloadmastodon_ynh-27e1471e45b09cbe188eab46ecbff2079a6ba4a0.tar.gz
mastodon_ynh-27e1471e45b09cbe188eab46ecbff2079a6ba4a0.tar.bz2
mastodon_ynh-27e1471e45b09cbe188eab46ecbff2079a6ba4a0.zip
Merge pull request #263 from YunoHost-Apps/testing
ynh_install_ruby__2
-rw-r--r--README.md4
-rw-r--r--README_fr.md4
-rw-r--r--check_process14
-rw-r--r--conf/app.src4
-rw-r--r--manifest.json22
-rw-r--r--scripts/_common.sh2
-rw-r--r--scripts/backup2
-rw-r--r--scripts/install118
-rw-r--r--scripts/remove10
-rw-r--r--scripts/restore57
-rw-r--r--scripts/upgrade96
-rw-r--r--scripts/ynh_install_ruby__2363
12 files changed, 395 insertions, 301 deletions
diff --git a/README.md b/README.md
index 5336221..a4bd460 100644
--- a/README.md
+++ b/README.md
@@ -58,8 +58,8 @@ LDAP authentication is activated. All YunoHost users can authenticate.
#### Supported architectures
-* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/)
-* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/)
+* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/)
+* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/)
## Links
diff --git a/README_fr.md b/README_fr.md
index 6553753..1f1fc84 100644
--- a/README_fr.md
+++ b/README_fr.md
@@ -59,8 +59,8 @@ L'authentification LDAP est activée. Tous les utilisateurs YunoHost peuvent s'a
#### Architectures supportées
-* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/)
-* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/)
+* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps.yunohost.org/ci/apps/mastodon/)
+* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/mastodon.svg)](https://ci-apps-arm.yunohost.org/ci/apps/mastodon/)
## Liens
diff --git a/check_process b/check_process
index 72f8049..1c35a30 100644
--- a/check_process
+++ b/check_process
@@ -17,15 +17,17 @@
# 3.1.2~ynh3
#upgrade=1 from_commit=6b30109fc986d83166b1805ec3ad7e28200e3743
# 3.1.2~ynh4
- upgrade=1 from_commit=d3df899e0a99a63ee1cf7ad845cc513aeaaf30ef
+ #upgrade=1 from_commit=d3df899e0a99a63ee1cf7ad845cc513aeaaf30ef
# 3.2.0~ynh1
- upgrade=1 from_commit=bde14cc4496445fdfed4616ac44fc9527c8369fd
+ #upgrade=1 from_commit=bde14cc4496445fdfed4616ac44fc9527c8369fd
# 3.2.1~ynh1
- upgrade=1 from_commit=248b717f373f3c82bdb19c33cf20980494608697
+ #upgrade=1 from_commit=248b717f373f3c82bdb19c33cf20980494608697
# 3.2.1~ynh2
- upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75
+ #upgrade=1 from_commit=74908bf3e70c134bc838c7db3ae8b5aa0938cd75
# 3.2.2~ynh1
- upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c
+ #upgrade=1 from_commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c
+ # 3.3.0~ynh1
+ #upgrade=1 from_commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12
backup_restore=1
multi_instance=1
port_already_use=0
@@ -48,3 +50,5 @@ Notification=all
name=3.2.1~ynh2
; commit=a233ccc644d97aa89756fac9f0ce68c98d81d27c
name=3.2.2~ynh1
+ ; commit=a7eb98db3fac0697b923072dcd78c1ca04bf0a12
+ name=3.3.0~ynh1
diff --git a/conf/app.src b/conf/app.src
index 6fb011a..6383dac 100644
--- a/conf/app.src
+++ b/conf/app.src
@@ -1,5 +1,5 @@
-SOURCE_URL=https://github.com/tootsuite/mastodon/archive/v3.3.0.tar.gz
-SOURCE_SUM=ffbaeaf18d9c440ac61c6c5c29fd6581b88c1d2843170f2cb5f0fcf8dcc0ecd6
+SOURCE_URL=https://github.com/tootsuite/mastodon/archive/1efcbb9cfe36d4428ef6af988bb0d7b25ace3971.tar.gz
+SOURCE_SUM=4ecbfd34ea37d739fbcec11cf9b812e8d8f60f6367f8ce255a062d5d64d92557
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
diff --git a/manifest.json b/manifest.json
index 2d38584..d6aa9f1 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,10 +6,13 @@
"en": "A libre and federated social network.",
"fr": "Un réseau social libre et fédéré."
},
- "version": "3.3.0~ynh1",
+ "version": "3.3.0~ynh2",
"url": "https://github.com/tootsuite/mastodon",
"license": "AGPL-3.0-or-later",
- "maintainer": [
+ "maintainer": {
+ "name": "yalh76"
+ },
+ "previous_maintainer": [
{
"name": "cyp",
"email": "cyp@rouquin.me"
@@ -17,9 +20,6 @@
{
"name": "nemsia",
"email": "nemsia@nemsia.org"
- },
- {
- "name": "yalh76"
}
],
"requirements": {
@@ -34,28 +34,16 @@
{
"name": "domain",
"type": "domain",
- "ask": {
- "en": "Choose a domain for Mastodon",
- "fr": "Choisissez un domaine pour Mastodon"
- },
"example": "example.com"
},
{
"name": "admin",
"type": "user",
- "ask": {
- "en": "Choose an admin user",
- "fr": "Choisissez l'administrateur"
- },
"example": "johndoe"
},
{
"name": "is_public",
"type": "boolean",
- "ask": {
- "en": "Is it a public application?",
- "fr": "Est-ce une application publique ?"
- },
"default": true
},
{
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 1c28aec..b6f4796 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -10,7 +10,7 @@ pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git
MEMORY_NEEDED="2560"
RUBY_VERSION="2.7.2"
-BUNDLER_VERSION="1.17.3"
+
NODEJS_VERSION="12"
#=================================================
diff --git a/scripts/backup b/scripts/backup
index c1d4f6f..590ce0f 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
-#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
+# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
diff --git a/scripts/install b/scripts/install
index 7d21d45..f5da202 100644
--- a/scripts/install
+++ b/scripts/install
@@ -75,9 +75,18 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream
#=================================================
ynh_script_progression --message="Installing dependencies..."
+ynh_install_app_dependencies $pkg_dependencies
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_ruby --ruby_version=$RUBY_VERSION
+
+#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_script_progression --message="Configuring system user..."
+
+# Create a system user
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A POSTGRESQL DATABASE
@@ -103,28 +112,24 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/live"
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
+
#=================================================
# NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Configuring nginx web server..."
+ynh_script_progression --message="Configuring NGINX web server..."
-# Create a dedicated nginx config
+# Create a dedicated NGINX config
ynh_add_nginx_config 'port_web port_stream'
#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Configuring system user..."
-
-# Create a system user
-ynh_system_user_create --username=$app --home_dir=$final_path
-
-#=================================================
# SPECIFIC SETUP
#=================================================
# 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)
swap_needed=0
@@ -142,16 +147,16 @@ ynh_add_swap --size=$swap_needed
#=================================================
ynh_script_progression --message="Installing Ruby..."
-ynh_install_ruby --ruby_version=$RUBY_VERSION
pushd "$final_path/live"
- $RBENV_ROOT/versions/$app/bin/gem update --system
- $RBENV_ROOT/versions/$app/bin/gem install bundler:$BUNDLER_VERSION --no-document
+ ynh_use_ruby
+ ynh_gem update --system
+ ynh_gem install bundler --no-document
popd
#=================================================
-# MODIFY A CONFIG FILE
+# ADD A CONFIGURATION
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Adding a config file..."
config="$final_path/live/.env.production"
@@ -168,30 +173,44 @@ vapid_public_key=""
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
+chmod 400 "$config"
+chown $app:$app "$config"
+
ynh_replace_string --match_string="registrations_mode: 'open'" --replace_string="registrations_mode: 'none'" --target_file="$final_path/live/config/settings.yml"
ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="min_invite_role: 'none'" --target_file="$final_path/live/config/settings.yml"
ynh_store_file_checksum --file="$final_path/live/config/settings.yml"
+chmod 400 "$final_path/live/config/settings.yml"
+chown $app:$app "$final_path/live/config/settings.yml"
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Configuring a systemd service..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
+ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
+ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
+
#=================================================
# INSTALLING MASTODON
#=================================================
ynh_script_progression --message="Installing Mastodon..."
-chown -R "$app": "$final_path"
-
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
- sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true'
- 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
+ sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile
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 PATH=$PATH $RBENV_ROOT/versions/$app/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 PATH=$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/bundle exec rails db:setup --quiet
+ sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile --quiet
+ 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 $ynh_ruby_load_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 modify "$admin" --approve
popd
vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt")
@@ -200,9 +219,14 @@ ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private
vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt")
ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key"
+ynh_secure_remove --file="$final_path/live/key.txt"
+
+ynh_delete_file_checksum --file="$config"
+
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
-ynh_secure_remove --file="$final_path/live/key.txt"
+chmod 400 "$config"
+chown $app:$app "$config"
#=================================================
# SETUP THE CRON FILE
@@ -212,48 +236,22 @@ ynh_script_progression --message="Setuping the cron file..."
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Configuring a systemd service..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
-ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
-ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
-
-#=================================================
-# STORE THE CONFIG FILE CHECKSUM
-#=================================================
-ynh_script_progression --message="Storing the config file checksum..."
-
-# Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --file="$config"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions to app files
-chown -R "$app": "$final_path"
-
-#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START 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}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
@@ -275,7 +273,7 @@ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --aut
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/remove b/scripts/remove
index 6b16380..42b0109 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -29,7 +29,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
-# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
+# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null
then
ynh_script_progression --message="Removing $app-web service integration..."
@@ -64,7 +64,7 @@ ynh_remove_systemd_config --service="$app-streaming"
ynh_script_progression --message="Removing the PostgreSQL database..."
# Remove a database if it exists, along with the associated user
-ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name"
+ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
@@ -73,8 +73,8 @@ ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_ruby
-ynh_remove_app_dependencies
ynh_remove_nodejs
+ynh_remove_app_dependencies
ynh_remove_extra_repo
#=================================================
@@ -88,9 +88,9 @@ ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Removing nginx web server configuration..."
+ynh_script_progression --message="Removing NGINX web server configuration..."
-# Remove the dedicated nginx config
+# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
diff --git a/scripts/restore b/scripts/restore
index 6744ddb..7a3808b 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
-#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
+# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_ruby__2
source ../settings/scripts/ynh_add_swap
@@ -25,7 +25,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
-ynh_script_progression --message="Loading settings..."
+ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -51,32 +51,28 @@ test ! -d $final_path \
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Restoring the nginx configuration..."
+ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
-# RESTORE THE APP MAIN DIR
-#=================================================
-ynh_script_progression --message="Restoring the app main directory..."
-
-ynh_restore_file --origin_path="$final_path"
-
-#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
-# RESTORE USER RIGHTS
+# RESTORE THE APP MAIN DIR
#=================================================
-ynh_script_progression --message="Restoring user rights..."
+ynh_script_progression --message="Restoring the app main directory..."
+
+ynh_restore_file --origin_path="$final_path"
-# Restore permissions on app files
-chown -R $app: $final_path
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
#=================================================
# SPECIFIC RESTORATION
@@ -97,23 +93,31 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
#=================================================
+# RESTORE THE CRON FILE
+#=================================================
+ynh_script_progression --message="Restoring the cron file..."
+
+ynh_restore_file --origin_path="/etc/cron.d/$app"
+
+#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
+ynh_install_app_dependencies $pkg_dependencies
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_ruby --ruby_version=$RUBY_VERSION
#=================================================
# INSTALLING RUBY AND BUNDLER
#=================================================
ynh_script_progression --message="Installing Ruby..."
-ynh_install_ruby --ruby_version=$RUBY_VERSION
pushd "$final_path/live"
- gem update --system
- gem install bundler:$BUNDLER_VERSION --no-document
+ ynh_use_ruby
+ ynh_gem update --system
+ ynh_gem install bundler --no-document
popd
#=================================================
@@ -141,27 +145,20 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START 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}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
#=================================================
-# RESTORE THE CRON FILE
-#=================================================
-ynh_script_progression --message="Restoring the cron file..."
-
-ynh_restore_file --origin_path="/etc/cron.d/$app"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
diff --git a/scripts/upgrade b/scripts/upgrade
index bbbe50b..86555dc 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -49,7 +49,6 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
-
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@@ -124,7 +123,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
- # restore it if the upgrade fails
+ # Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
@@ -142,6 +141,14 @@ ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=syst
ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped"
#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_script_progression --message="Making sure dedicated system user exists..."
+
+# Create a dedicated user (if not existing)
+ynh_system_user_create --username=$app --home_dir="$final_path"
+
+#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@@ -171,10 +178,14 @@ then
ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb"
fi
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
+
#=================================================
# NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Upgrading nginx web server configuration..."
+ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config 'port_web port_stream'
@@ -184,18 +195,10 @@ ynh_add_nginx_config 'port_web port_stream'
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
-ynh_remove_nodejs
-ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
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"
-
-#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Making sure dedicated system user exists..."
-
-# Create a dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_install_ruby --ruby_version=$RUBY_VERSION
#=================================================
# SPECIFIC UPGRADE
@@ -220,21 +223,34 @@ ynh_add_swap --size=$swap_needed
#=================================================
ynh_script_progression --message="Installing Ruby..."
-ynh_install_ruby --ruby_version=$RUBY_VERSION
pushd "$final_path/live"
- gem update --system
- gem install bundler:$BUNDLER_VERSION --no-document
+ ynh_use_ruby
+ ynh_gem update --system
+ ynh_gem install bundler --no-document
popd
#=================================================
-# MODIFY A CONFIG FILE
+# UPDATE A CONFIG FILE
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Updating a config file..."
language="$(echo $language | head -c 2)"
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
+chmod 400 "$config"
+chown $app:$app "$config"
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Upgrading systemd configuration..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
+ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
+ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
+
#=================================================
# UPGRADE MASTODON
#=================================================
@@ -243,15 +259,15 @@ ynh_script_progression --message="Upgrading Mastodon..."
chown -R "$app": "$final_path"
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
- sudo -u $app PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle config deployment 'true'
- 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
- sudo -u $app RAILS_ENV=production PATH=$PATH $RBENV_ROOT/versions/$app/bin/bundle exec rails assets:clean
- 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
+ sudo -u $app $ynh_node_load_PATH yarn install --pure-lockfile
+ sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:clean
+ sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails assets:precompile
+ sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/bundle exec rails db:migrate
+ sudo -u $app RAILS_ENV=production $ynh_ruby_load_path bin/tootctl cache clear
popd
#=================================================
@@ -262,47 +278,29 @@ ynh_script_progression --message="Setuping the cron file..."
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Upgrading systemd configuration..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
-ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
-ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions on app files
-chown -R $app: $final_path
-
-#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START 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}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2
index 1d9bf8d..fae1755 100644
--- a/scripts/ynh_install_ruby__2
+++ b/scripts/ynh_install_ruby__2
@@ -1,59 +1,89 @@
#!/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"
+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
+# 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
#
-# [internal]
#
-# usage: ynh_install_rbenv
-ynh_install_rbenv () {
- ynh_print_info --message="Installation of rbenv - Ruby Version Management - rbenv-${rbenv_version}/ruby-build-${rbenv_rubybuild_version}"
+# 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
- 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
+ # Get the absolute path of this version of Ruby
+ ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin"
- # 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
-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
+ # Allow alias to be used into bash script
+ shopt -s expand_aliases
- # 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
-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
+ # 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"
- (cd $rbenv_install_dir
- ./src/configure && make -C src)
+ # 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"
-# Create shims directory if needed
-if [ ! -d $rbenv_install_dir/shims ] ; then
- mkdir $rbenv_install_dir/shims
-fi
+ # Sets the local application-specific Ruby version
+ pushd $final_path
+ $rbenv_install_dir/bin/rbenv local $ruby_version
+ popd
}
# Install a specific version of 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 <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
# 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
# | arg: -v, --ruby_version= - Version of ruby to install.
+#
+# Requires YunoHost version 3.2.2 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 "$@"
+ # 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
+ # Load rbenv path in PATH
+ local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
- # Create $rbenv_install_dir if doesn't exist already
- mkdir -p "$rbenv_install_dir/plugins/ruby-build"
+ # Remove /usr/local/bin in PATH in case of Ruby prior installation
+ PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
- # Create the file if doesn't exist already
- touch "$rbenv_install_dir/ynh_app_version"
+ # Move an existing Ruby binary, to avoid to block rbenv
+ test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
- # Load rbenv path in PATH
- CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
+ # 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 "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
- PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
+ 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 "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
- test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
+ 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 "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
- 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
+ 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 "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
+ 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
- # Restore /usr/local/bin in PATH (if needed)
- PATH=$CLEAR_PATH
+ # Enable caching
+ mkdir -p "${rbenv_install_dir}/cache"
- # And replace the old Ruby binary
- test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
+ # Create shims directory if needed
+ mkdir -p "${rbenv_install_dir}/shims"
- # 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
+ # Restore /usr/local/bin in PATH
+ PATH=$CLEAR_PATH
- # Do not add twice the same line
- if ! grep --quiet "$YNH_APP_INSTANCE_NAME:$ruby_version" "$rbenv_install_dir/ynh_app_version"
- then
+ # And replace the old Ruby binary
+ test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
- # Remove previous version
- if grep --quiet "$YNH_APP_INSTANCE_NAME:" "$rbenv_install_dir/ynh_app_version"
- 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"
+ # 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
- # 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
+ # 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 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"
+ # 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 $final_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 -)"
-
- (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)
+ 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"
+ # 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:@@')
+ # 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
+ 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"
+ # Remove the line for this app
+ ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_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
+ # Cleanup Ruby versions
+ ynh_cleanup_ruby
+}
- # 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
+# 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 versions
+ 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
}