Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / utils / load_ldap.sh
1 #!/bin/bash
2 #
3 # Load a lustre config xml into an openldap database.
4 # See https://projects.clusterfs.com/lustre/LustreLDAP
5 # for more details.
6 #
7 # Usage: load_ldap.sh <xml_file>
8 set -e
9
10 LDAP_BASE=${LDAP_BASE:-fs=lustre}
11 LDAP_ROOTDN=${LDAP_ROOTDN:-cn=Manager,fs=lustre}
12 LDAP_PW=${LDAP_PW:-secret}
13 LDAP_AUTH="-x -D $LDAP_ROOTDN -w $LDAP_PW"
14 LUSTRE=${LUSTRE:-`dirname $0`/..}
15
16 if [ -f $LUSTRE/Makefile.am ]; then
17   CONFDIR=$LUSTRE/conf
18 else
19   CONFDIR=/usr/lib/lustre
20 fi
21
22 TOP=$CONFDIR/top.ldif
23 XSL=$CONFDIR/lustre2ldif.xsl
24
25 [ ! -z $LDAPURL ] && LDAP_AUTH="$LDAP_AUTH -H $LDAPURL"
26
27 XML=${XML:-$1}
28
29 if [ -z "$XML" ] || [  ! -r $XML ]; then
30      echo "usage: $0 xmlfile"
31      exit 1
32 fi
33
34 NAME=`basename $XML .xml`
35 LDIF=/tmp/$NAME.ldif
36
37 # add the top level record, if needed
38 ldapsearch $LDAP_AUTH -b $LDAP_BASE > /dev/null 2>&1 ||
39     ldapadd $LDAP_AUTH -f $TOP 
40
41 # If this config already exists, then delete it
42 ldapsearch $LDAP_AUTH -b config=$NAME,$LDAP_BASE > /dev/null 2>&1 && 
43     ldapdelete $LDAP_AUTH -r config=$NAME,$LDAP_BASE
44
45 4xslt -D config=$NAME $XML $XSL   > $LDIF
46
47 echo "Loading config to 'config=$NAME,$LDAP_BASE' ..."
48 ldapadd $LDAP_AUTH -f $LDIF
49
50 rm -f $LDIF