2017-11-14 16:05:26 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2022-03-13 15:22:35 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2018-01-31 16:08:58 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2020-11-17 23:51:51 +01:00
|
|
|
source ../settings/scripts/experimental_helper.sh
|
|
|
|
source ../settings/scripts/_common.sh
|
2017-11-14 16:05:26 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-11-14 16:05:26 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
2017-11-14 16:05:26 +01:00
|
|
|
# LOAD SETTINGS
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
|
|
|
|
2020-11-28 19:24:23 +01:00
|
|
|
app_version=$(ynh_app_upstream_version)
|
|
|
|
app_main_version=$(echo $app_version | cut -d'-' -f1)
|
|
|
|
app_sub_version=$(echo $app_version | cut -d'-' -f2)
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
pgadmin_user="$app"
|
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
2022-03-13 15:22:35 +01:00
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
2018-01-31 16:08:58 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..."
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
# Create the dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$pgadmin_user --home_dir=$final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=5
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
|
|
|
|
|
|
|
|
# Define and install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2020-07-29 22:48:16 +02:00
|
|
|
# Check that the good python version is installed
|
|
|
|
# If not upgrade the source
|
2020-07-31 22:56:34 +02:00
|
|
|
install_source
|
2020-07-29 22:48:16 +02:00
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# POPULATE THE DATABASE
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Reconfiguring Postgresql database..."
|
2017-11-16 21:10:21 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_psql_execute_as_root --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring various files..."
|
2019-06-06 22:39:49 +02:00
|
|
|
|
2022-03-14 22:13:23 +01:00
|
|
|
ynh_restore_file --origin_path="/var/lib/pgadmin"
|
|
|
|
|
2019-06-06 22:39:49 +02:00
|
|
|
# Restore systemd configuration
|
|
|
|
ynh_script_progression --message="Reconfiguring application..."
|
2021-03-07 17:35:19 +01:00
|
|
|
ynh_restore_uwsgi_service
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Set the permission
|
2019-06-11 22:27:54 +02:00
|
|
|
ynh_script_progression --message="Protecting directory..."
|
2017-11-16 21:10:21 +01:00
|
|
|
set_permission
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the logrotate configuration..."
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2020-07-30 22:55:35 +02:00
|
|
|
sleep 10
|
2019-06-06 22:39:49 +02:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|