#!/bin/sh
#
# x-start-ldap
#
# Start the directory server

PROG=`basename "$0"`

if test ! -f slapd.conf -a -f openldap/slapd.conf
then
	cd openldap
fi

if test ! -f slapd.conf
then
	echo "$PROG: must be run from the directory containing slapd.conf" 1>&2
	exit 1
fi

# Get the config for this example
. ../vars

# There is a symlink to the chosen slapd program in the global sbin directory
PATH=../../sbin:$PATH
export PATH

# Make the database directory if necessary
if test ! -d openldap-db
then
	mkdir openldap-db
fi

# Create a DB_CONFIG if necessary
if test ! -f openldap-db/DB_CONFIG
then
	# Use local version if there is one
	# otherwise use generic version
	if test -f DB_CONFIG
	then
		cp DB_CONFIG openldap-db/DB_CONFIG
	else
		cp ../../etc/DB_CONFIG openldap-db/DB_CONFIG
	fi
fi

# Start the server
#
slapd	-f slapd.conf \
	-h "ldap://:${serverport}/" \
	-n "${servername}:${serverport}" \
	"$@"

