1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gotosocial_ynh.git synced 2024-09-03 19:16:06 +02:00
gotosocial_ynh/scripts/restore

275 lines
13 KiB
Text
Raw Normal View History

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
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_clean_setup () {
2021-08-15 21:48:06 +02:00
#### 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
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_abort_if_errors
2021-08-15 21:48:06 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? app="$YNH_APP_INSTANCE_NAME"
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir)
2022-03-15 02:14:16 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? landing_page_user=$(ynh_app_setting_get --app="$app" --key=landing_page_user)
2022-12-17 22:05:20 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain)
#REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port)
#REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path)
2022-03-15 02:14:16 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size)
2022-03-26 00:21:52 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
#REMOVEME? db_user=$(ynh_app_setting_get --app="$app" --key=db_user)
#REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd)
2022-03-15 02:14:16 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? data_dir=$(ynh_app_setting_get --app="$app" --key=data_dir)
2022-03-26 00:43:51 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? cache_memory_target=$(ynh_app_setting_get --app="$app" --key=cache_memory_target)
2023-08-15 21:38:37 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? instance_federation_mode=$(ynh_app_setting_get --app="$app" --key=instance_federation_mode)
#REMOVEME? instance_expose_peers=$(ynh_app_setting_get --app="$app" --key=instance_expose_peers)
#REMOVEME? instance_expose_suspended=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended)
#REMOVEME? instance_expose_suspended_web=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended_web)
#REMOVEME? instance_expose_public_timeline=$(ynh_app_setting_get --app="$app" --key=instance_expose_public_timeline)
#REMOVEME? instance_deliver_to_shared_inboxes=$(ynh_app_setting_get --app="$app" --key=instance_deliver_to_shared_inboxes)
#REMOVEME? instance_inject_mastodon_version=$(ynh_app_setting_get --app="$app" --key=instance_inject_mastodon_version)
2022-12-17 22:05:20 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? accounts_registration_open=$(ynh_app_setting_get --app="$app" --key=accounts_registration_open)
#REMOVEME? accounts_approval_required=$(ynh_app_setting_get --app="$app" --key=accounts_approval_required)
#REMOVEME? accounts_reason_required=$(ynh_app_setting_get --app="$app" --key=accounts_reason_required)
#REMOVEME? accounts_allow_custom_css=$(ynh_app_setting_get --app="$app" --key=accounts_allow_custom_css)
#REMOVEME? accounts_custom_css_length=$(ynh_app_setting_get --app="$app" --key=accounts_custom_css_length)
2022-03-15 02:14:16 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? media_image_max_size=$(ynh_app_setting_get --app="$app" --key=media_image_max_size)
#REMOVEME? media_video_max_size=$(ynh_app_setting_get --app="$app" --key=media_video_max_size)
#REMOVEME? media_description_min_chars=$(ynh_app_setting_get --app="$app" --key=media_description_min_chars)
#REMOVEME? media_description_max_chars=$(ynh_app_setting_get --app="$app" --key=media_description_max_chars)
#REMOVEME? media_remote_cache_days=$(ynh_app_setting_get --app="$app" --key=media_remote_cache_days)
#REMOVEME? media_emoji_local_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_local_max_size)
#REMOVEME? media_emoji_remote_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_remote_max_size)
2022-12-17 22:05:20 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? storage_backend=$(ynh_app_setting_get --app="$app" --key=storage_backend)
#REMOVEME? storage_s3_endpoint=$(ynh_app_setting_get --app="$app" --key=storage_s3_endpoint)
#REMOVEME? storage_s3_proxy=$(ynh_app_setting_get --app="$app" --key=storage_s3_proxy)
#REMOVEME? storage_s3_access_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_access_key)
#REMOVEME? storage_s3_secret_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_secret_key)
#REMOVEME? storage_s3_bucket=$(ynh_app_setting_get --app="$app" --key=storage_s3_bucket)
2022-03-26 00:43:51 +01:00
2024-01-08 17:50:43 +01:00
#REMOVEME? statuses_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_max_chars)
#REMOVEME? statuses_cw_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_cw_max_chars)
#REMOVEME? statuses_poll_max_options=$(ynh_app_setting_get --app="$app" --key=statuses_poll_max_options)
#REMOVEME? statuses_poll_option_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_poll_option_max_chars)
#REMOVEME? statuses_media_max_files=$(ynh_app_setting_get --app="$app" --key=statuses_media_max_files)
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? oidc_enabled=$(ynh_app_setting_get --app="$app" --key=oidc_enabled)
#REMOVEME? oidc_idp_name=$(ynh_app_setting_get --app="$app" --key=oidc_idp_name)
#REMOVEME? oidc_skip_verification=$(ynh_app_setting_get --app="$app" --key=oidc_skip_verification)
#REMOVEME? oidc_issuer=$(ynh_app_setting_get --app="$app" --key=oidc_issuer)
#REMOVEME? oidc_client_id=$(ynh_app_setting_get --app="$app" --key=oidc_client_id)
#REMOVEME? oidc_client_secret=$(ynh_app_setting_get --app="$app" --key=oidc_client_secret)
#REMOVEME? oidc_link_existing=$(ynh_app_setting_get --app="$app" --key=oidc_link_existing)
2024-01-08 17:50:43 +01:00
#REMOVEME? smtp_host=$(ynh_app_setting_get --app="$app" --key=smtp_host)
#REMOVEME? smtp_port=$(ynh_app_setting_get --app="$app" --key=smtp_port)
#REMOVEME? smtp_username=$(ynh_app_setting_get --app="$app" --key=smtp_username)
#REMOVEME? smtp_password=$(ynh_app_setting_get --app="$app" --key=smtp_password)
#REMOVEME? smtp_from=$(ynh_app_setting_get --app="$app" --key=smtp_from)
#REMOVEME? smtp_disclose_recipients=$(ynh_app_setting_get --app="$app" --key=smtp_disclose_recipients)
2024-01-08 17:50:43 +01:00
#REMOVEME? advanced_cookies_samesite=$(ynh_app_setting_get --app="$app" --key=advanced_cookies_samesite)
#REMOVEME? advanced_rate_limit_requests=$(ynh_app_setting_get --app="$app" --key=advanced_rate_limit_requests)
2022-12-17 22:05:20 +01:00
2021-08-15 21:48:06 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? test ! -d "$install_dir" \
|| ynh_die --message="There is already a directory: $install_dir "
2021-08-15 21:48:06 +02:00
#=================================================
# 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
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? 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)
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir"
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
2024-01-08 17:50:43 +01:00
ynh_restore_file --origin_path="$install_dir"
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.
2024-01-08 17:50:43 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
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
2024-01-08 17:50:43 +01:00
ynh_restore_file --origin_path="$data_dir" --not_mandatory
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
mkdir -p "$data_dir"
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.
2024-01-08 17:50:43 +01:00
chmod 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
2021-08-15 21:48:06 +02:00
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=5
2021-08-15 21:48:06 +02:00
# Define and install dependencies
2024-01-08 17:50:43 +01:00
#REMOVEME? 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
#=================================================
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5
2021-08-15 21:48:06 +02:00
2024-01-08 17:50:43 +01:00
#REMOVEME? ynh_psql_test_if_first_run
#REMOVEME? 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
#=================================================
# 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-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
2024-01-08 17:50:43 +01:00
if [ "$architecture" != "$(file "$install_dir"/gotosocial | cut -d ',' -f 2 | tr -d ' ')" ]
2023-09-02 19:41:15 +02:00
then
ynh_script_progression --message="Migrating binary architecture..."
# Download, check integrity, uncompress and patch the source from app.src
2024-01-08 17:50:43 +01:00
ynh_setup_source --dest_dir="$install_dir" --keep="config.yaml"
2023-09-02 19:41:15 +02:00
fi
# 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.
2024-01-08 17:50:43 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
2021-08-15 21:48:06 +02:00
#=================================================
# RESTORE VARIOUS FILES
#=================================================
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"
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
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
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