2021-08-15 21:48:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
app="$YNH_APP_INSTANCE_NAME"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
2022-03-15 02:14:16 +01:00
|
|
|
|
2022-12-17 22:05:20 +01:00
|
|
|
landing_page_user=$(ynh_app_setting_get --app="$app" --key=landing_page_user)
|
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
port=$(ynh_app_setting_get --app="$app" --key=port)
|
|
|
|
path_url=$(ynh_app_setting_get --app="$app" --key=path_url)
|
2022-03-15 02:14:16 +01:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size)
|
2022-03-26 00:21:52 +01:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
2022-12-17 22:05:20 +01:00
|
|
|
db_user=$(ynh_app_setting_get --app="$app" --key=db_user)
|
2022-03-28 20:00:13 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd)
|
2022-03-15 02:14:16 +01:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app="$app" --key=datadir)
|
2022-03-26 00:43:51 +01:00
|
|
|
|
2023-08-15 21:38:37 +02:00
|
|
|
cache_memory_target=$(ynh_app_setting_get --app="$app" --key=cache_memory_target)
|
|
|
|
|
2023-10-17 17:11:26 +02:00
|
|
|
instance_federation_mode=$(ynh_app_setting_get --app="$app" --key=instance_federation_mode)
|
2022-12-17 22:05:20 +01:00
|
|
|
instance_expose_peers=$(ynh_app_setting_get --app="$app" --key=instance_expose_peers)
|
|
|
|
instance_expose_suspended=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended)
|
2023-02-18 20:20:14 +01:00
|
|
|
instance_expose_suspended_web=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended_web)
|
2022-12-17 22:05:20 +01:00
|
|
|
instance_expose_public_timeline=$(ynh_app_setting_get --app="$app" --key=instance_expose_public_timeline)
|
|
|
|
instance_deliver_to_shared_inboxes=$(ynh_app_setting_get --app="$app" --key=instance_deliver_to_shared_inboxes)
|
2023-08-15 21:38:37 +02:00
|
|
|
instance_inject_mastodon_version=$(ynh_app_setting_get --app="$app" --key=instance_inject_mastodon_version)
|
2022-12-17 22:05:20 +01:00
|
|
|
|
|
|
|
accounts_registration_open=$(ynh_app_setting_get --app="$app" --key=accounts_registration_open)
|
|
|
|
accounts_approval_required=$(ynh_app_setting_get --app="$app" --key=accounts_approval_required)
|
|
|
|
accounts_reason_required=$(ynh_app_setting_get --app="$app" --key=accounts_reason_required)
|
|
|
|
accounts_allow_custom_css=$(ynh_app_setting_get --app="$app" --key=accounts_allow_custom_css)
|
2023-08-15 21:38:37 +02:00
|
|
|
accounts_custom_css_length=$(ynh_app_setting_get --app="$app" --key=accounts_custom_css_length)
|
2022-03-15 02:14:16 +01:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
media_image_max_size=$(ynh_app_setting_get --app="$app" --key=media_image_max_size)
|
|
|
|
media_video_max_size=$(ynh_app_setting_get --app="$app" --key=media_video_max_size)
|
|
|
|
media_description_min_chars=$(ynh_app_setting_get --app="$app" --key=media_description_min_chars)
|
|
|
|
media_description_max_chars=$(ynh_app_setting_get --app="$app" --key=media_description_max_chars)
|
|
|
|
media_remote_cache_days=$(ynh_app_setting_get --app="$app" --key=media_remote_cache_days)
|
2022-12-17 22:05:20 +01:00
|
|
|
media_emoji_local_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_local_max_size)
|
|
|
|
media_emoji_remote_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_remote_max_size)
|
|
|
|
|
|
|
|
storage_backend=$(ynh_app_setting_get --app="$app" --key=storage_backend)
|
|
|
|
storage_s3_endpoint=$(ynh_app_setting_get --app="$app" --key=storage_s3_endpoint)
|
|
|
|
storage_s3_proxy=$(ynh_app_setting_get --app="$app" --key=storage_s3_proxy)
|
|
|
|
storage_s3_access_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_access_key)
|
|
|
|
storage_s3_secret_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_secret_key)
|
|
|
|
storage_s3_bucket=$(ynh_app_setting_get --app="$app" --key=storage_s3_bucket)
|
2022-03-26 00:43:51 +01:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
statuses_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_max_chars)
|
|
|
|
statuses_cw_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_cw_max_chars)
|
|
|
|
statuses_poll_max_options=$(ynh_app_setting_get --app="$app" --key=statuses_poll_max_options)
|
|
|
|
statuses_poll_option_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_poll_option_max_chars)
|
|
|
|
statuses_media_max_files=$(ynh_app_setting_get --app="$app" --key=statuses_media_max_files)
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2023-04-10 21:06:14 +02:00
|
|
|
smtp_host=$(ynh_app_setting_get --app="$app" --key=smtp_host)
|
|
|
|
smtp_port=$(ynh_app_setting_get --app="$app" --key=smtp_port)
|
|
|
|
smtp_username=$(ynh_app_setting_get --app="$app" --key=smtp_username)
|
|
|
|
smtp_password=$(ynh_app_setting_get --app="$app" --key=smtp_password)
|
|
|
|
smtp_from=$(ynh_app_setting_get --app="$app" --key=smtp_from)
|
|
|
|
smtp_disclose_recipients=$(ynh_app_setting_get --app="$app" --key=smtp_disclose_recipients)
|
|
|
|
|
2022-12-17 22:05:20 +01:00
|
|
|
advanced_cookies_samesite=$(ynh_app_setting_get --app="$app" --key=advanced_cookies_samesite)
|
|
|
|
advanced_rate_limit_requests=$(ynh_app_setting_get --app="$app" --key=advanced_rate_limit_requests)
|
|
|
|
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
test ! -d "$final_path" \
|
2021-08-15 21:48:06 +02:00
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2022-03-28 20:00:13 +02:00
|
|
|
ynh_system_user_create --username="$app" --home_dir="$final_path"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
|
|
|
|
|
|
|
# FIXME: this should be managed by the core in the future
|
|
|
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
|
|
|
# such that the appropriate users (e.g. maybe www-data) can access
|
|
|
|
# files in some cases.
|
|
|
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
|
|
|
|
# this will be treated as a security issue.
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
2022-03-28 20:00:13 +02:00
|
|
|
chown -R "$app:www-data" "$final_path"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE DATA DIRECTORY
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the data directory..." --weight=5
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$datadir" --not_mandatory
|
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
mkdir -p "$datadir"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
# FIXME: this should be managed by the core in the future
|
|
|
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
|
|
|
# such that the appropriate users (e.g. maybe www-data) can access
|
|
|
|
# files in some cases.
|
|
|
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
|
|
|
|
# this will be treated as a security issue.
|
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
2022-03-28 20:00:13 +02:00
|
|
|
chown -R "$app:www-data" "$datadir"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
# Define and install dependencies
|
2022-05-13 16:23:01 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-13 21:44:18 +01:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-13 21:44:18 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2022-03-28 20:00:13 +02:00
|
|
|
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd"
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name"
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name"
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name"
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name"
|
2022-03-13 21:44:18 +01:00
|
|
|
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2023-09-02 09:05:07 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
|
|
|
|
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
|
|
|
|
### downloaded from an upstream source, like a git repository.
|
|
|
|
### `ynh_setup_source` use the file conf/app.src
|
|
|
|
|
|
|
|
# detect_arch comes from _common.sh / personnal helpers
|
2023-09-02 19:41:15 +02:00
|
|
|
architecture="$(detect_arch)"
|
2023-09-02 09:05:07 +02:00
|
|
|
|
2023-09-05 17:05:06 +02:00
|
|
|
# compare if the system arch is different from the binary arch
|
2023-09-02 19:41:15 +02:00
|
|
|
# if so, download the correct binary
|
|
|
|
if [ "$architecture" != "$(file "$final_path"/gotosocial | cut -d ',' -f 2 | tr -d ' ')" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Migrating binary architecture..."
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" --keep="config.yaml"
|
|
|
|
fi
|
2023-09-02 09:05:07 +02:00
|
|
|
|
|
|
|
# FIXME: this should be managed by the core in the future
|
|
|
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
|
|
|
# such that the appropriate users (e.g. maybe www-data) can access
|
|
|
|
# files in some cases.
|
|
|
|
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder _
|
|
|
|
# this will be treated as a security issue.
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R "$app:www-data" "$final_path"
|
|
|
|
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
|
|
|
#=================================================
|
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
2022-03-15 03:29:42 +01:00
|
|
|
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
2022-03-28 20:00:13 +02:00
|
|
|
systemctl enable "$app.service" --quiet
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
2022-03-28 20:00:13 +02:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
|
2023-09-10 22:07:43 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE FAIL2BAN CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
|
|
|
|
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
|
|
|
|
ynh_systemd_action --action=restart --service_name=fail2ban
|
|
|
|
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2022-03-14 03:08:20 +01:00
|
|
|
# RELOAD NGINX
|
2021-08-15 21:48:06 +02:00
|
|
|
#=================================================
|
2022-03-14 03:08:20 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2021-08-15 21:48:06 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-03-14 03:07:20 +01:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|