#!/bin/bash
set -e
rootdn=`python3 -c "from eoleaaf.config import rootdn;print(rootdn)"`
rootdnpasswd=`python3 -c "from eoleaaf.config import rootdnpasswd;print(rootdnpasswd)"`
ldif_path=`python3 -c "from eoleaaf.config import ldif_path; print(ldif_path)"`
timestamppath="${ldif_path}/$(date +%s)"
/usr/sbin/parsedelta.py
/usr/sbin/gentemplate.py delta
aaf_type=`python3 -c "from eoleaaf.config import aaf_type; print(aaf_type)"`

if [ $aaf_type == "openldap" ]
then
    mkdir -p "$timestamppath"
    /usr/sbin/genldif.py delta "$timestamppath"
    ldap_delta_create_filename=`python3 -c "from eoleaaf.config import ldap_delta_create_filename;print(ldap_delta_create_filename)"`
    ldap_delta_update_filename=`python3 -c "from eoleaaf.config import ldap_delta_update_filename;print(ldap_delta_update_filename)"`
    ldap_delta_delete_filename=`python3 -c "from eoleaaf.config import ldap_delta_delete_filename;print(ldap_delta_delete_filename)"`
    ldapadd -c -D "$rootdn" -w "$rootdnpasswd" -f $timestamppath/$ldap_delta_create_filename
    ldapmodify -c -D "$rootdn" -w "$rootdnpasswd" -f $timestamppath/$ldap_delta_delete_filename
    ldapmodify -c -D "$rootdn" -w "$rootdnpasswd" -f $timestamppath/$ldap_delta_update_filename
fi
if [ $aaf_type == "samba4" ]
then
    echo "traitements specifiques au module seth"
	export TDB_NO_FSYNC=1
    /usr/sbin/importsamba.py
fi
