#!/bin/bash . .env user_exists() { res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ') [ -n "$res" ] } group_exists() { res=$(ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(cn=$1)(objectClass=groupOfNames))" | grep cn: | cut -f2 -d' ') [ -n "$res" ] } is_posix() { res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ') [ -n "$res" ] } get_posix_number() { echo $(( $(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1)) }