#! /bin/sh

domain=$(/sbin/e-smith/config get DomainName)
ldif="/home/e-smith/db/ldap/$domain.ldif"

if [ -e ldif ]
then
    old_ldif=$(readlink ldif)
    if [ "$old_ldif" != "$ldif" ]
    then
	# The domain name has changed, so we need to delete
	# the old directory contents. We still have the old
	# dump.
	find /var/lib/ldap -type f | xargs rm -f
    fi
fi

# Set up symlink for ldap dump at shutdown
ln -sf $ldif ./ldif

# Prime directory if required
if [ \! -f /var/lib/ldap/nextid.dbb -a -f $ldif ]
then
    sed 's/objectClass: group/objectClass: posixGroup/' < $ldif | \
      setuidgid ldap slapadd -c
fi

# Now run daemon
exec /usr/sbin/slapd -u ldap -d 0
