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
2019-06-07 22:08:36 +02:00

79 lines
2.6 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)
ynh_print_OFF
db_pwd=$(ynh_app_setting_get --app $app --key db_pwd)
ynh_print_ON
#=================================================
# 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
# POPULATE THE DATABASE
ynh_script_progression --message="Reconfiguring Postgresql database..."
ynh_psql_test_if_first_run
ynh_print_OFF
ynh_psql_execute_as_root \
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
ynh_print_ON
# Restore systemd configuration
ynh_script_progression --message="Reconfiguring application..."
systemctl daemon-reload
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 /var/log/pgadmin
# reload uwsgi and nginx
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