aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoryalh76 <yalh@yahoo.com>2022-05-29 15:54:35 +0200
committeryalh76 <yalh@yahoo.com>2022-05-29 15:54:35 +0200
commitad7007b3464dd9c00da8bf2d6bd566d08dd96db6 (patch)
treed733c07e0cee76345c973e0c5f8d0e214b18ec6e /scripts
parent4c87683b08ad2f391f24a2f364aaae6609ec4ac3 (diff)
downloadmastodon_ynh-ad7007b3464dd9c00da8bf2d6bd566d08dd96db6.tar.gz
mastodon_ynh-ad7007b3464dd9c00da8bf2d6bd566d08dd96db6.tar.bz2
mastodon_ynh-ad7007b3464dd9c00da8bf2d6bd566d08dd96db6.zip
Apply last example_yn
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_common.sh9
-rw-r--r--scripts/backup2
-rw-r--r--scripts/install68
-rw-r--r--scripts/remove1
-rw-r--r--scripts/restore25
-rw-r--r--scripts/upgrade53
-rw-r--r--scripts/ynh_install_ruby__29
7 files changed, 80 insertions, 87 deletions
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 168251c..142584e 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -6,12 +6,11 @@
# 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-tools redis-server postgresql postgresql-contrib libidn11-dev libicu-dev libjemalloc-dev curl apt-transport-https"
+build_pkg_dependencies=""
-MEMORY_NEEDED="2560"
-
-RUBY_VERSION="2.7.2"
-
-NODEJS_VERSION="12"
+memory_needed="2560"
+ruby_version=2.7.2
+nodejs_version=12
# Workaround for Mastodon on Bullseye
# See https://github.com/mastodon/mastodon/issues/15751#issuecomment-873594463
diff --git a/scripts/backup b/scripts/backup
index 2a64b32..96a895d 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
- ynh_clean_check_starting
+ true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
diff --git a/scripts/install b/scripts/install
index 2b7a807..5d2905d 100644
--- a/scripts/install
+++ b/scripts/install
@@ -27,11 +27,11 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
-admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
+admin=$YNH_APP_ARG_ADMIN
-admin_mail=$(ynh_user_get_info $admin 'mail')
+admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
app=$YNH_APP_INSTANCE_NAME
@@ -53,8 +53,8 @@ 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
-ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=language --value=$language
+ynh_app_setting_set --app=$app --key=admin --value=$admin
#=================================================
# STANDARD MODIFICATIONS
@@ -75,10 +75,10 @@ ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream
#=================================================
ynh_script_progression --message="Installing dependencies..."
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
-ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
-ynh_install_ruby --ruby_version=$RUBY_VERSION
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
+ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
+ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
+ynh_exec_warn_less 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
@@ -86,24 +86,21 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION
ynh_script_progression --message="Configuring system user..."
# Create a system user
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..."
-
-# Create PostgreSQL database
db_name=$(ynh_sanitize_dbid --db_name="${app}_production")
db_user=$(ynh_sanitize_dbid --db_name=$app)
-db_pwd=$(ynh_string_random --length=30)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
-ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
ynh_psql_test_if_first_run
-ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
+ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;"
+db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@@ -136,26 +133,15 @@ ynh_script_progression --message="Adding swap if needed..."
total_memory=$(ynh_get_ram --total)
swap_needed=0
-if [ $total_memory -lt $MEMORY_NEEDED ]; then
+if [ $total_memory -lt $memory_needed ]; then
# Need a minimum of 2.5Go of memory
- swap_needed=$(($MEMORY_NEEDED - $total_memory))
+ swap_needed=$(($memory_needed - $total_memory))
fi
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..."
-
-pushd "$final_path/live"
- ynh_use_ruby
- ynh_gem update --system
- ynh_gem install bundler --no-document
-popd
-
-#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
@@ -190,21 +176,14 @@ chmod 400 "$final_path/live/config/settings.yml"
chown $app:$app "$final_path/live/config/settings.yml"
#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Configuring a systemd service..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service"
-ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service"
-ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
-
-#=================================================
-# INSTALLING MASTODON
+# BUILD APP
#=================================================
-ynh_script_progression --message="Installing Mastodon..."
+ynh_script_progression --message="Building app..."
pushd "$final_path/live"
+ ynh_use_ruby
+ ynh_gem update --system
+ ynh_gem install bundler --no-document
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config deployment 'true'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config without 'development test'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config set force_ruby_platform true
@@ -234,6 +213,19 @@ ynh_add_config --template="../conf/.env.production.sample" --destination="$confi
chmod 400 "$config"
chown $app:$app "$config"
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
+ynh_package_autoremove
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Configuring a systemd service..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service"
+ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service"
+ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
+
#=================================================
# SETUP THE CRON FILE
#=================================================
diff --git a/scripts/remove b/scripts/remove
index d6d2afd..56bfccb 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -91,7 +91,6 @@ ynh_script_progression --message="Removing dependencies..."
ynh_remove_ruby
ynh_remove_nodejs
ynh_remove_app_dependencies
-ynh_remove_extra_repo
#=================================================
# SPECIFIC REMOVE
diff --git a/scripts/restore b/scripts/restore
index db512fe..c71b839 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -34,7 +34,6 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
-db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
@@ -59,7 +58,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
@@ -80,10 +79,10 @@ chown -R $app:www-data "$final_path"
ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
-ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
-ynh_install_ruby --ruby_version=$RUBY_VERSION
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
+ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
+ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
+ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
@@ -91,6 +90,7 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION
ynh_script_progression --message="Restoring the PostgreSQL database..."
ynh_psql_test_if_first_run
+db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;"
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
@@ -103,26 +103,29 @@ ynh_script_progression --message="Adding swap if needed..."
total_memory=$(ynh_get_ram --total)
swap_needed=0
-if [ $total_memory -lt $MEMORY_NEEDED ]; then
+if [ $total_memory -lt $memory_needed ]; then
# Need a minimum of 8Go of memory
- swap_needed=$(($MEMORY_NEEDED - $total_memory))
+ swap_needed=$(($memory_needed - $total_memory))
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
#=================================================
-# INSTALLING RUBY AND BUNDLER
+# BUILD APP
#=================================================
-ynh_script_progression --message="Installing Ruby..."
+ynh_script_progression --message="Building app..."
pushd "$final_path/live"
ynh_use_ruby
ynh_gem update --system
ynh_gem install bundler --no-document
- ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install --redownload -j$(getconf _NPROCESSORS_ONLN)
+ ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install --redownload -j$(getconf _NPROCESSORS_ONLN)
popd
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
+ynh_package_autoremove
+
#=================================================
# RESTORE VARIOUS FILES
#=================================================
diff --git a/scripts/upgrade b/scripts/upgrade
index 9aee01c..968045d 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -20,13 +20,13 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
+language=$(ynh_app_setting_get --app=$app --key=language)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
-language=$(ynh_app_setting_get --app=$app --key=language)
redis_namespace=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
-db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
+db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
admin_mail=$(ynh_user_get_info --username=$admin --key='mail')
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
port_stream=$(ynh_app_setting_get --app=$app --key=port_stream)
@@ -159,7 +159,7 @@ ynh_remove_extra_repo
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@@ -208,10 +208,10 @@ ynh_add_nginx_config
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
-ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
-ynh_install_ruby --ruby_version=$RUBY_VERSION
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
+ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
+ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
+ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# SPECIFIC UPGRADE
@@ -223,25 +223,38 @@ ynh_script_progression --message="Adding swap if needed..."
total_memory=$(ynh_get_ram --total)
swap_needed=0
-if [ $total_memory -lt $MEMORY_NEEDED ]; then
+if [ $total_memory -lt $memory_needed ]; then
# Need a minimum of 8Go of memory
- swap_needed=$(($MEMORY_NEEDED - $total_memory))
+ swap_needed=$(($memory_needed - $total_memory))
fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
#=================================================
-# INSTALLING RUBY AND BUNDLER
+# BUILD APP
#=================================================
-ynh_script_progression --message="Installing Ruby..."
+ynh_script_progression --message="Building app..."
pushd "$final_path/live"
ynh_use_ruby
ynh_gem update --system
ynh_gem install bundler --no-document
+ ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config deployment 'true'
+ ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config without 'development test'
+ ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config set force_ruby_platform true --quiet
+ ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
+ ynh_use_nodejs
+ ynh_exec_as $app $ynh_node_load_PATH yarn install --pure-lockfile
+ ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:clean
+ ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:precompile
+ ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails db:migrate
+ ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/tootctl cache clear
popd
+ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
+ynh_package_autoremove
+
#=================================================
# UPDATE A CONFIG FILE
#=================================================
@@ -265,24 +278,6 @@ ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.ser
ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
#=================================================
-# UPGRADE MASTODON
-#=================================================
-ynh_script_progression --message="Upgrading Mastodon..."
-
-pushd "$final_path/live"
- ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config deployment 'true'
- ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config without 'development test'
- ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config set force_ruby_platform true --quiet
- ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
- ynh_use_nodejs
- ynh_exec_as $app $ynh_node_load_PATH yarn install --pure-lockfile
- ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:clean
- ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:precompile
- ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails db:migrate
- ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/tootctl cache clear
-popd
-
-#=================================================
# SETUP THE CRON FILE
#=================================================
ynh_script_progression --message="Setuping the cron file..."
diff --git a/scripts/ynh_install_ruby__2 b/scripts/ynh_install_ruby__2
index b12ab74..982d0b2 100644
--- a/scripts/ynh_install_ruby__2
+++ b/scripts/ynh_install_ruby__2
@@ -14,6 +14,11 @@ ruby_version_path="$rbenv_install_dir/versions"
export RBENV_ROOT="$rbenv_install_dir"
export rbenv_root="$rbenv_install_dir"
+ruby_dependencies=""
+build_ruby_dependencies="libjemalloc-dev curl build-essential libreadline-dev zlib1g-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev autoconf automake bison libtool"
+pkg_dependencies="$pkg_dependencies $ruby_dependencies"
+build_pkg_dependencies="$build_pkg_dependencies $build_ruby_dependencies"
+
# Load the version of Ruby for an app, and set variables.
#
# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time.
@@ -37,9 +42,9 @@ export rbenv_root="$rbenv_install_dir"
# Finally, to start a Ruby service with the correct version, 2 solutions
# Either the app is dependent of Ruby or gem, but does not called it directly.
# In such situation, you need to load PATH
-# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"`
+# `Environment="__YNH_RUBY_LOAD_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
-# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path
+# You will replace __YNH_RUBY_LOAD_PATH__ with $ynh_ruby_load_path
#
# Or Ruby start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_RUBY__ my_app run`