#!/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 #================================================= ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) data_path=$(ynh_app_setting_get --app=$app --key=data_path) allow_multimedia_write=$(ynh_app_setting_get --app=$app --key=allow_multimedia_write) port=$(ynh_app_setting_get --app=$app --key=port) backend_port=$(ynh_app_setting_get --app=$app --key=port) similarity_port=$(ynh_app_setting_get --app=$app --key=similarity_port) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " test ! -d $data_path \ || ynh_die --message="There is already a directory: $data_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$data_path #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the 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 $final_path/data_models $data_path/data_models #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files set_permissions #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=60 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies 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 NODE.JS #================================================= ynh_script_progression --message="Restoring Node.js..." --weight=1 set_node_vars #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC RESTORATION #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=2 ynh_psql_test_if_first_run 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 VARIOUS FILES #================================================= ynh_restore_file --origin_path="/var/log/$app" #================================================= # 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 #================================================= # 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 #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # 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" #================================================= # 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