From 0ecdb6e3c330b9594a83443ea60597f8367c55bf Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Mon, 18 May 2020 15:23:13 +0200 Subject: [PATCH 01/40] Fix nginx.conf for multi-instance --- conf/nginx.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 7fa7b87..d348613 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -38,7 +38,7 @@ location @proxy { proxy_set_header Proxy ""; proxy_pass_header Server; - proxy_pass http://127.0.0.1:3000; + proxy_pass http://127.0.0.1:__PORT_WEB__; proxy_buffering on; proxy_redirect off; proxy_http_version 1.1; @@ -62,7 +62,7 @@ location /api/v1/streaming { proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; - proxy_pass http://127.0.0.1:4000; + proxy_pass http://127.0.0.1:__PORT_STREAM__; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; From ee08de04d42a5e9831f500242bd99d4cb63fbd19 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 19:40:55 +0200 Subject: [PATCH 02/40] Update readme --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd421eb..5ae936a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* ## Overview -Mastodon is a free, open-source social network. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. Pick a server that you trust — whichever you choose, you can interact with everyone else. Anyone can run their own Mastodon instance and participate in the social network seamlessly. +Mastodon is a free, open-source social network. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. **Shipped version:** 3.1.2 diff --git a/README_fr.md b/README_fr.md index ea8fc4f..684d762 100644 --- a/README_fr.md +++ b/README_fr.md @@ -9,7 +9,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* ## Vue d'ensemble -Mastodon est un réseau social gratuit et open source. Une alternative décentralisée aux plates-formes commerciales, elle évite les risques d'une seule société qui monopolise votre communication. Choisissez un serveur sur lequel vous faites confiance - selon votre choix, vous pouvez interagir avec tous les autres. N'importe qui peut exécuter sa propre instance de Mastodon et participer au réseau social de façon transparente. +Mastodon est un réseau social gratuit et open source. Une alternative décentralisée aux plates-formes commerciales, elle évite les risques d'une seule société qui monopolise votre communication. **Version incluse:** 3.1.2 From 69fe6ac2e99f1247e11d797601ecd5f7f0abe04f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:09:24 +0200 Subject: [PATCH 03/40] spacing --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index f5e4602..0e62a0a 100644 --- a/check_process +++ b/check_process @@ -3,7 +3,7 @@ ; Manifest domain="domain.tld" (DOMAIN) admin="john" (USER) - language="fr_FR" + language="fr_FR" ; Checks pkg_linter=1 setup_sub_dir=0 From 123386436f2b02c779e403a750da6ef299032090 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:09:42 +0200 Subject: [PATCH 04/40] missing is_public --- check_process | 1 + 1 file changed, 1 insertion(+) diff --git a/check_process b/check_process index 0e62a0a..9d3b4bb 100644 --- a/check_process +++ b/check_process @@ -4,6 +4,7 @@ domain="domain.tld" (DOMAIN) admin="john" (USER) language="fr_FR" + is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 setup_sub_dir=0 From d83e11d8ac71c39dc33fc37f51aabb0baf57263f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:23:32 +0200 Subject: [PATCH 05/40] indentation --- manifest.json | 110 +++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/manifest.json b/manifest.json index 5925f8f..76b6a5c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,54 +1,54 @@ { - "name": "Mastodon", - "id": "mastodon", - "packaging_format": 1, - "description": { - "en": "A libre and federated social network.", - "fr": "Un réseau social libre et fédéré." - }, - "version": "3.1.2~ynh3", - "url": "https://github.com/tootsuite/mastodon", - "license": "AGPL-3.0-or-later", - "maintainer": [ - { - "name": "cyp", - "email": "cyp@rouquin.me" - }, - { - "name": "nemsia", - "email": "nemsia@nemsia.org" - }, - { - "name": "yalh76" - } - ], + "name": "Mastodon", + "id": "mastodon", + "packaging_format": 1, + "description": { + "en": "A libre and federated social network.", + "fr": "Un réseau social libre et fédéré." + }, + "version": "3.1.2~ynh3", + "url": "https://github.com/tootsuite/mastodon", + "license": "AGPL-3.0-or-later", + "maintainer": [ + { + "name": "cyp", + "email": "cyp@rouquin.me" + }, + { + "name": "nemsia", + "email": "nemsia@nemsia.org" + }, + { + "name": "yalh76" + } + ], "requirements": { "yunohost": ">= 3.7" }, "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain for Mastodon", - "fr": "Choisissez un domaine pour Mastodon" - }, + "services": [ + "nginx" + ], + "arguments": { + "install" : [ + { + "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" - }, + }, + { + "name": "admin", + "type": "user", + "ask": { + "en": "Choose an admin user", + "fr": "Choisissez l'administrateur" + }, "example": "johndoe" - }, + }, { "name": "is_public", "type": "boolean", @@ -58,16 +58,16 @@ }, "default": true }, - { - "name": "language", + { + "name": "language", "type": "string", - "ask": { - "en": "Choose the application language", - "fr": "Choisissez la langue de l'application" - }, - "choices": ["en_EN", "fr_FR"], - "default": "fr_FR" - } - ] - } + "ask": { + "en": "Choose the application language", + "fr": "Choisissez la langue de l'application" + }, + "choices": ["en_EN", "fr_FR"], + "default": "fr_FR" + } + ] + } } From 93f2e6201a0692f0665148b5d5776217f1c06ba7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:33:02 +0200 Subject: [PATCH 06/40] correct spacing --- check_process | 2 +- scripts/install | 18 +++++++++--------- scripts/upgrade | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/check_process b/check_process index 9d3b4bb..52ea6cb 100644 --- a/check_process +++ b/check_process @@ -2,7 +2,7 @@ auto_remove=1 ; Manifest domain="domain.tld" (DOMAIN) - admin="john" (USER) + admin="john" (USER) language="fr_FR" is_public=1 (PUBLIC|public=1|private=0) ; Checks diff --git a/scripts/install b/scripts/install index cb059ba..d3cc1ca 100644 --- a/scripts/install +++ b/scripts/install @@ -108,7 +108,7 @@ ynh_script_progression --message="Setting up source files..." --weight=5 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src mkdir $final_path -ynh_setup_source --dest_dir="$final_path/live" +ynh_setup_source --dest_dir="$final_path/live" # Temporary workaround for https://github.com/tootsuite/mastodon/issues/13292 ynh_replace_string --match_string="sidekiq-unique-jobs (6.0.18)" --replace_string="sidekiq-unique-jobs (6.0.20)" --target_file="$final_path/live/Gemfile.lock" @@ -167,10 +167,10 @@ ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/live/.env.production" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/live/.env.production" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" language="$(echo $language | head -c 2)" -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="${final_path}/live/.env.production" @@ -208,8 +208,8 @@ ynh_secure_remove --file="$final_path/live/acc.txt" vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") -ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file="${final_path}/live/.env.production" -ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="${final_path}/live/.env.production" ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private_key" ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key" @@ -222,7 +222,7 @@ ynh_secure_remove --file="$final_path/live/key.txt" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" +ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= @@ -231,11 +231,11 @@ sudo cp -f ../conf/cron /etc/cron.d/$app ynh_script_progression --message="Configuring a systemd service..." --weight=5 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" +ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" +ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 153437b..88947cf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -180,7 +180,7 @@ then mkdir $tmpdir/system if [ -d "$final_path/live/public/system" ]; then rsync -a "$final_path/live/public/system" "$tmpdir/." - fi + fi rsync -a "$final_path/live/.env.production" "$tmpdir/." ynh_secure_remove --file="$final_path/live" ynh_setup_source --dest_dir="$final_path/live" @@ -262,10 +262,10 @@ ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/live/.env.production" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/live/.env.production" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" language="$(echo $language | head -c 2)" -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="${final_path}/live/.env.production" @@ -273,8 +273,8 @@ ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secre ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$final_path/live/.env.production" -ynh_replace_string "__VAPID_PRIVATE_KEY__" "$vapid_private_key" "$final_path/live/.env.production" -ynh_replace_string "__VAPID_PUBLIC_KEY__" "$vapid_public_key" "$final_path/live/.env.production" +ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file"$final_path/live/.env.production" +ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$final_path/live/.env.production" #================================================= # UPGRADE MASTODON @@ -301,8 +301,8 @@ popd # ynh_app_setting_set "$app" vapid_private_key "$vapid_private_key" # ynh_app_setting_set "$app" vapid_public_key "$vapid_public_key" # ynh_secure_remove "$final_path/live/key.txt" -# ynh_replace_string "__VAPID_PRIVATE_KEY__" "$vapid_private_key" "${final_path}/live/.env.production" -# ynh_replace_string "__VAPID_PUBLIC_KEY__" "$vapid_public_key" "${final_path}/live/.env.production" +# ynh_replace_string "__VAPID_PRIVATE_KEY__" "$vapid_private_key" "${final_path}/live/.env.production" +# ynh_replace_string "__VAPID_PUBLIC_KEY__" "$vapid_public_key" "${final_path}/live/.env.production" #fi # Recalculate and store the checksum of the file for the next upgrade. @@ -314,7 +314,7 @@ ynh_store_file_checksum --file="${final_path}/live/.env.production" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" +ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" sudo cp -f ../conf/cron /etc/cron.d/$app #================================================= @@ -323,11 +323,11 @@ sudo cp -f ../conf/cron /etc/cron.d/$app ynh_script_progression --message="Upgrading systemd configuration..." --weight=13 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" +ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" +ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" #================================================= From 0e27aab64a45ecdae0ce2b4500e81f72f28f9293 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:33:31 +0200 Subject: [PATCH 07/40] remove not needed code --- scripts/upgrade | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 88947cf..1c78242 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -293,18 +293,6 @@ pushd "$final_path/live" sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl cache clear popd -# If vapid_private_key doesn't exist, retrieve it or create it -#if [[ -z "$vapid_private_key" ]]; then -# sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.0/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt -# vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") -# vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") -# ynh_app_setting_set "$app" vapid_private_key "$vapid_private_key" -# ynh_app_setting_set "$app" vapid_public_key "$vapid_public_key" -# ynh_secure_remove "$final_path/live/key.txt" -# ynh_replace_string "__VAPID_PRIVATE_KEY__" "$vapid_private_key" "${final_path}/live/.env.production" -# ynh_replace_string "__VAPID_PUBLIC_KEY__" "$vapid_public_key" "${final_path}/live/.env.production" -#fi - # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="${final_path}/live/.env.production" From 36ff48ac1d930f235217d5758f6bd33bac039cc5 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 18 May 2020 22:38:55 +0200 Subject: [PATCH 08/40] config filename factorisation --- scripts/install | 29 +++++++++++++++-------------- scripts/upgrade | 44 +++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/scripts/install b/scripts/install index d3cc1ca..409911b 100644 --- a/scripts/install +++ b/scripts/install @@ -162,26 +162,27 @@ ynh_install_ruby --ruby_version=2.6.5 #================================================= ynh_script_progression --message="Modifying a config file..." --weight=2 -cp -f ../conf/.env.production.sample "$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" +config="$final_path/live/.env.production" +cp -f ../conf/.env.production.sample "$config" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$config" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" +ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="$config" language="$(echo $language | head -c 2)" -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$config" paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="$config" ynh_app_setting_set --app="$app" --key=paperclip_secret --value="$paperclip_secret" secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secret_key_base" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secret_key_base" --target_file="$config" ynh_app_setting_set --app="$app" --key=secret_key_base --value="$secret_key_base" otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) -ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$config" ynh_app_setting_set --app="$app" --key=otp_secret --value="$otp_secret" #================================================= @@ -195,7 +196,7 @@ pushd "$final_path/live" ynh_use_nodejs sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.5/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile - sudo -u "$app" echo "SAFETY_ASSURED=1">> .env.production + sudo -u "$app" echo "SAFETY_ASSURED=1">> $config sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails db:setup --quiet sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails assets:precompile --quiet sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt @@ -208,8 +209,8 @@ ynh_secure_remove --file="$final_path/live/acc.txt" vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") -ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file="${final_path}/live/.env.production" -ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file="$config" +ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$config" ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private_key" ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key" @@ -244,7 +245,7 @@ ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming ynh_script_progression --message="Storing the config file checksum..." --weight=1 # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="${final_path}/live/.env.production" +ynh_store_file_checksum --file="$config" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 1c78242..98d0403 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -51,6 +51,8 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +config="$final_path/live/.env.production" + # If db_name doesn't exist, create it if [ -z "$db_name" ]; then db_name="${app}_production" @@ -87,12 +89,12 @@ if [[ -z "$db_pwd" ]]; then ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd ynh_psql_test_if_first_run sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres - ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="${final_path}/live/.env.production" + ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config" fi # If paperclip_secret doesn't exist, retrieve it or create it if [[ -z "$paperclip_secret" ]]; then - paperclip_secret=$(grep -oP "PAPERCLIP_SECRET=\K\w+" ${final_path}/live/.env.production) + paperclip_secret=$(grep -oP "PAPERCLIP_SECRET=\K\w+" $config) if [[ -z "$paperclip_secret" ]]; then paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi @@ -101,7 +103,7 @@ fi # If secret_key_base doesn't exist, retrieve it or create it if [[ -z "$secret_key_base" ]]; then - secret_key_base=$(grep -oP "SECRET_KEY_BASE=\K\w+" ${final_path}/live/.env.production) + secret_key_base=$(grep -oP "SECRET_KEY_BASE=\K\w+" $config) if [[ -z "$secret_key_base" ]]; then secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi @@ -110,7 +112,7 @@ fi # If otp_secret doesn't exist, retrieve it or create it if [[ -z "$otp_secret" ]]; then - otp_secret=$(grep -oP "OTP_SECRET=\K\w+" ${final_path}/live/.env.production) + otp_secret=$(grep -oP "OTP_SECRET=\K\w+" $config) if [[ -z "$otp_secret" ]]; then otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi @@ -119,8 +121,8 @@ fi # If vapid_private_key doesn't exist, retrieve it or create it if [[ -z "$vapid_private_key" ]]; then - vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" ${final_path}/live/.env.production) - vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" ${final_path}/live/.env.production) + vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" $config) + vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" $config) ynh_app_setting_set "$app" vapid_private_key "$vapid_private_key" ynh_app_setting_set "$app" vapid_public_key "$vapid_public_key" fi @@ -181,7 +183,7 @@ then if [ -d "$final_path/live/public/system" ]; then rsync -a "$final_path/live/public/system" "$tmpdir/." fi - rsync -a "$final_path/live/.env.production" "$tmpdir/." + rsync -a "$config" "$tmpdir/." ynh_secure_remove --file="$final_path/live" ynh_setup_source --dest_dir="$final_path/live" @@ -256,25 +258,25 @@ ynh_install_ruby --ruby_version=2.6.5 #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -ynh_backup_if_checksum_is_different --file="$final_path/live/.env.production" -cp -f ../conf/.env.production.sample "$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/live/.env.production" -ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="${final_path}/live/.env.production" +ynh_backup_if_checksum_is_different --file="$config" +cp -f ../conf/.env.production.sample "$config" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$config" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" +ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" +ynh_replace_string --match_string="__SMTP_FROM_ADDRESS__" --replace_string="$admin_mail" --target_file="$config" language="$(echo $language | head -c 2)" -ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$config" -ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="${final_path}/live/.env.production" +ynh_replace_string --match_string="PAPERCLIP_SECRET=" --replace_string="PAPERCLIP_SECRET=$paperclip_secret" --target_file="$config" -ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secret_key_base" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secret_key_base" --target_file="$config" -ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$config" -ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file"$final_path/live/.env.production" -ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$final_path/live/.env.production" +ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file"$config" +ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$config" #================================================= # UPGRADE MASTODON @@ -294,7 +296,7 @@ pushd "$final_path/live" popd # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="${final_path}/live/.env.production" +ynh_store_file_checksum --file="$config" #================================================= # SETUP CRON JOB FOR REMOVING CACHE From 736d7908b4f31095e7a7b92fc632b0f6fad05e83 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 01:20:45 +0200 Subject: [PATCH 09/40] RUBY_VERSION factorisation --- conf/cron | 2 +- conf/mastodon-sidekiq.service | 2 +- conf/mastodon-web.service | 2 +- scripts/_common.sh | 2 ++ scripts/install | 28 +++++++++++++++++----------- scripts/restore | 8 +++++--- scripts/upgrade | 25 +++++++++++++++---------- 7 files changed, 42 insertions(+), 27 deletions(-) diff --git a/conf/cron b/conf/cron index 9a984a3..8bf7bdb 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,2 @@ RAILS_ENV=production -@daily cd __FINAL__PATH__/live && /opt/rbenv/versions/2.6.5/bin/bundle exec rake __USER__:media:remove_remote +@daily cd __FINAL__PATH__/live && __RBENVROOT__/shims/bundle exec rake __USER__:media:remove_remote diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index d5fc7e1..73f29e5 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -9,7 +9,7 @@ Environment="RAILS_ENV=production" Environment="DB_POOL=25" Environment="MALLOC_ARENA_MAX=2" - ExecStart=/opt/rbenv/versions/2.6.5/bin/bundle exec sidekiq -c 25 + ExecStart=__RBENVROOT__/shims/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index bb65afe..14d1260 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -8,7 +8,7 @@ WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" Environment="PORT=__PORT_WEB__" - ExecStart=/opt/rbenv/versions/2.6.5/bin/bundle exec puma -C config/puma.rb + ExecStart=__RBENVROOT__/shims/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always diff --git a/scripts/_common.sh b/scripts/_common.sh index 015c1e9..f39b966 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,8 @@ # dependencies used by the app pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core g++ libprotobuf-dev protobuf-compiler pkg-config gcc autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3|libgdbm6 libgdbm-dev redis-server redis-tools postgresql postgresql-contrib libidn11-dev libicu-dev libjemalloc-dev curl apt-transport-https" +RUBY_VERSION="2.6.5" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 409911b..2e218c6 100644 --- a/scripts/install +++ b/scripts/install @@ -20,6 +20,7 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Managing script failure..." --weight=1 ynh_clean_setup () { + read -p "key" ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -153,9 +154,11 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Installing Ruby..." --weight=424 -ynh_install_ruby --ruby_version=2.6.5 -/opt/rbenv/versions/2.6.5/bin/gem update --system -/opt/rbenv/versions/2.6.5/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION +pushd "$final_path/live" + gem update --system + gem install bundler:1.17.3 --no-document +popd #================================================= # MODIFY A CONFIG FILE @@ -194,13 +197,13 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.5/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test - sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile - sudo -u "$app" echo "SAFETY_ASSURED=1">> $config - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails db:setup --quiet - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails assets:precompile --quiet - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt + bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + yarn install --pure-lockfile + echo "SAFETY_ASSURED=1">> $config + RAILS_ENV=production bundle exec rails db:setup --quiet + RAILS_ENV=production bundle exec rails assets:precompile --quiet + RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key > key.txt + RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt popd admin_pass=$( tail -1 $final_path/live/acc.txt | head -1 | cut -c 15- ) @@ -224,7 +227,8 @@ ynh_script_progression --message="Setuping a cron job for removing cache..." --w ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -sudo cp -f ../conf/cron /etc/cron.d/$app +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" +cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SYSTEMD @@ -233,6 +237,8 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=5 # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" diff --git a/scripts/restore b/scripts/restore index c6e4bc8..bd79e95 100644 --- a/scripts/restore +++ b/scripts/restore @@ -114,9 +114,11 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= ynh_script_progression --message="Installing Ruby..." --weight=393 -ynh_install_ruby --ruby_version=2.6.5 -/opt/rbenv/versions/2.6.5/bin/gem update --system -/opt/rbenv/versions/2.6.5/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION +pushd "$final_path/live" + gem update --system + gem install bundler:1.17.3 --no-document +popd #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 98d0403..f34010b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -249,9 +249,11 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Installing Ruby..." --weight=424 -ynh_install_ruby --ruby_version=2.6.5 -/opt/rbenv/versions/2.6.5/bin/gem update --system -/opt/rbenv/versions/2.6.5/bin/gem install bundler:1.17.3 --no-document +ynh_install_ruby --ruby_version=$RUBY_VERSION +pushd "$final_path/live" + gem update --system + gem install bundler:1.17.3 --no-document +popd #================================================= # MODIFY A CONFIG FILE @@ -287,12 +289,12 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - sudo -u "$app" env PATH=$PATH /opt/rbenv/versions/2.6.5/bin/bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test - sudo -u "$app" env PATH=$PATH yarn install --pure-lockfile - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails assets:clean - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails assets:precompile - sudo -u "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/2.6.5/bin/bundle exec rails db:migrate - sudo -u "$app" env PATH=$PATH RAILS_ENV=production bin/tootctl cache clear + bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + yarn install --pure-lockfile + RAILS_ENV=production bundle exec rails assets:clean + RAILS_ENV=production bundle exec rails assets:precompile + RAILS_ENV=production bundle exec rails db:migrate + RAILS_ENV=production bin/tootctl cache clear popd # Recalculate and store the checksum of the file for the next upgrade. @@ -305,7 +307,8 @@ ynh_script_progression --message="Setuping a cron job for removing cache..." --w ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -sudo cp -f ../conf/cron /etc/cron.d/$app +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" +cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SYSTEMD @@ -314,6 +317,8 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" +ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" From b5556ae674f1ca35da8f5e1d5a8a8ce4e69bc580 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 01:24:16 +0200 Subject: [PATCH 10/40] BUNDLER_VERSION factorization --- scripts/_common.sh | 2 ++ scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f39b966..bb0fe95 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,6 +9,8 @@ pkg_dependencies="imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git RUBY_VERSION="2.6.5" +BUNDLER_VERSION="1.17.3" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 2e218c6..ab3aaa9 100644 --- a/scripts/install +++ b/scripts/install @@ -157,7 +157,7 @@ ynh_script_progression --message="Installing Ruby..." --weight=424 ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" gem update --system - gem install bundler:1.17.3 --no-document + gem install bundler:$BUNDLER_VERSION --no-document popd #================================================= diff --git a/scripts/restore b/scripts/restore index bd79e95..724afc3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -117,7 +117,7 @@ ynh_script_progression --message="Installing Ruby..." --weight=393 ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" gem update --system - gem install bundler:1.17.3 --no-document + gem install bundler:$BUNDLER_VERSION --no-document popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f34010b..149c2f5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -252,7 +252,7 @@ ynh_script_progression --message="Installing Ruby..." --weight=424 ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" gem update --system - gem install bundler:1.17.3 --no-document + gem install bundler:$BUNDLER_VERSION --no-document popd #================================================= From ff8fbd3fd06a0a87272e751bf3011d730dbfffc0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 01:31:51 +0200 Subject: [PATCH 11/40] disable registrations and invitations --- scripts/install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install b/scripts/install index ab3aaa9..c5e5775 100644 --- a/scripts/install +++ b/scripts/install @@ -188,6 +188,9 @@ otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$config" ynh_app_setting_set --app="$app" --key=otp_secret --value="$otp_secret" +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" + #================================================= # INSTALLING MASTODON #================================================= From 2396f84cdb7c8105037df6a45b857a0d28ed0804 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 01:39:19 +0200 Subject: [PATCH 12/40] Update install --- scripts/install | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install b/scripts/install index c5e5775..c359dfd 100644 --- a/scripts/install +++ b/scripts/install @@ -20,7 +20,6 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Managing script failure..." --weight=1 ynh_clean_setup () { - read -p "key" ynh_clean_check_starting } # Exit if an error occurs during the execution of the script From 4aafbbb86cd9110adce6506b93ba17463578c308 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 13:22:00 +0200 Subject: [PATCH 13/40] missing = :/ --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 149c2f5..7d747e0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -277,7 +277,7 @@ ynh_replace_string --match_string="__SECRET_KEY_BASE__" --replace_string="$secre ynh_replace_string --match_string="__OTP_SECRET__" --replace_string="$otp_secret" --target_file="$config" -ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file"$config" +ynh_replace_string --match_string="__VAPID_PRIVATE_KEY__" --replace_string="$vapid_private_key" --target_file="$config" ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$config" #================================================= From f4487bb3df27286b811579116af4decb8bd29fea Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 13:25:24 +0200 Subject: [PATCH 14/40] fix bundle install --- scripts/install | 4 +++- scripts/upgrade | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index c359dfd..f6a1411 100644 --- a/scripts/install +++ b/scripts/install @@ -199,7 +199,9 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + bundle config deployment 'true' + bundle config without 'development test' + bundle install -j$(getconf _NPROCESSORS_ONLN) yarn install --pure-lockfile echo "SAFETY_ASSURED=1">> $config RAILS_ENV=production bundle exec rails db:setup --quiet diff --git a/scripts/upgrade b/scripts/upgrade index 7d747e0..ee97cde 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -289,7 +289,9 @@ chown -R "$app": "$final_path" pushd "$final_path/live" ynh_use_nodejs - bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test + bundle config deployment 'true' + bundle config without 'development test' + bundle install -j$(getconf _NPROCESSORS_ONLN) yarn install --pure-lockfile RAILS_ENV=production bundle exec rails assets:clean RAILS_ENV=production bundle exec rails assets:precompile From d6ad96999ea61b292d212ebc00f0d1ef2eecff72 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 18:36:29 +0200 Subject: [PATCH 15/40] remove ynh_send_readme_to_admin__2 --- scripts/install | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install b/scripts/install index f6a1411..510701f 100644 --- a/scripts/install +++ b/scripts/install @@ -9,7 +9,6 @@ source _common.sh source ynh_install_ruby__2 source ynh_add_extra_apt_repos__3 -source ynh_send_readme_to_admin__2 source ynh_add_swap source ynh_check_ram source /usr/share/yunohost/helpers From aac5dadc34f4810b852f1836576272eb52e115a1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 18:44:16 +0200 Subject: [PATCH 16/40] $NODEJS_VERSION factorisation --- scripts/_common.sh | 2 ++ scripts/install | 2 +- scripts/upgrade | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index bb0fe95..0c5fb0e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,6 +11,8 @@ RUBY_VERSION="2.6.5" BUNDLER_VERSION="1.17.3" +NODEJS_VERSION="10" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 510701f..8f4f223 100644 --- a/scripts/install +++ b/scripts/install @@ -80,7 +80,7 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream #================================================= ynh_script_progression --message="Installing dependencies..." --weight=86 -ynh_install_nodejs --nodejs_version="10" +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" diff --git a/scripts/upgrade b/scripts/upgrade index ee97cde..da0e7bb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -213,7 +213,7 @@ ynh_add_nginx_config 'port_web port_stream' ynh_script_progression --message="Upgrading dependencies..." --weight=24 ynh_remove_nodejs -ynh_install_nodejs --nodejs_version="10" +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" From 2eb6680a727a36ac5bcb179d20eec5c6a4c871d3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 18:58:25 +0200 Subject: [PATCH 17/40] Update restore --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 724afc3..5a349d4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -105,7 +105,7 @@ ynh_add_swap --size=$swap_needed #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=63 -ynh_install_nodejs --nodejs_version="10" +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" From c309a117e7eacc2bdaaa8057ddf4411fc6bd9bd9 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 19:19:02 +0200 Subject: [PATCH 18/40] fix admin account approval --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index 8f4f223..1f1a11f 100644 --- a/scripts/install +++ b/scripts/install @@ -207,6 +207,7 @@ pushd "$final_path/live" RAILS_ENV=production bundle exec rails assets:precompile --quiet RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key > key.txt RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt + RAILS_ENV=production bin/tootctl accounts modify "$admin" --approve popd admin_pass=$( tail -1 $final_path/live/acc.txt | head -1 | cut -c 15- ) From 5f421f48d7fb69b8c8adafad48b93bbb621c6dce Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 19:20:06 +0200 Subject: [PATCH 19/40] Fix CRON --- conf/cron | 2 +- scripts/install | 2 -- scripts/upgrade | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/conf/cron b/conf/cron index 8bf7bdb..af98c3c 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,2 @@ RAILS_ENV=production -@daily cd __FINAL__PATH__/live && __RBENVROOT__/shims/bundle exec rake __USER__:media:remove_remote +@daily cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove diff --git a/scripts/install b/scripts/install index 1f1a11f..32cb94e 100644 --- a/scripts/install +++ b/scripts/install @@ -230,8 +230,6 @@ ynh_secure_remove --file="$final_path/live/key.txt" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index da0e7bb..0a19125 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -308,8 +308,6 @@ ynh_store_file_checksum --file="$config" ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app #================================================= From bf0fef631f39616ed455cc9face32cacdda16172 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 19:24:47 +0200 Subject: [PATCH 20/40] remove not needed retrieving admin generated password --- scripts/install | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 32cb94e..8b36e56 100644 --- a/scripts/install +++ b/scripts/install @@ -206,13 +206,10 @@ pushd "$final_path/live" RAILS_ENV=production bundle exec rails db:setup --quiet RAILS_ENV=production bundle exec rails assets:precompile --quiet RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key > key.txt - RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > acc.txt + RAILS_ENV=production bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=admin > /dev/null RAILS_ENV=production bin/tootctl accounts modify "$admin" --approve popd -admin_pass=$( tail -1 $final_path/live/acc.txt | head -1 | cut -c 15- ) -ynh_secure_remove --file="$final_path/live/acc.txt" - vapid_private_key=$(grep -oP "VAPID_PRIVATE_KEY=\K.+" "$final_path/live/key.txt") vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt") From 477d3adf08699435883ff2c7c7fee50123bfbdc7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 19:51:05 +0200 Subject: [PATCH 21/40] increase version number --- check_process | 2 ++ manifest.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/check_process b/check_process index 52ea6cb..12c74c8 100644 --- a/check_process +++ b/check_process @@ -15,6 +15,8 @@ upgrade=1 # 3.1.2~ynh2 upgrade=1 from_commit=7e1f4c2dee5f2c8374686aea62f4648cdf2722c3 + # 3.1.2~ynh3 + upgrade=1 from_commit=6b30109fc986d83166b1805ec3ad7e28200e3743 backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. diff --git a/manifest.json b/manifest.json index 76b6a5c..12f7789 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A libre and federated social network.", "fr": "Un réseau social libre et fédéré." }, - "version": "3.1.2~ynh3", + "version": "3.1.2~ynh4", "url": "https://github.com/tootsuite/mastodon", "license": "AGPL-3.0-or-later", "maintainer": [ From c2f6661420069146b6ca6777b4acedd827863bf1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 20:26:36 +0200 Subject: [PATCH 22/40] increase nodejs version --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 0c5fb0e..e0686b2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,7 +11,7 @@ RUBY_VERSION="2.6.5" BUNDLER_VERSION="1.17.3" -NODEJS_VERSION="10" +NODEJS_VERSION="12" #================================================= # PERSONAL HELPERS From 1977f0fff725ff589618fffc18e861b264f46891 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 19 May 2020 23:57:16 +0200 Subject: [PATCH 23/40] Imrpove cron --- conf/cron | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conf/cron b/conf/cron index af98c3c..1296c1b 100644 --- a/conf/cron +++ b/conf/cron @@ -1,2 +1,4 @@ -RAILS_ENV=production @daily cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove-orphans +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl accounts cull +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl status remove From b4dc3908d08cb1767dbe729ea2cc8956369359c3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 22 May 2020 03:12:41 +0200 Subject: [PATCH 24/40] add tootctl preview_cards remove --- conf/cron | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/cron b/conf/cron index 1296c1b..f3cae63 100644 --- a/conf/cron +++ b/conf/cron @@ -2,3 +2,4 @@ @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove-orphans @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl accounts cull @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl status remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl preview_cards remove From 29c9a33cdb9f11f14083bebaa519bf7a6f762cfc Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 22 May 2020 03:16:41 +0200 Subject: [PATCH 25/40] fix tootctl statuses remove --- conf/cron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/cron b/conf/cron index f3cae63..776808b 100644 --- a/conf/cron +++ b/conf/cron @@ -1,5 +1,5 @@ @daily cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl media remove-orphans @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl accounts cull -@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl status remove +@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl statuses remove @monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl preview_cards remove From f7e0cfd553116619409035037643441b1da0be85 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 12:23:48 +0200 Subject: [PATCH 26/40] moving to 3.8 new helper --- manifest.json | 2 +- scripts/install | 1 - scripts/remove | 1 - scripts/restore | 1 - scripts/upgrade | 1 - scripts/ynh_add_extra_apt_repos__3 | 294 ----------------------------- 6 files changed, 1 insertion(+), 299 deletions(-) delete mode 100644 scripts/ynh_add_extra_apt_repos__3 diff --git a/manifest.json b/manifest.json index 12f7789..b54d843 100644 --- a/manifest.json +++ b/manifest.json @@ -23,7 +23,7 @@ } ], "requirements": { - "yunohost": ">= 3.7" + "yunohost": ">= 3.8" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index 8b36e56..388b2a3 100644 --- a/scripts/install +++ b/scripts/install @@ -8,7 +8,6 @@ source _common.sh source ynh_install_ruby__2 -source ynh_add_extra_apt_repos__3 source ynh_add_swap source ynh_check_ram source /usr/share/yunohost/helpers diff --git a/scripts/remove b/scripts/remove index f2b2e16..d955a8a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ source _common.sh source ynh_install_ruby__2 -source ynh_add_extra_apt_repos__3 source ynh_add_swap source /usr/share/yunohost/helpers diff --git a/scripts/restore b/scripts/restore index 5a349d4..dbcd5cb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -9,7 +9,6 @@ #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_extra_apt_repos__3 source ../settings/scripts/ynh_add_swap source ../settings/scripts/ynh_check_ram source /usr/share/yunohost/helpers diff --git a/scripts/upgrade b/scripts/upgrade index 0a19125..c5be012 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,7 +8,6 @@ source _common.sh source ynh_install_ruby__2 -source ynh_add_extra_apt_repos__3 source ynh_add_swap source ynh_check_ram source /usr/share/yunohost/helpers diff --git a/scripts/ynh_add_extra_apt_repos__3 b/scripts/ynh_add_extra_apt_repos__3 deleted file mode 100644 index 3276f00..0000000 --- a/scripts/ynh_add_extra_apt_repos__3 +++ /dev/null @@ -1,294 +0,0 @@ -#!/bin/bash - -# Pin a repository. -# -# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] -# | arg: -p, --package - Packages concerned by the pin. Or all, *. -# | arg: -i, --pin - Filter for the pin. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. -# -ynh_pin_repo () { - # Declare an array to define the options of this helper. - local legacy_args=pirna - declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) - local package - local pin - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package="${package:-*}" - priority=${priority:-50} - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/preferences.d" - echo "Package: $package -Pin: $pin -Pin-Priority: $priority" \ - | $append "/etc/apt/preferences.d/$name" -} - -# Add a repository. -# -# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] -# | arg: -u, --uri - Uri of the repository. -# | arg: -s, --suite - Suite of the repository. -# | arg: -c, --component - Component of the repository. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable -# uri suite component -# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable -# -ynh_add_repo () { - # Declare an array to define the options of this helper. - local legacy_args=uscna - declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) - local uri - local suite - local component - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/sources.list.d" - # Add the new repo in sources.list.d - echo "deb $uri $suite $component" \ - | $append "/etc/apt/sources.list.d/$name.list" -} - -# Add an extra repository correctly, pin it and get the key. -# -# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -k, --key - url to get the public key. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -ynh_install_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=rkpna - declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) - local repo - local key - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-0} - priority=${priority:-} - - if [ $append -eq 1 ] - then - append="--append" - wget_append="tee -a" - else - append="" - wget_append="tee" - fi - - # Split the repository into uri, suite and components. - # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" - - # Get the components - local component="${repo##$uri $suite }" - - # Add the repository into sources.list.d - ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append - - # Pin the new repo with the default priority, so it won't be used for upgrades. - # Build $pin from the uri without http and any sub path - local pin="${uri#*://}" - pin="${pin%%/*}" - # Set a priority only if asked - if [ -n "$priority" ] - then - priority="--priority=$priority" - fi - ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append - - # Get the public key for the repo - if [ -n "$key" ] - then - mkdir -p "/etc/apt/trusted.gpg.d" - wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null - fi - - # Update the list of package with the new repo - ynh_package_update -} - -# Remove an extra repository and the assiociated configuration. -# -# usage: ynh_remove_extra_repo [--name=name] -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_remove_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=n - declare -Ar args_array=( [n]=name= ) - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - - ynh_secure_remove "/etc/apt/sources.list.d/$name.list" - ynh_secure_remove "/etc/apt/preferences.d/$name" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" - - # Update the list of package to exclude the old repo - ynh_package_update -} - -# Install packages from an extra repository properly. -# -# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -p, --package - The packages to install from this extra repository -# | arg: -k, --key - url to get the public key. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_install_extra_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=rpkn - declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) - local repo - local package - local key - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - key=${key:-0} - - # Set a key only if asked - if [ -n "$key" ] - then - key="--key=$key" - fi - # Add an extra repository for those packages - ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name - - # Install requested dependencies from this extra repository. - ynh_add_app_dependencies --package="$package" - - # Remove this extra repository after packages are installed - ynh_remove_extra_repo --name=$app -} - -#================================================= - -# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies - -# Define and install dependencies with a equivs control file -# This helper can/should only be called once per app -# -# usage: ynh_install_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence -# You can give a choice between some package with this syntax : "dep1|dep2" -# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" -# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) -# -# Requires YunoHost version 2.6.4 or higher. -ynh_install_app_dependencies () { - local dependencies=$@ - dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" - dependencies=${dependencies//|/ | } - local manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - - local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. - if [ ${#version} -eq 0 ]; then - version="1.0" - fi - local dep_app=${app//_/-} # Replace all '_' by '-' - - # Handle specific versions - if [[ "$dependencies" =~ [\<=\>] ]] - then - # Replace version specifications by relationships syntax - # https://www.debian.org/doc/debian-policy/ch-relationships.html - # Sed clarification - # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. - # [\<=\>] matches < = or > - # \+ matches one or more occurence of the previous characters, for >= or >>. - # [^,]\+ matches all characters except ',' - # Ex: package>=1.0 will be replaced by package (>= 1.0) - dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" - fi - - cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies} -Architecture: all -Description: Fake package for $app (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ - || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies - rm /tmp/${dep_app}-ynh-deps.control - ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" -} - -ynh_add_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=pr - declare -Ar args_array=( [p]=package= [r]=replace) - local package - local replace - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - replace=${replace:-0} - - local current_dependencies="" - if [ $replace -eq 0 ] - then - local dep_app=${app//_/-} # Replace all '_' by '-' - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then - current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " - fi - - current_dependencies=${current_dependencies// | /|} - fi - - ynh_install_app_dependencies "${current_dependencies}${package}" -} From 3d713af143776d074d2f37cb0689d777aa632fdf Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:18:02 +0200 Subject: [PATCH 27/40] Moving from ynh_check_ram to ynh_get_ram --- manifest.json | 2 +- scripts/install | 6 ++-- scripts/restore | 4 +-- scripts/upgrade | 4 +-- scripts/ynh_check_ram | 72 ------------------------------------------- 5 files changed, 5 insertions(+), 83 deletions(-) delete mode 100644 scripts/ynh_check_ram diff --git a/manifest.json b/manifest.json index b54d843..9041ab7 100644 --- a/manifest.json +++ b/manifest.json @@ -23,7 +23,7 @@ } ], "requirements": { - "yunohost": ">= 3.8" + "yunohost": ">= 3.8.1" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index 388b2a3..97dee20 100644 --- a/scripts/install +++ b/scripts/install @@ -9,7 +9,6 @@ source _common.sh source ynh_install_ruby__2 source ynh_add_swap -source ynh_check_ram source /usr/share/yunohost/helpers #================================================= @@ -134,12 +133,11 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= ynh_script_progression --message="Adding swap is needed..." --weight=4 -total_memory=$(ynh_check_ram) -total_swap=$(ynh_check_ram --only_swap) +total_memory=$(ynh_get_ram --total) swap_needed=0 if [ $total_memory -lt 2560 ]; then - # Need a minimum of 8Go of memory + # Need a minimum of 2.5Go of memory swap_needed=$((2560 - $total_memory)) fi diff --git a/scripts/restore b/scripts/restore index dbcd5cb..ed0b27d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,7 +10,6 @@ source ../settings/scripts/_common.sh source ../settings/scripts/ynh_install_ruby__2 source ../settings/scripts/ynh_add_swap -source ../settings/scripts/ynh_check_ram source /usr/share/yunohost/helpers #================================================= @@ -87,8 +86,7 @@ chown -R $app: $final_path #================================================= ynh_script_progression --message="Adding swap if needed..." --weight=4 -total_memory=$(ynh_check_ram) -total_swap=$(ynh_check_ram --only_swap) +total_memory=$(ynh_get_ram --total) swap_needed=0 if [ $total_memory -lt 2560 ]; then diff --git a/scripts/upgrade b/scripts/upgrade index c5be012..9e02c01 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,7 +9,6 @@ source _common.sh source ynh_install_ruby__2 source ynh_add_swap -source ynh_check_ram source /usr/share/yunohost/helpers #================================================= @@ -231,8 +230,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= ynh_script_progression --message="Adding swap if needed..." --weight=7 -total_memory=$(ynh_check_ram) -total_swap=$(ynh_check_ram --only_swap) +total_memory=$(ynh_get_ram --total) swap_needed=0 if [ $total_memory -lt 2560 ]; then diff --git a/scripts/ynh_check_ram b/scripts/ynh_check_ram deleted file mode 100644 index 11012a3..0000000 --- a/scripts/ynh_check_ram +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash - -# Check the amount of available RAM -# -# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram] -# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise. -# If --required isn't set, the helper will print the amount of RAM, in Mb. -# | arg: -s, --no_swap - Ignore swap -# | arg: -o, --only_swap - Ignore real RAM, consider only swap. -# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available. -ynh_check_ram () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram ) - local required - local no_swap - local only_swap - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - required=${required:-} - no_swap=${no_swap:-0} - only_swap=${only_swap:-0} - - local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}') - local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}') - local total_ram_swap=$(( total_ram + total_swap )) - - local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}') - local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}') - local free_ram_swap=$(( free_ram + free_swap )) - - # Use the total amount of ram - local ram=$total_ram_swap - if [ $free_ram -eq 1 ] - then - # Use the total amount of free ram - ram=$free_ram_swap - if [ $no_swap -eq 1 ] - then - # Use only the amount of free ram - ram=$free_ram - elif [ $only_swap -eq 1 ] - then - # Use only the amount of free swap - ram=$free_swap - fi - else - if [ $no_swap -eq 1 ] - then - # Use only the amount of free ram - ram=$total_ram - elif [ $only_swap -eq 1 ] - then - # Use only the amount of free swap - ram=$total_swap - fi - fi - - if [ -n "$required" ] - then - # Return 1 if the amount of ram isn't enough. - if [ $ram -lt $required ] - then - return 1 - else - return 0 - fi - - # If no RAM is required, return the amount of available ram. - else - echo $ram - fi -} From 9c47591da2ba69b548382ac324702217733b1ec9 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:18:15 +0200 Subject: [PATCH 28/40] Adding commit name --- check_process | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/check_process b/check_process index 12c74c8..6050dcd 100644 --- a/check_process +++ b/check_process @@ -29,3 +29,8 @@ ;;; Options Email=yalh@yahoo.com Notification=all +;;; Upgrade options + ; commit=7e1f4c2dee5f2c8374686aea62f4648cdf2722c3 + name=3.1.2~ynh2 + ; commit=6b30109fc986d83166b1805ec3ad7e28200e3743 + name=3.1.2~ynh3 From f2051e67a3a7ee03254677434a35209beff2225b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:19:50 +0200 Subject: [PATCH 29/40] $MEMORY_NEEDED factorisation --- scripts/_common.sh | 2 ++ scripts/install | 4 ++-- scripts/restore | 4 ++-- scripts/upgrade | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index e0686b2..dc466ba 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -13,6 +13,8 @@ BUNDLER_VERSION="1.17.3" NODEJS_VERSION="12" +MEMORY_NEEDED="2560" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 97dee20..8c63cde 100644 --- a/scripts/install +++ b/scripts/install @@ -136,9 +136,9 @@ ynh_script_progression --message="Adding swap is needed..." --weight=4 total_memory=$(ynh_get_ram --total) swap_needed=0 -if [ $total_memory -lt 2560 ]; then +if [ $total_memory -lt $MEMORY_NEEDED ]; then # Need a minimum of 2.5Go of memory - swap_needed=$((2560 - $total_memory)) + swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 diff --git a/scripts/restore b/scripts/restore index ed0b27d..ae64eaf 100644 --- a/scripts/restore +++ b/scripts/restore @@ -89,9 +89,9 @@ ynh_script_progression --message="Adding swap if needed..." --weight=4 total_memory=$(ynh_get_ram --total) swap_needed=0 -if [ $total_memory -lt 2560 ]; then +if [ $total_memory -lt $MEMORY_NEEDED ]; then # Need a minimum of 8Go of memory - swap_needed=$((2560 - $total_memory)) + swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 diff --git a/scripts/upgrade b/scripts/upgrade index 9e02c01..fd58f16 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -233,9 +233,9 @@ ynh_script_progression --message="Adding swap if needed..." --weight=7 total_memory=$(ynh_get_ram --total) swap_needed=0 -if [ $total_memory -lt 2560 ]; then +if [ $total_memory -lt $MEMORY_NEEDED ]; then # Need a minimum of 8Go of memory - swap_needed=$((2560 - $total_memory)) + swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 From d3ea53c200fd20a61acb4bb1a5dce5aa6ab77752 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:22:20 +0200 Subject: [PATCH 30/40] removing not needed cron job description --- scripts/install | 4 ++-- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 8c63cde..c78419e 100644 --- a/scripts/install +++ b/scripts/install @@ -219,9 +219,9 @@ ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_k ynh_secure_remove --file="$final_path/live/key.txt" #================================================= -# SETUP CRON JOB FOR REMOVING CACHE +# SETUP CRON JOB #================================================= -ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 +ynh_script_progression --message="Setuping a cron job..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app diff --git a/scripts/restore b/scripts/restore index ae64eaf..f41b2a8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -158,7 +158,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # RESTORE THE CRON FILE #================================================= -ynh_script_progression --message="Restoring a cron job for removing cache..." --weight=2 +ynh_script_progression --message="Restoring a cron job..." --weight=2 ynh_restore_file --origin_path="/etc/cron.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index fd58f16..eff42b3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -302,7 +302,7 @@ ynh_store_file_checksum --file="$config" #================================================= # SETUP CRON JOB FOR REMOVING CACHE #================================================= -ynh_script_progression --message="Setuping a cron job for removing cache..." --weight=1 +ynh_script_progression --message="Setuping a cron job..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app From 0c4121ac5234e4351a431f9e6091c426a60aa533 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:40:04 +0200 Subject: [PATCH 31/40] Add service description --- scripts/install | 6 +++--- scripts/restore | 6 +++--- scripts/upgrade | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index c78419e..5443717 100644 --- a/scripts/install +++ b/scripts/install @@ -264,9 +264,9 @@ chown -R "$app": "$final_path" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 -yunohost service add "$app-web" -yunohost service add "$app-sidekiq" -yunohost service add "$app-streaming" +yunohost service add "$app-web" --description "$app web service" --log_type "systemd" +yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" +yunohost service add "$app-streaming" --description "$app streaming service" --log_type "systemd" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index f41b2a8..175543a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -142,9 +142,9 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 -yunohost service add $app-web -yunohost service add $app-sidekiq -yunohost service add $app-streaming +yunohost service add "$app-web" --description "$app web service" --log_type "systemd" +yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" +yunohost service add "$app-streaming" --description "$app streaming service" --log_type "systemd" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index eff42b3..f14c08b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -322,6 +322,15 @@ ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 + +yunohost service add "$app-web" --description "$app web service" --log_type "systemd" +yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" +yunohost service add "$app-streaming" --description "$app streaming service" --log_type "systemd" + #================================================= # GENERIC FINALIZATION #================================================= From 117393a2f5beacc301df6271b0f62b3a0bd2c090 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:40:25 +0200 Subject: [PATCH 32/40] Apply last example_ynh on backup script --- scripts/backup | 55 +++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/scripts/backup b/scripts/backup index 61ad5f4..9159b31 100644 --- a/scripts/backup +++ b/scripts/backup @@ -33,30 +33,38 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=27 - -ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped" -ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped" -ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped" +ynh_print_info --message="Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --weight=2 ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --weight=2 ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app-web.service" +ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service" +ynh_backup --src_path="/etc/systemd/system/$app-streaming.service" + +#================================================= +# BACKUP A CRON FILE +#================================================= + +ynh_backup --src_path="/etc/cron.d/$app" + #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= @@ -64,33 +72,6 @@ ynh_script_progression --message="Backing up the PostgreSQL database..." --weigh ynh_psql_dump_db --database="$db_name" > db.sql -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP SYSTEMD -#================================================= -ynh_script_progression --message="Backing up systemd configuration..." --weight=2 - -ynh_backup --src_path="/etc/systemd/system/$app-web.service" -ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service" -ynh_backup --src_path="/etc/systemd/system/$app-streaming.service" - -#================================================= -# BACKUP A CRON FILE -#================================================= -ynh_script_progression --message="Backing up a cron file..." --weight=1 - -ynh_backup --src_path="/etc/cron.d/$app" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -ynh_systemd_action --action=start --service_name=${app}-web --line_match="Listening on tcp" --log_path=systemd -ynh_systemd_action --action=start --service_name=${app}-sidekiq --line_match="Starting processing" --log_path=systemd -ynh_systemd_action --action=start --service_name=${app}-streaming --line_match="Worker 1 now listening" --log_path=systemd - #================================================= # END OF SCRIPT #================================================= From 5108846acb8628d01aec2f8444e2256be2f13fae Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:44:21 +0200 Subject: [PATCH 33/40] cron job to cron file --- scripts/install | 4 ++-- scripts/restore | 2 +- scripts/upgrade | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index 5443717..77c3cca 100644 --- a/scripts/install +++ b/scripts/install @@ -219,9 +219,9 @@ ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_k ynh_secure_remove --file="$final_path/live/key.txt" #================================================= -# SETUP CRON JOB +# SETUP THE CRON FILE #================================================= -ynh_script_progression --message="Setuping a cron job..." --weight=1 +ynh_script_progression --message="Setuping the cron file..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app diff --git a/scripts/restore b/scripts/restore index 175543a..694b649 100644 --- a/scripts/restore +++ b/scripts/restore @@ -158,7 +158,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # RESTORE THE CRON FILE #================================================= -ynh_script_progression --message="Restoring a cron job..." --weight=2 +ynh_script_progression --message="Restoring the cron file..." --weight=2 ynh_restore_file --origin_path="/etc/cron.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index f14c08b..d578415 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -300,9 +300,9 @@ popd ynh_store_file_checksum --file="$config" #================================================= -# SETUP CRON JOB FOR REMOVING CACHE +# SETUP THE CRON FILE #================================================= -ynh_script_progression --message="Setuping a cron job..." --weight=1 +ynh_script_progression --message="Setuping the cron file..." --weight=1 ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app From d9cac4a31a4007b4b0223480deb74806f7a3458d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:50:52 +0200 Subject: [PATCH 34/40] spacing --- scripts/upgrade | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index d578415..bf81be9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -65,8 +65,8 @@ fi # Check if admin is not null if [[ "$admin" = "" || "$language" = "" ]]; then - echo "Unable to upgrade, please contact support" - ynh_die + echo "Unable to upgrade, please contact support" + ynh_die fi # If port_web doesn't exist, create it, need for old install @@ -94,7 +94,7 @@ fi if [[ -z "$paperclip_secret" ]]; then paperclip_secret=$(grep -oP "PAPERCLIP_SECRET=\K\w+" $config) if [[ -z "$paperclip_secret" ]]; then - paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi ynh_app_setting_set --app=$app --key=paperclip_secret --value="$paperclip_secret" fi @@ -103,7 +103,7 @@ fi if [[ -z "$secret_key_base" ]]; then secret_key_base=$(grep -oP "SECRET_KEY_BASE=\K\w+" $config) if [[ -z "$secret_key_base" ]]; then - secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi ynh_app_setting_set --app=$app --key=secret_key_base --value="$secret_key_base" fi @@ -112,7 +112,7 @@ fi if [[ -z "$otp_secret" ]]; then otp_secret=$(grep -oP "OTP_SECRET=\K\w+" $config) if [[ -z "$otp_secret" ]]; then - otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) + otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128) fi ynh_app_setting_set --app=$app --key=otp_secret --value="$otp_secret" fi @@ -172,30 +172,30 @@ ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=sy if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=14 + ynh_script_progression --message="Upgrading source files..." --weight=14 - # Download Mastodon - tmpdir="$(mktemp -d)" + # Download Mastodon + tmpdir="$(mktemp -d)" - mkdir $tmpdir/system - if [ -d "$final_path/live/public/system" ]; then - rsync -a "$final_path/live/public/system" "$tmpdir/." - fi - rsync -a "$config" "$tmpdir/." - ynh_secure_remove --file="$final_path/live" - ynh_setup_source --dest_dir="$final_path/live" + mkdir $tmpdir/system + if [ -d "$final_path/live/public/system" ]; then + rsync -a "$final_path/live/public/system" "$tmpdir/." + fi + rsync -a "$config" "$tmpdir/." + ynh_secure_remove --file="$final_path/live" + ynh_setup_source --dest_dir="$final_path/live" - # Temporary workaround for https://github.com/tootsuite/mastodon/issues/13292 - ynh_replace_string --match_string="sidekiq-unique-jobs (6.0.18)" --replace_string="sidekiq-unique-jobs (6.0.20)" --target_file="$final_path/live/Gemfile.lock" - - if [ -d "$tmpdir/system" ]; then - rsync -a "$tmpdir/system" "$final_path/live/public/." - fi - rsync -a "$tmpdir/.env.production" "$final_path/live/." - ynh_secure_remove --file="$tmpdir" + # Temporary workaround for https://github.com/tootsuite/mastodon/issues/13292 + ynh_replace_string --match_string="sidekiq-unique-jobs (6.0.18)" --replace_string="sidekiq-unique-jobs (6.0.20)" --target_file="$final_path/live/Gemfile.lock" - # Clean files which are not needed anymore - ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb" + if [ -d "$tmpdir/system" ]; then + rsync -a "$tmpdir/system" "$final_path/live/public/." + fi + rsync -a "$tmpdir/.env.production" "$final_path/live/." + ynh_secure_remove --file="$tmpdir" + + # Clean files which are not needed anymore + ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb" fi #================================================= @@ -285,15 +285,15 @@ ynh_script_progression --message="Upgrading Mastodon..." --weight=2640 chown -R "$app": "$final_path" pushd "$final_path/live" - ynh_use_nodejs - bundle config deployment 'true' - bundle config without 'development test' - bundle install -j$(getconf _NPROCESSORS_ONLN) - yarn install --pure-lockfile - RAILS_ENV=production bundle exec rails assets:clean - RAILS_ENV=production bundle exec rails assets:precompile - RAILS_ENV=production bundle exec rails db:migrate - RAILS_ENV=production bin/tootctl cache clear + ynh_use_nodejs + bundle config deployment 'true' + bundle config without 'development test' + bundle install -j$(getconf _NPROCESSORS_ONLN) + yarn install --pure-lockfile + RAILS_ENV=production bundle exec rails assets:clean + RAILS_ENV=production bundle exec rails assets:precompile + RAILS_ENV=production bundle exec rails db:migrate + RAILS_ENV=production bin/tootctl cache clear popd # Recalculate and store the checksum of the file for the next upgrade. From 27628985664a552291b74d11df8f104c5977eb6c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 13:51:42 +0200 Subject: [PATCH 35/40] typo --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index bf81be9..e4295fe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -212,7 +212,7 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=24 ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies +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" #================================================= From 1f9dc463f214a8692e99ca1f3273461dda55e8fd Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 26 May 2020 14:39:04 +0200 Subject: [PATCH 36/40] switching from add_header to more_set_headers --- conf/nginx.conf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index d348613..866fcc7 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -19,14 +19,14 @@ location / { } location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) { - add_header Cache-Control "public, max-age=31536000, immutable"; - add_header Strict-Transport-Security "max-age=31536000"; + more_set_headers "Cache-Control: public, max-age=31536000, immutable"; + more_set_headers "Strict-Transport-Security: max-age=31536000"; try_files $uri @proxy; } location /sw.js { - add_header Cache-Control "public, max-age=0"; - add_header Strict-Transport-Security "max-age=31536000"; + more_set_headers "Cache-Control: public, max-age=0"; + more_set_headers "Strict-Transport-Security: max-age=31536000"; try_files $uri @proxy; } @@ -49,8 +49,8 @@ location @proxy { proxy_cache_valid 200 7d; proxy_cache_valid 410 24h; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; - add_header X-Cached $upstream_cache_status; - add_header Strict-Transport-Security "max-age=31536000"; + more_set_headers "X-Cached: $upstream_cache_status"; + more_set_headers "Strict-Transport-Security: max-age=31536000"; tcp_nodelay on; } From 81ff2eef08d08086c6ff647c3c5e6cfe15525a30 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 29 May 2020 22:31:25 +0200 Subject: [PATCH 37/40] Backup to node 10 --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index dc466ba..2cf8424 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,7 +11,7 @@ RUBY_VERSION="2.6.5" BUNDLER_VERSION="1.17.3" -NODEJS_VERSION="12" +NODEJS_VERSION="10" MEMORY_NEEDED="2560" From 960d1c7d65dea1730ddb50adf0953b70993c5141 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 30 May 2020 00:20:28 +0200 Subject: [PATCH 38/40] Bump to last ynh_install_ruby version --- scripts/ynh_install_ruby__2 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2 index f064c08..df03e07 100644 --- a/scripts/ynh_install_ruby__2 +++ b/scripts/ynh_install_ruby__2 @@ -22,8 +22,8 @@ SOURCE_SUM=80ad89ffe04c0b481503bd375f05c212bbc7d44ef5f5e649e0acdf25eba86736" > " # Build an app.src for ruby-build mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20191004.tar.gz -SOURCE_SUM=6f053957acb0af6d621ebf2b9dacc9c265844b2dc6842a021eb10f0a70094fe8" > "../conf/ruby-build.src" + echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20200520.tar.gz +SOURCE_SUM=52be6908a94fbd4a94f5064e8b19d4a3baa4b773269c3884165518d83bcc8922" > "../conf/ruby-build.src" # Download and extract ruby-build ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build @@ -79,7 +79,10 @@ ynh_install_ruby () { if ! type rbenv > /dev/null 2>&1 then ynh_install_rbenv - elif dpkg --compare-versions "$(/opt/rbenv/bin/rbenv --version | cut -d" " -f2)" lt "1.1.2" + elif dpkg --compare-versions "$($rbenv_install_dir/bin/rbenv --version | cut -d" " -f2)" lt "1.1.2" + then + ynh_install_rbenv + elif dpkg --compare-versions "$($rbenv_install_dir/plugins/ruby-build/bin/ruby-build --version | cut -d" " -f2)" lt "20200520" then ynh_install_rbenv fi @@ -91,7 +94,7 @@ ynh_install_ruby () { test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby # Install the requested version of ruby - CONFIGURE_OPTS="--disable-install-doc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version + CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version # Store the ID of this app and the version of ruby requested for it echo "$YNH_APP_ID:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version" From 8fea96dcd81f40923ba2f599c3b7ab838429f2de Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 2 Jun 2020 18:34:04 +0200 Subject: [PATCH 39/40] apply last example_ynh for ynh_script_progression --- scripts/backup | 7 +++---- scripts/install | 46 ++++++++++++++++++++++------------------------ scripts/remove | 25 ++++++++++++------------- scripts/restore | 36 ++++++++++++++++++------------------ scripts/upgrade | 44 ++++++++++++++++++++++---------------------- 5 files changed, 77 insertions(+), 81 deletions(-) diff --git a/scripts/backup b/scripts/backup index 9159b31..c1d4f6f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,7 +13,6 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_script_progression --message="Managing script failure..." --weight=1 ynh_clean_setup () { ynh_clean_check_starting @@ -24,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -68,7 +67,7 @@ ynh_backup --src_path="/etc/cron.d/$app" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Backing up the PostgreSQL database..." --weight=4 +ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql @@ -76,4 +75,4 @@ ynh_psql_dump_db --database="$db_name" > db.sql # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 77c3cca..ebc4173 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_script_progression --message="Managing script failure..." --weight=1 ynh_clean_setup () { ynh_clean_check_starting @@ -25,7 +24,6 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -ynh_script_progression --message="Retrieving arguments from the manifest..." --weight=1 domain=$YNH_APP_ARG_DOMAIN path_url="/" @@ -40,7 +38,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=2 +ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -51,7 +49,7 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=2 +ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url @@ -64,7 +62,7 @@ ynh_app_setting_set --app=$app --key=language --value=$language #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=1 +ynh_script_progression --message="Configuring firewall..." # Find an available port port_web=$(ynh_find_port --port=3000) @@ -76,7 +74,7 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=86 +ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_app_dependencies $pkg_dependencies @@ -85,7 +83,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=5 +ynh_script_progression --message="Creating a MySQL database..." # Create postgresql database db_name="${app}_production" @@ -100,7 +98,7 @@ ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=5 +ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -113,7 +111,7 @@ ynh_replace_string --match_string="sidekiq-unique-jobs (6.0.18)" --replace_strin #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --weight=3 +ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config 'port_web port_stream' @@ -121,7 +119,7 @@ ynh_add_nginx_config 'port_web port_stream' #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --weight=4 +ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir=$final_path @@ -131,7 +129,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_script_progression --message="Adding swap is needed..." --weight=4 +ynh_script_progression --message="Adding swap is needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 @@ -141,13 +139,13 @@ if [ $total_memory -lt $MEMORY_NEEDED ]; then swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi -ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_script_progression --message="Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed #================================================= # INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Installing Ruby..." --weight=424 +ynh_script_progression --message="Installing Ruby..." ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" @@ -158,7 +156,7 @@ popd #================================================= # MODIFY A CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." --weight=2 +ynh_script_progression --message="Modifying a config file..." config="$final_path/live/.env.production" cp -f ../conf/.env.production.sample "$config" @@ -189,7 +187,7 @@ ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="m #================================================= # INSTALLING MASTODON #================================================= -ynh_script_progression --message="Installing Mastodon..." --weight=2230 +ynh_script_progression --message="Installing Mastodon..." chown -R "$app": "$final_path" @@ -221,7 +219,7 @@ ynh_secure_remove --file="$final_path/live/key.txt" #================================================= # SETUP THE CRON FILE #================================================= -ynh_script_progression --message="Setuping the cron file..." --weight=1 +ynh_script_progression --message="Setuping the cron file..." ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app @@ -229,7 +227,7 @@ cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=5 +ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" @@ -244,7 +242,7 @@ ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -ynh_script_progression --message="Storing the config file checksum..." --weight=1 +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" @@ -254,7 +252,7 @@ ynh_store_file_checksum --file="$config" #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Securing files and directories..." --weight=9 +ynh_script_progression --message="Securing files and directories..." # Set permissions to app files chown -R "$app": "$final_path" @@ -262,7 +260,7 @@ chown -R "$app": "$final_path" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app-web" --description "$app web service" --log_type "systemd" yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" @@ -271,7 +269,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" --l #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=47 +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}-sidekiq --action="start" --log_path=systemd --line_match="Starting processing" @@ -280,7 +278,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=2 +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -292,7 +290,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=2 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -300,4 +298,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index d955a8a..9fac8f2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=6 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -28,31 +28,30 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -ynh_script_progression --message="Removing service integration in YunoHost..." --weight=2 # 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..." --weight=2 + ynh_script_progression --message="Removing $app-web service..." yunohost service remove "$app-web" fi if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null then - ynh_script_progression --message="Removing $app-sidekiq service..." --weight=2 + ynh_script_progression --message="Removing $app-sidekiq service..." yunohost service remove "$app-sidekiq" fi if ynh_exec_warn_less yunohost service status "$app-streaming" >/dev/null then - ynh_script_progression --message="Removing $app-streaming service..." --weight=2 + ynh_script_progression --message="Removing $app-streaming service..." yunohost service remove "$app-streaming" fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=27 +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config --service="$app-web" @@ -62,7 +61,7 @@ ynh_remove_systemd_config --service="$app-streaming" #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --weight=4 +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" @@ -70,7 +69,7 @@ ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=28 +ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_ruby @@ -81,7 +80,7 @@ ynh_remove_extra_repo #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --weight=16 +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -89,7 +88,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." --weight=2 +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -99,7 +98,7 @@ ynh_remove_nginx_config #================================================= # REMOVE THE CRON FILE #================================================= -ynh_script_progression --message="Removing the cron file..." --weight=2 +ynh_script_progression --message="Removing the cron file..." # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" @@ -112,7 +111,7 @@ ynh_del_swap #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=2 +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app @@ -121,4 +120,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 694b649..513d924 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= -ynh_script_progression --message="Managing script failure..." --weight=2 +ynh_script_progression --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -26,7 +26,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=2 +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME @@ -40,7 +40,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=2 +ynh_script_progression --message="Validating restoration parameters..." ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -52,21 +52,21 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring nginx configuration..." --weight=1 +ynh_script_progression --message="Restoring the nginx 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..." --weight=105 +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..." --weight=5 +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 @@ -74,7 +74,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # RESTORE USER RIGHTS #================================================= -ynh_script_progression --message="Restoring users rights..." --weight=4 +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R $app: $final_path @@ -84,7 +84,7 @@ chown -R $app: $final_path #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_script_progression --message="Adding swap if needed..." --weight=4 +ynh_script_progression --message="Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 @@ -94,13 +94,13 @@ if [ $total_memory -lt $MEMORY_NEEDED ]; then swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi -ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_script_progression --message="Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=63 +ynh_script_progression --message="Reinstalling dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_install_app_dependencies $pkg_dependencies @@ -109,7 +109,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= # INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Installing Ruby..." --weight=393 +ynh_script_progression --message="Installing Ruby..." ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" @@ -120,7 +120,7 @@ popd #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=18 +ynh_script_progression --message="Restoring the PostgreSQL database..." ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd @@ -130,7 +130,7 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 +ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service" ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service" @@ -140,7 +140,7 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app-web" --description "$app web service" --log_type "systemd" yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" @@ -149,7 +149,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" --l #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=41 +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}-sidekiq --action="start" --log_path=systemd --line_match="Starting processing" @@ -158,7 +158,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # RESTORE THE CRON FILE #================================================= -ynh_script_progression --message="Restoring the cron file..." --weight=2 +ynh_script_progression --message="Restoring the cron file..." ynh_restore_file --origin_path="/etc/cron.d/$app" @@ -167,7 +167,7 @@ ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=2 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -175,4 +175,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index e4295fe..8441307 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=4 +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -40,14 +40,14 @@ vapid_public_key=$(ynh_app_setting_get --app=$app --key=vapid_public_key) #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." --weight=1 +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." config="$final_path/live/.env.production" @@ -131,7 +131,7 @@ ynh_remove_extra_repo #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=442 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -160,7 +160,7 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=22 +ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped" ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped" @@ -172,7 +172,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=sy if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=14 + ynh_script_progression --message="Upgrading source files..." # Download Mastodon tmpdir="$(mktemp -d)" @@ -201,14 +201,14 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=3 +ynh_script_progression --message="Upgrading nginx web server configuration..." ynh_add_nginx_config 'port_web port_stream' #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=24 +ynh_script_progression --message="Upgrading dependencies..." ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$NODEJS_VERSION @@ -218,7 +218,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=7 +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 @@ -228,7 +228,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # ADD SWAP IF NEEDED #================================================= -ynh_script_progression --message="Adding swap if needed..." --weight=7 +ynh_script_progression --message="Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 @@ -238,13 +238,13 @@ if [ $total_memory -lt $MEMORY_NEEDED ]; then swap_needed=$(($MEMORY_NEEDED - $total_memory)) fi -ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1 +ynh_script_progression --message="Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed #================================================= # INSTALLING RUBY AND BUNDLER #================================================= -ynh_script_progression --message="Installing Ruby..." --weight=424 +ynh_script_progression --message="Installing Ruby..." ynh_install_ruby --ruby_version=$RUBY_VERSION pushd "$final_path/live" @@ -255,7 +255,7 @@ popd #================================================= # MODIFY A CONFIG FILE #================================================= -ynh_script_progression --message="Modifying a config file..." --weight=1 +ynh_script_progression --message="Modifying a config file..." ynh_backup_if_checksum_is_different --file="$config" cp -f ../conf/.env.production.sample "$config" @@ -280,7 +280,7 @@ ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapi #================================================= # UPGRADE MASTODON #================================================= -ynh_script_progression --message="Upgrading Mastodon..." --weight=2640 +ynh_script_progression --message="Upgrading Mastodon..." chown -R "$app": "$final_path" @@ -302,7 +302,7 @@ ynh_store_file_checksum --file="$config" #================================================= # SETUP THE CRON FILE #================================================= -ynh_script_progression --message="Setuping the cron file..." --weight=1 +ynh_script_progression --message="Setuping the cron file..." ynh_replace_string --match_string="__FINAL_PATH__" --replace_string="$final_path" --target_file="../conf/cron" cp -f ../conf/cron /etc/cron.d/$app @@ -310,7 +310,7 @@ cp -f ../conf/cron /etc/cron.d/$app #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=13 +ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" @@ -325,7 +325,7 @@ ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "$app-web" --description "$app web service" --log_type "systemd" yunohost service add "$app-sidekiq" --description "$app sidekiq service" --log_type "systemd" @@ -336,7 +336,7 @@ yunohost service add "$app-streaming" --description "$app streaming service" --l #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Securing files and directories..." --weight=9 +ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R $app: $final_path @@ -344,7 +344,7 @@ chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 +ynh_script_progression --message="Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -356,7 +356,7 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=48 +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}-sidekiq --action="start" --log_path=systemd --line_match="Starting processing" @@ -365,7 +365,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=2 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -373,4 +373,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression --message="Upgrade of $app completed" From d3df899e0a99a63ee1cf7ad845cc513aeaaf30ef Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 4 Jun 2020 00:36:02 +0200 Subject: [PATCH 40/40] Implement new nodejs helper --- conf/mastodon-sidekiq.service | 2 +- conf/mastodon-streaming.service | 4 ++-- conf/mastodon-web.service | 2 +- manifest.json | 2 +- scripts/install | 11 +++-------- scripts/upgrade | 11 +++-------- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/conf/mastodon-sidekiq.service b/conf/mastodon-sidekiq.service index 73f29e5..a4fc0da 100644 --- a/conf/mastodon-sidekiq.service +++ b/conf/mastodon-sidekiq.service @@ -9,7 +9,7 @@ Environment="RAILS_ENV=production" Environment="DB_POOL=25" Environment="MALLOC_ARENA_MAX=2" - ExecStart=__RBENVROOT__/shims/bundle exec sidekiq -c 25 + ExecStart=__RBENV_ROOT__/shims/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-streaming.service b/conf/mastodon-streaming.service index 2e130d5..94309c1 100644 --- a/conf/mastodon-streaming.service +++ b/conf/mastodon-streaming.service @@ -9,8 +9,8 @@ Environment="NODE_ENV=production" Environment="PORT=__PORT_STREAM__" Environment="STREAMING_CLUSTER_NUM=1" - Environment=PATH=__NODEJS_PATH__ - ExecStart=__NODEJS_PATH__/node ./streaming + Environment=__YNH_LOAD_NODE_PATH__ + ExecStart=__YNH_NODE__ ./streaming TimeoutSec=15 Restart=always StandardError=syslog diff --git a/conf/mastodon-web.service b/conf/mastodon-web.service index 14d1260..bb07cf4 100644 --- a/conf/mastodon-web.service +++ b/conf/mastodon-web.service @@ -8,7 +8,7 @@ WorkingDirectory=__FINALPATH__/live Environment="RAILS_ENV=production" Environment="PORT=__PORT_WEB__" - ExecStart=__RBENVROOT__/shims/bundle exec puma -C config/puma.rb + ExecStart=__RBENV_ROOT__/shims/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always diff --git a/manifest.json b/manifest.json index 9041ab7..a6dbf25 100644 --- a/manifest.json +++ b/manifest.json @@ -23,7 +23,7 @@ } ], "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 3.8.2" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index ebc4173..53b598b 100644 --- a/scripts/install +++ b/scripts/install @@ -230,14 +230,9 @@ cp -f ../conf/cron /etc/cron.d/$app ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" -ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" -ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" +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 diff --git a/scripts/upgrade b/scripts/upgrade index 8441307..6445cc8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -313,14 +313,9 @@ cp -f ../conf/cron /etc/cron.d/$app ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/mastodon-web.service" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-web.service" -ynh_replace_string --match_string="__RBENVROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/mastodon-sidekiq.service" -ynh_replace_string --match_string="__PORT_STREAM__" --replace_string="$port_stream" --target_file="../conf/mastodon-streaming.service" -ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="../conf/mastodon-streaming.service" -ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" -ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" -ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" +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" #================================================= # INTEGRATE SERVICE IN YUNOHOST