#!/bin/bash
set -e
ldif_path=`python3 -c "from eoleaaf.config import ldif_path; print(ldif_path)"`
timestampfilename="${ldif_path}/$(date +%s)"
/usr/sbin/parseaaf.py all
/usr/sbin/gentemplate.py complet
aaf_type=`python3 -c "from eoleaaf.config import aaf_type; print(aaf_type)"`

if [ $aaf_type == "openldap" ]
then
    echo "traitements specifiques au module thot"
    mkdir -p "$timestampfilename"
    /usr/sbin/genldif.py all $timestampfilename #all.ldif
    /usr/share/eole/posttemplate/02-annuaire instance force
    CreoleService slapd stop
    for ldif in `ls "$timestampfilename/"*.ldif`;do
        echo "Importation de $ldif"
        nice -n -19 ionice -c2 -n0 su openldap -s /bin/bash -c "slapadd -cqs -f /etc/ldap/slapd.conf -l \"$ldif\" > /dev/null"
    done
    CreoleService slapd start
    reconfigure
fi
if [ $aaf_type == "samba4" ]
then
    echo "traitements specifiques au module seth"
    export TDB_NO_FSYNC=1
    /usr/sbin/importsamba.py
fi



