1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pgadmin_ynh.git synced 2024-09-03 19:56:38 +02:00
pgadmin_ynh/scripts/restore
2020-07-29 22:48:16 +02:00

80 lines
2.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Import common cmd
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh
# LOAD SETTINGS
ynh_script_progression --message="Loading settings..."
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_name=$(ynh_app_setting_get --app $app --key db_name)
db_user=$(ynh_app_setting_get --app $app --key db_user)
db_pwd=$(ynh_app_setting_get --app $app --key db_pwd)
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# Install dependance
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
ynh_install_app_dependencies $dependances
# Create user
ynh_script_progression --message="Recreating the dedicated system user..."
ynh_system_user_create --username $pgadmin_user --home_dir /var/lib/$app
# Restore all config and data
ynh_script_progression --message="Restoring files..." --weight=5
ynh_restore
# Check that the good python version is installed
# If not upgrade the source
install_sources
# POPULATE THE DATABASE
ynh_script_progression --message="Reconfiguring Postgresql database..."
ynh_psql_test_if_first_run
ynh_psql_execute_as_root \
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
# Restore systemd configuration
ynh_script_progression --message="Reconfiguring application..."
ynh_check_global_uwsgi_config
systemctl enable "uwsgi-app@$app.service"
#=================================================
# GENERIC FINALIZATION
#=================================================
# Set the permission
ynh_script_progression --message="Protecting directory..."
set_permission
# Restrict access to admin only
ynh_script_progression --message="Configuring permissions..."
yunohost app addaccess --users=$admin $app
# Configuration de logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile /var/log/pgadmin
# reload uwsgi and nginx
ynh_script_progression --message="Starting pgadmin services..." --weight=3
ynh_systemd_action --service_name "uwsgi-app@$app.service" \
--line_match "WSGI app 0 \(mountpoint='$path_url'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log"
systemctl reload nginx
ynh_script_progression --message="Restoration completed for $app" --last