#!/bin/bash assert(){ [[ $? -eq 0 ]] || { [[ -n ${1} ]] && echo ${@} ; exit 1 ; } } # from https://github.com/dinkel/docker-openldap/blob/master/entrypoint.sh: # When not limiting the open file descritors limit, the memory consumption of # slapd is absurdly high. See https://github.com/docker/docker/issues/8231 ulimit -n 8192 echo "I: running slapd for initial setup..." slapd -u openldap -g openldap -h ldapi:/// assert "E: openldap died unexpectedly!" PIDFILE=$(ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b "cn=config" -s base \ "" olcPidFile | grep olcPidFile | awk "{print $2}") echo "I: slapd running with PID ${PIDFILE}" [[ -n "${LDAP_CONFIG_PASSWORD}" ]] assert "E: please set non-empty password in LDAP_CONFIG_PASSWORD and retry." HASHED_PW=$(slappasswd -h "{SSHA}" -s "${LDAP_CONFIG_PASSWORD}") echo "I: Setting administrator password..." ldapmodify -Y EXTERNAL -H ldapi:/// <