#!/bin/sh
#
# x-load-ldif
#
# Loads entries into LDAP server.
# The entries must not already exist if the -a flag is given.
# andrew.findlay@skills-1st.co.uk
#
# $Id$

PROG=`basename "$0"`

# Check for -a (add) flag
if test "$1" = "-a"
then
	AFLAG="-a"
	shift
fi

if test -z "$1"
then
	echo "usage: $PROG [-a] ldiff-filename" 1>&2
	exit 1
fi

# Find the vars file for this example
# The working directory must be in the example subtree

if test -f ../vars
then
	. ../vars
elif test -f vars
then
	. ./vars
else
	echo "$PROG: no vars file in . or .." 1>&2
	exit 1
fi

if test -z "${servername}" -o -z "${serverport}" -o -z "${basedn}"
then
	echo "$PROG: must define servername, serverport and basedn in the vars file" 1>&2
	exit 1
fi

if test -z "${manager}" -o -z "${password}"
then
	echo "$PROG: must define manager and password in the vars file" 1>&2
	exit 1
fi


ldapmodify -x -H ldap://${servername}:${serverport}/ \
	-c -D "${manager}" -w ${password} \
	$AFLAG -f $1

