#!/bin/bash

source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

ynh_script_progression --message="Restoring the main directory..." --weight=1
ynh_restore_file -o "$install_dir"

ynh_script_progression --message="Restoring the web server configuration..." --weight=1
ynh_restore_file -o "/etc/nginx/conf.d/$domain.d/$app.conf"

ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_systemd_action --action=enable

ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app

ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --action=start

ynh_script_progression --message="Reloading the web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload

ynh_script_progression --message="Restoration completed" --last