aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoryalh76 <yalh@yahoo.com>2021-04-21 20:32:02 +0200
committerGitHub <noreply@github.com>2021-04-21 20:32:02 +0200
commit00d4516409fae2e6e3afec092e491bc8dba5fff4 (patch)
tree7b9c1e4e210ce073680ab449d080985600d77cd8 /scripts
parent2e9f19e75a4b047702fcab3c2b0325ee03e97045 (diff)
parent799587668ba8d57ab579092b76ce2e39c7373257 (diff)
downloadmastodon_ynh-00d4516409fae2e6e3afec092e491bc8dba5fff4.tar.gz
mastodon_ynh-00d4516409fae2e6e3afec092e491bc8dba5fff4.tar.bz2
mastodon_ynh-00d4516409fae2e6e3afec092e491bc8dba5fff4.zip
Merge pull request #264 from YunoHost-Apps/example
Apply example_ynh
Diffstat (limited to 'scripts')
-rw-r--r--scripts/backup2
-rw-r--r--scripts/install85
-rw-r--r--scripts/remove8
-rw-r--r--scripts/restore46
-rw-r--r--scripts/upgrade68
5 files changed, 99 insertions, 110 deletions
diff --git a/scripts/backup b/scripts/backup
index c1d4f6f..590ce0f 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
-#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
+# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
diff --git a/scripts/install b/scripts/install
index 0b79b96..f5da202 100644
--- a/scripts/install
+++ b/scripts/install
@@ -81,6 +81,14 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
ynh_install_ruby --ruby_version=$RUBY_VERSION
#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_script_progression --message="Configuring system user..."
+
+# Create a system user
+ynh_system_user_create --username=$app --home_dir="$final_path"
+
+#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..."
@@ -104,23 +112,19 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/live"
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
+
#=================================================
# NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Configuring nginx web server..."
+ynh_script_progression --message="Configuring NGINX web server..."
-# Create a dedicated nginx config
+# Create a dedicated NGINX config
ynh_add_nginx_config 'port_web port_stream'
#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Configuring system user..."
-
-# Create a system user
-ynh_system_user_create --username=$app --home_dir=$final_path
-
-#=================================================
# SPECIFIC SETUP
#=================================================
# ADD SWAP IF NEEDED
@@ -150,9 +154,9 @@ pushd "$final_path/live"
popd
#=================================================
-# MODIFY A CONFIG FILE
+# ADD A CONFIGURATION
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Adding a config file..."
config="$final_path/live/.env.production"
@@ -169,18 +173,32 @@ vapid_public_key=""
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
+chmod 400 "$config"
+chown $app:$app "$config"
+
ynh_replace_string --match_string="registrations_mode: 'open'" --replace_string="registrations_mode: 'none'" --target_file="$final_path/live/config/settings.yml"
ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="min_invite_role: 'none'" --target_file="$final_path/live/config/settings.yml"
ynh_store_file_checksum --file="$final_path/live/config/settings.yml"
+chmod 400 "$final_path/live/config/settings.yml"
+chown $app:$app "$final_path/live/config/settings.yml"
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Configuring a systemd service..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
+ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
+ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
+
#=================================================
# INSTALLING MASTODON
#=================================================
ynh_script_progression --message="Installing Mastodon..."
-chown -R "$app": "$final_path"
-
pushd "$final_path/live"
sudo -u $app $ynh_ruby_load_path bin/bundle config deployment 'true'
sudo -u $app $ynh_ruby_load_path bin/bundle config without 'development test'
@@ -201,11 +219,14 @@ ynh_app_setting_set --app="$app" --key=vapid_private_key --value="$vapid_private
vapid_public_key=$(grep -oP "VAPID_PUBLIC_KEY=\K.+" "$final_path/live/key.txt")
ynh_app_setting_set --app="$app" --key=vapid_public_key --value="$vapid_public_key"
+ynh_secure_remove --file="$final_path/live/key.txt"
+
ynh_delete_file_checksum --file="$config"
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
-ynh_secure_remove --file="$final_path/live/key.txt"
+chmod 400 "$config"
+chown $app:$app "$config"
#=================================================
# SETUP THE CRON FILE
@@ -215,41 +236,15 @@ ynh_script_progression --message="Setuping the cron file..."
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Configuring a systemd service..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
-ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
-ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
-
-#=================================================
-# STORE THE CONFIG FILE CHECKSUM
-#=================================================
-ynh_script_progression --message="Storing the config file checksum..."
-
-# Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --file="$config"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions to app files
-chown -R "$app": "$final_path"
-
-#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START SYSTEMD SERVICE
@@ -278,7 +273,7 @@ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --aut
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/remove b/scripts/remove
index 8a465a4..42b0109 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -29,7 +29,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
-# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
+# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null
then
ynh_script_progression --message="Removing $app-web service integration..."
@@ -64,7 +64,7 @@ ynh_remove_systemd_config --service="$app-streaming"
ynh_script_progression --message="Removing the PostgreSQL database..."
# Remove a database if it exists, along with the associated user
-ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name"
+ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
@@ -88,9 +88,9 @@ ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Removing nginx web server configuration..."
+ynh_script_progression --message="Removing NGINX web server configuration..."
-# Remove the dedicated nginx config
+# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
diff --git a/scripts/restore b/scripts/restore
index a8cfd30..7a3808b 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -6,7 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
-#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
+# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_ruby__2
source ../settings/scripts/ynh_add_swap
@@ -25,7 +25,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
-ynh_script_progression --message="Loading settings..."
+ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -51,32 +51,28 @@ test ! -d $final_path \
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Restoring the nginx configuration..."
+ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
-# RESTORE THE APP MAIN DIR
-#=================================================
-ynh_script_progression --message="Restoring the app main directory..."
-
-ynh_restore_file --origin_path="$final_path"
-
-#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
+ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
-# RESTORE USER RIGHTS
+# RESTORE THE APP MAIN DIR
#=================================================
-ynh_script_progression --message="Restoring user rights..."
+ynh_script_progression --message="Restoring the app main directory..."
+
+ynh_restore_file --origin_path="$final_path"
-# Restore permissions on app files
-chown -R $app: $final_path
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
#=================================================
# SPECIFIC RESTORATION
@@ -97,6 +93,13 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
#=================================================
+# RESTORE THE CRON FILE
+#=================================================
+ynh_script_progression --message="Restoring the cron file..."
+
+ynh_restore_file --origin_path="/etc/cron.d/$app"
+
+#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
@@ -142,9 +145,9 @@ systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START SYSTEMD SERVICE
@@ -156,13 +159,6 @@ ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=sys
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
#=================================================
-# RESTORE THE CRON FILE
-#=================================================
-ynh_script_progression --message="Restoring the cron file..."
-
-ynh_restore_file --origin_path="/etc/cron.d/$app"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
diff --git a/scripts/upgrade b/scripts/upgrade
index aa96bef..86555dc 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -49,7 +49,6 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
-
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@@ -124,7 +123,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
- # restore it if the upgrade fails
+ # Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
@@ -142,6 +141,14 @@ ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=syst
ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped"
#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_script_progression --message="Making sure dedicated system user exists..."
+
+# Create a dedicated user (if not existing)
+ynh_system_user_create --username=$app --home_dir="$final_path"
+
+#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@@ -171,10 +178,14 @@ then
ynh_secure_remove --file="$final_path/live/config/initializers/timeout.rb"
fi
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:www-data "$final_path"
+
#=================================================
# NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Upgrading nginx web server configuration..."
+ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config 'port_web port_stream'
@@ -190,14 +201,6 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
ynh_install_ruby --ruby_version=$RUBY_VERSION
#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Making sure dedicated system user exists..."
-
-# Create a dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir=$final_path
-
-#=================================================
# SPECIFIC UPGRADE
#=================================================
# ADD SWAP IF NEEDED
@@ -227,14 +230,27 @@ pushd "$final_path/live"
popd
#=================================================
-# MODIFY A CONFIG FILE
+# UPDATE A CONFIG FILE
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Updating a config file..."
language="$(echo $language | head -c 2)"
ynh_add_config --template="../conf/.env.production.sample" --destination="$config"
+chmod 400 "$config"
+chown $app:$app "$config"
+
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Upgrading systemd configuration..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
+ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
+ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
+
#=================================================
# UPGRADE MASTODON
#=================================================
@@ -262,33 +278,15 @@ ynh_script_progression --message="Setuping the cron file..."
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Upgrading systemd configuration..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service" --others_var="port_web RBENV_ROOT"
-ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service" --others_var="RBENV_ROOT"
-ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service" --others_var="port_stream ynh_node_load_PATH ynh_node"
-
-#=================================================
# GENERIC FINALIZATION
#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions on app files
-chown -R $app: $final_path
-
-#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add "$app-web" --description "$app web service"
-yunohost service add "$app-sidekiq" --description "$app sidekiq service"
-yunohost service add "$app-streaming" --description "$app streaming service"
+yunohost service add "$app-web" --description="$app web service"
+yunohost service add "$app-sidekiq" --description="$app sidekiq service"
+yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START SYSTEMD SERVICE
@@ -302,7 +300,7 @@ ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=s
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload