#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers

ynh_script_progression "Restauration des fichiers..."
ynh_restore "$install_dir"
ynh_restore "$data_dir"

ynh_script_progression "Reconfiguration des permissions..."
chown -R "$app:$app" "$install_dir" "$data_dir"
chmod 600 "$install_dir/config.py"
chmod 700 "$data_dir/keys"

ynh_script_progression "Restauration des règles sudo..."
ynh_config_add --template="sudoers" --destination="/etc/sudoers.d/$app"
chmod 440 "/etc/sudoers.d/$app"

ynh_script_progression "Restauration du service systemd..."
ynh_config_add_systemd
yunohost service add "$app" \
    --description="Backup Manager ($instance_name)" \
    --log="$data_dir/logs/backupmanager.log"

ynh_script_progression "Restauration de nginx..."
ynh_config_add_nginx

ynh_script_progression "Démarrage du service..."
ynh_systemctl --action="start" --service="$app"

ynh_script_progression "Restauration terminée !"
