1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/librephotos_ynh.git synced 2024-09-03 19:36:12 +02:00
librephotos_ynh/scripts/restore

193 lines
8.2 KiB
Bash
Executable file

#!/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
#=================================================
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#REMOVEME? allow_multimedia_write=$(ynh_app_setting_get --app=$app --key=allow_multimedia_write)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? backend_port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? similarity_port=$(ynh_app_setting_get --app=$app --key=similarity_port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1
#REMOVEME? ynh_webpath_available --domain=$domain --path=$path \
|| ynh_die --message="Path not available: ${domain}${path}"
#REMOVEME? test ! -d $install_dir \
|| ynh_die --message="There is already a directory: $install_dir "
test ! -d $data_path \
|| ynh_die --message="There is already a directory: $data_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
#=================================================
# RESTORE THE APP DATA DIR
#=================================================
ynh_script_progression --message="Restoring the app data directory..." --weight=1
ynh_restore_file --origin_path="$data_path" --not_mandatory
mkdir -p $data_path/protected_media/{thumbnails_big,square_thumbnails,square_thumbnails_small,faces}
mkdir -p $data_path/data/nextcloud_media
mkdir -p $data_path/matplotlib
ln -s $install_dir/data_models $data_path/data_models
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
#REMOVEME? ynh_system_user_create --username=$app --home_dir=$data_path
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_restore_file --origin_path="/var/log/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=60
# Define and install dependencies
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
set_permissions
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=2
#REMOVEME? ynh_psql_test_if_first_run
#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE NODE.JS
#=================================================
ynh_script_progression --message="Restoring Node.js..." --weight=1
set_node_vars
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configurations..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app-backend.service"
systemctl enable $app-backend.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-frontend.service"
systemctl enable $app-frontend.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-image-similarity.service"
systemctl enable $app-image-similarity.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-worker.service"
systemctl enable $app-worker.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
yunohost service add $app-backend --description="Backend for librephotos" --log="/var/log/$app/gunicorn_django.log"
yunohost service add $app-frontend --description="Frontend for librephotos" --log="/var/log/$app/$app-frontend.log"
yunohost service add $app-image-similarity --description="Image similarity server for librephotos" --log="/var/log/$app/image_similarity.log"
yunohost service add $app-worker --description="Worker for librephotos" --log="/var/log/$app/$app-worker.log"
#=================================================
# START SYSTEMD SERVICES
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/gunicorn_django.log" --line_match="Listening at: http"
ynh_systemd_action --service_name=$app-frontend --action="start" --log_path="systemd" --line_match="INFO: Accepting connections at http:"
ynh_systemd_action --service_name=$app-image-similarity --action="start" --log_path="/var/log/$app/image_similarity.log"
ynh_systemd_action --service_name=$app-worker --action="start" --log_path="/var/log/$app/$app-worker.log"
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=1
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
if [ $allow_multimedia_write -eq 1 ]; then
ynh_multimedia_addaccess $app
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last