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

194 lines
7.8 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
#=================================================
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
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2022-03-15 02:14:16 +01: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-26 00:21:52 +01:00
client_max_body_size=$(ynh_app_setting_get --app=$app --key=client_max_body_size)
2021-08-15 21:48:06 +02:00
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
2022-03-14 22:51:06 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
2022-03-15 02:14:16 +01:00
2022-03-26 00:43:51 +01:00
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
2022-03-15 02:14:16 +01:00
registration_open=$(ynh_app_setting_get --app=$app --key=registration_open)
registration_approval=$(ynh_app_setting_get --app=$app --key=registration_approval)
registration_reason=$(ynh_app_setting_get --app=$app --key=registration_reason)
2022-03-26 00:43:51 +01: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)
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
#=================================================
# 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
test ! -d $final_path \
|| 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)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# 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"
chown -R $app:www-data "$final_path"
#=================================================
# 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
mkdir -p $datadir
# 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"
chown -R $app:www-data "$datadir"
#=================================================
# 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
ynh_install_app_dependencies $pkg_dependencies
#=================================================
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
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
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
2021-08-15 21:48:06 +02:00
#=================================================
# RESTORE VARIOUS FILES
#=================================================
2022-03-15 03:29:42 +01:00
mkdir -p /var/log/$app
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
#=================================================
# 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-13 21:46:54 +01: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"
#=================================================
# 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"
#=================================================
# 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