#!/bin/bash #------------------------------------------------------------------------------ # readConfig function readConfig { confDir=. cfgFile=${confDir}/ldap.conf if [ ! -f $cfgFile ]; then echo "The conf file '$cfgFile' does not exist !" exit 1 fi # read config file . $cfgFile } #------------------------------------------------------------------------------ # getNextuidNumber function getNextUidNumber { # read all uidNumber ldapsearch -x -LLL -H $LDAP_SRV -b "$LDAP_BASE" -D "$LDAP_MANAGER_USER" -w $LDAP_MANAGER_PASS \ uidNumber | grep -v dn | grep -v '^$' > /tmp/ldap_uid.tmp #grep -v '^$' empty line # delete uidNumber form the file sed -i -e 's/^uidNumber: //' /tmp/ldap_uid.tmp # create an array while IFS= read -r line; do ldap_array=("${ldap_array[@]}" $line) done < /tmp/ldap_uid.tmp # delete temporary file rm -rf /tmp/ldap_uid.tmp # sort the array to find the highest uidNumber max=0 for uidNum in ${ldap_array[@]}; do if (( $uidNum > $max )); then max=$uidNum fi done # increases the max by 1 next_uidNumber=`expr $max + 1` } # check if ldapsearch exist ldapsearch_path=$(command -v ldapsearch) if [ "$?" == "1" ]; then echo "ldapsearch doesn't exist. Please install openldap-clients package" exit 1 fi slappasswd_path=$(command -v slappasswd ) if [ "$?" == "1" ]; then echo "ldapsearch doesn't exist. Please install openldap-servers package" exit 1 fi