#!/bin/bash

if [ -f /etc/eole/samba4-vars.conf ]; then
    . /etc/eole/samba4-vars.conf
else
    . /var/lib/lxc/addc/rootfs/etc/eole/samba4-vars.conf
fi

if [ "$AD_SERVER_ROLE" != "controleur de domaine" ]; then
    exit 0
fi

if [ "$AD_TYPE" = "scribe" ]; then
    function CreoleRun () {
        lxc-attach -n addc -- $1
    }
fi

CreoleRun "samba-tool dbcheck" domaine > /var/lib/eole/reports/samba-dbcheck.full_report
sed -e '/([0-9]\+ errors)/!d' -e 's/.* (\([0-9]\+ errors\))/\1/' /var/lib/eole/reports/samba-dbcheck.full_report > /var/lib/eole/reports/samba-dbcheck.log

exit 0
