#!/bin/bash msg(){ ${VERBOSE:-true} && echo ${@} ; } assert(){ [[ $? -eq 0 ]] || { [[ -n ${1} ]] && msg ${@} ; 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 msg "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}") msg "I: slapd running with PID ${PIDFILE}" [[ -n "${OPENLDAP_ADMIN_PASSWORD}" ]] assert "E: please set non-empty password in OPENLDAP_ADMIN_PASSWORD and retry." HASHED_PW=$(slappasswd -h {SSHA} -s "${OPENLDAP_ADMIN_PASSWORD}") [[ -n "${HASHED_PW}" ]] assert "E: password hash unexpectedly empty!" msg "I: Setting administrator password..." ldapmodify -Y EXTERNAL -H ldapi:/// <