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
2021-03-07 17:35:19 +01:00

83 lines
2.9 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Import common cmd
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# 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)
app_version=$(ynh_app_upstream_version)
app_main_version=$(echo $app_version | cut -d'-' -f1)
app_sub_version=$(echo $app_version | cut -d'-' -f2)
#=================================================
# 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_source
# 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_restore_uwsgi_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"
ynh_permission_update --permission="main" --remove="all_users" --add=$admin
# 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='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log"
systemctl reload nginx
sleep 10
ynh_script_progression --message="Restoration completed for $app" --last