mirror of
https://github.com/YunoHost-Apps/glitchsoc_ynh.git
synced 2024-09-03 19:15:59 +02:00
make some cleaning of scripts
make some cleaning of scripts
This commit is contained in:
commit
01d0696ff7
18 changed files with 317 additions and 692 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -14,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.
|
||||
|
@ -26,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
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
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 && 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 statuses remove
|
||||
@monthly cd __FINAL_PATH__/live && RAILS_ENV=production bin/tootctl preview_cards remove
|
||||
|
|
|
@ -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=__RBENV_ROOT__/shims/bundle exec sidekiq -c 25
|
||||
TimeoutSec=15
|
||||
Restart=always
|
||||
StandardError=syslog
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=__RBENV_ROOT__/shims/bundle exec puma -C config/puma.rb
|
||||
ExecReload=/bin/kill -SIGUSR1 $MAINPID
|
||||
TimeoutSec=15
|
||||
Restart=always
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -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": [
|
||||
|
@ -23,7 +23,7 @@
|
|||
}
|
||||
],
|
||||
"requirements": {
|
||||
"yunohost": ">= 3.7"
|
||||
"yunohost": ">= 3.8.2"
|
||||
},
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
# 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"
|
||||
|
||||
BUNDLER_VERSION="1.17.3"
|
||||
|
||||
NODEJS_VERSION="10"
|
||||
|
||||
MEMORY_NEEDED="2560"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -33,43 +32,27 @@ 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"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the PostgreSQL database..." --weight=4
|
||||
|
||||
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"
|
||||
|
@ -78,21 +61,18 @@ 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
|
||||
# BACKUP THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
ynh_print_info --message="Backing up the PostgreSQL database..."
|
||||
|
||||
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
|
||||
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)."
|
||||
|
|
138
scripts/install
138
scripts/install
|
@ -8,16 +8,12 @@
|
|||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Managing script failure..." --weight=1
|
||||
|
||||
ynh_clean_setup () {
|
||||
ynh_clean_check_starting
|
||||
|
@ -28,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="/"
|
||||
|
@ -43,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"
|
||||
|
@ -54,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
|
||||
|
@ -67,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)
|
||||
|
@ -79,16 +74,16 @@ 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="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"
|
||||
|
||||
#=================================================
|
||||
# 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"
|
||||
|
@ -103,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
|
||||
|
@ -116,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'
|
||||
|
@ -124,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
|
||||
|
@ -134,82 +129,87 @@ 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_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
|
||||
swap_needed=$((2560 - $total_memory))
|
||||
if [ $total_memory -lt $MEMORY_NEEDED ]; then
|
||||
# Need a minimum of 2.5Go of memory
|
||||
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=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:$BUNDLER_VERSION --no-document
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Modifying a config file..." --weight=2
|
||||
ynh_script_progression --message="Modifying a config file..."
|
||||
|
||||
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"
|
||||
|
||||
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
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing Mastodon..." --weight=2230
|
||||
ynh_script_progression --message="Installing Mastodon..."
|
||||
|
||||
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">> .env.production
|
||||
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 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
|
||||
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 > /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")
|
||||
|
||||
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"
|
||||
|
@ -217,41 +217,37 @@ 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 THE CRON FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setuping a cron job for removing cache..." --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"
|
||||
ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron"
|
||||
sudo cp -f ../conf/cron /etc/cron.d/$app
|
||||
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"
|
||||
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
|
||||
#=================================================
|
||||
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="${final_path}/live/.env.production"
|
||||
ynh_store_file_checksum --file="$config"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# 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"
|
||||
|
@ -259,16 +255,16 @@ 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"
|
||||
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
|
||||
#=================================================
|
||||
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"
|
||||
|
@ -277,7 +273,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 ]
|
||||
|
@ -289,7 +285,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
|
||||
|
||||
|
@ -297,4 +293,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"
|
||||
|
|
|
@ -8,14 +8,13 @@
|
|||
|
||||
source _common.sh
|
||||
source ynh_install_ruby__2
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source ynh_add_swap
|
||||
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
|
||||
|
||||
|
@ -29,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"
|
||||
|
@ -63,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"
|
||||
|
@ -71,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
|
||||
|
@ -82,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"
|
||||
|
@ -90,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
|
||||
|
@ -100,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"
|
||||
|
@ -113,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
|
||||
|
@ -122,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"
|
||||
|
|
|
@ -9,15 +9,13 @@
|
|||
#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
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
|
@ -28,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
|
||||
|
||||
|
@ -42,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}"
|
||||
|
@ -54,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
|
||||
|
@ -76,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
|
||||
|
@ -86,42 +84,43 @@ 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_check_ram)
|
||||
total_swap=$(ynh_check_ram --only_swap)
|
||||
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
|
||||
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="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"
|
||||
|
||||
#=================================================
|
||||
# INSTALLING RUBY AND BUNDLER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing Ruby..." --weight=393
|
||||
ynh_script_progression --message="Installing Ruby..."
|
||||
|
||||
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:$BUNDLER_VERSION --no-document
|
||||
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
|
||||
|
@ -131,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"
|
||||
|
@ -141,16 +140,16 @@ 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
|
||||
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
|
||||
#=================================================
|
||||
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"
|
||||
|
@ -159,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 the cron file..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
||||
|
||||
|
@ -168,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
|
||||
|
||||
|
@ -176,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"
|
||||
|
|
154
scripts/upgrade
154
scripts/upgrade
|
@ -8,15 +8,13 @@
|
|||
|
||||
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
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --weight=4
|
||||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
|
@ -42,14 +40,16 @@ 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"
|
||||
|
||||
# If db_name doesn't exist, create it
|
||||
if [ -z "$db_name" ]; then
|
||||
|
@ -87,12 +87,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 +101,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 +110,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 +119,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
|
||||
|
@ -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)"
|
||||
|
@ -181,7 +181,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"
|
||||
|
||||
|
@ -201,24 +201,24 @@ 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="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"
|
||||
|
||||
#=================================================
|
||||
# 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,114 +228,110 @@ 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_check_ram)
|
||||
total_swap=$(ynh_check_ram --only_swap)
|
||||
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
|
||||
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=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:$BUNDLER_VERSION --no-document
|
||||
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="$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 "__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="$config"
|
||||
ynh_replace_string --match_string="__VAPID_PUBLIC_KEY__" --replace_string="$vapid_public_key" --target_file="$config"
|
||||
|
||||
#=================================================
|
||||
# UPGRADE MASTODON
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading Mastodon..." --weight=2640
|
||||
ynh_script_progression --message="Upgrading Mastodon..."
|
||||
|
||||
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 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
|
||||
|
||||
# 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"
|
||||
ynh_store_file_checksum --file="$config"
|
||||
|
||||
#=================================================
|
||||
# SETUP CRON JOB FOR REMOVING CACHE
|
||||
# SETUP THE CRON FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setuping a cron job for removing cache..." --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"
|
||||
ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/cron"
|
||||
sudo cp -f ../conf/cron /etc/cron.d/$app
|
||||
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"
|
||||
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
|
||||
#=================================================
|
||||
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"
|
||||
yunohost service add "$app-streaming" --description "$app streaming service" --log_type "systemd"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# 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
|
||||
|
@ -343,7 +339,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 ]
|
||||
|
@ -355,7 +351,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"
|
||||
|
@ -364,7 +360,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
|
||||
|
||||
|
@ -372,4 +368,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"
|
||||
|
|
|
@ -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}"
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue