#!/bin/bash -e

WHERE="/home/backup/samba/"

echo "Restauration des fichiers"

systemctl stop samba-ad-dc
rsync -av --delete ${WHERE}samba/ /var/lib/samba
systemctl start samba-ad-dc

sysvol_ntacl=${WHERE}sysvol_ntacl.tar.gz

sed -i 's/full_audit:success = connect//g' /etc/samba/smb.conf

echo "Restauration des autorisations NTACL pour SYSVOL"

python3 -c """
from optparse import OptionParser
from samba.samdb import SamDB
from samba.auth import system_session
from samba import getopt
from samba.ntacls import backup_restore
parse = OptionParser()
lp = getopt.SambaOptions(parse).get_loadparm()
creds = getopt.CredentialsOptions(parse).get_credentials(lp)
samdb = SamDB(session_info=system_session(), credentials=creds, lp=lp)
backup_restore('${sysvol_ntacl}', lp.get('path', 'sysvol'), samdb, lp.configfile)
"""

exit 0
