Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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 [ ! -z $LDAPURL ] && LDAP_AUTH="$LDAP_AUTH -H $LDAPURL"
17
18 XML=${XML:-$1}
19
20 if [ -z "$XML" ] || [  ! -r $XML ]; then
21      echo "usage: $0 xmlfile"
22      exit 1
23 fi
24
25 NAME=`basename $XML .xml`
26 LDIF=/tmp/$NAME.ldif
27
28 # add the top level record, if needed
29 ldapsearch $LDAP_AUTH -b $LDAP_BASE > /dev/null 2>&1 ||
30     ldapadd $LDAP_AUTH -f $LUSTRE/conf/top.ldif
31
32 # If this config already exists, then delete it
33 ldapsearch $LDAP_AUTH -b config=$NAME,$LDAP_BASE > /dev/null 2>&1 && 
34     ldapdelete $LDAP_AUTH -r config=$NAME,$LDAP_BASE
35
36 4xslt -D config=$NAME $XML $LUSTRE/conf/lustre2ldif.xsl  > $LDIF
37
38 echo "Loading config to 'config=$NAME,$LDAP_BASE' ..."
39 ldapadd $LDAP_AUTH -f $LDIF
40
41 rm -f $LDIF