#!/bin/bash

# Récupère les infos de l'application.
app=lutim
final_path=$(sudo yunohost app setting $app final_path)
domain=$(sudo yunohost app setting $app domain)

# The parameter $1 is the uncompressed restore directory location
backup_dir=$1/apps/$app

# Restore sources & data
sudo cp -a $backup_dir/sources/. $final_path

# Restore Nginx and YunoHost parameters
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
sudo cp -a $backup_dir/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf


# Restauration des fichiers du script init
sudo cp -a $backup_dir/init.d_lutim /etc/init.d/lutim
sudo cp -a $backup_dir/default_lutim /etc/default/lutim

# Restauration du fichier du cron
sudo cp -a $backup_dir/cron_$app /etc/cron.d/$app


# Restart webserver
sudo service nginx reload
