#!/bin/bash

. ${TOOLKIT}-functions.sh

# cleanup old stuffs
#
purgefiles /usr/bin/ku-ldap* /usr/sbin/ku-smbldap-usersetup

out=/etc/ldap.secret
pass=`jtconf ldap.admin_password 2>/dev/null` && {
	echo "  WARN: writing LDAP admin password in $out"
	echo -n "$pass" >$out	|| { st=$?; rm -f $out ; exit $st; }
	chown root:root $out	|| { st=$?; rm -f $out ; exit $st; }
	chmod 600 $out		|| { st=$?; rm -f $out ; exit $st; }
}

if datadir=`jtconf ldap.datadir 2>/dev/null`
then
	# checkout (ignore errors)
	#
	if [ "X$(ls $datadir/ 2>/dev/null)" = "X" ]
	then
		echo "  LDAP: EMPTY DB, skipping ku-ldap-populate"
	else
		ku-ldap-populate || :
	fi
else
	echo " this is not the LDAP server, skipping 'ku-ldap-populate' phase"
fi


exit 0
