|
| 1 | +#!/bin/sh |
| 2 | +set -eu |
| 3 | + |
| 4 | + |
| 5 | +readonly LDAP_BINDDN="cn=admin,dc=planetexpress,dc=com" |
| 6 | + |
| 7 | + |
| 8 | +file_exist() { |
| 9 | + local file=$1 |
| 10 | + |
| 11 | + [[ -e $file ]] |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +reconfigure_slapd() { |
| 16 | + echo "Reconfigure slapd..." |
| 17 | + cat <<EOL | debconf-set-selections |
| 18 | +slapd slapd/internal/generated_adminpw password ${LDAP_ADMIN_SECRET} |
| 19 | +slapd slapd/internal/adminpw password ${LDAP_ADMIN_SECRET} |
| 20 | +slapd slapd/password2 password ${LDAP_ADMIN_SECRET} |
| 21 | +slapd slapd/password1 password ${LDAP_ADMIN_SECRET} |
| 22 | +slapd slapd/dump_database_destdir string /var/backups/slapd-VERSION |
| 23 | +slapd slapd/domain string ${LDAP_DOMAIN} |
| 24 | +slapd shared/organization string ${LDAP_ORGANISATION} |
| 25 | +slapd slapd/backend string HDB |
| 26 | +slapd slapd/purge_database boolean true |
| 27 | +slapd slapd/move_old_database boolean true |
| 28 | +slapd slapd/allow_ldap_v2 boolean false |
| 29 | +slapd slapd/no_configuration boolean false |
| 30 | +slapd slapd/dump_database select when needed |
| 31 | +EOL |
| 32 | + |
| 33 | + dpkg-reconfigure -f noninteractive slapd |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +configure_tls() { |
| 38 | + echo "Configure TLS..." |
| 39 | + ldapmodify -Y EXTERNAL -H ldapi:/// -f /bootstrap/ldif/tls.ldif -Q |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +configure_logging() { |
| 44 | + echo "Configure logging..." |
| 45 | + ldapmodify -Y EXTERNAL -H ldapi:/// -f /bootstrap/ldif/logging.ldif -Q |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +load_initial_data() { |
| 50 | + echo "Load data..." |
| 51 | + data=$(find /bootstrap/ldif -maxdepth 1 -name \*_\*.ldif -type f | sort) |
| 52 | + for ldif in ${data}; do |
| 53 | + echo "Processing file ${ldif}..." |
| 54 | + ldapadd -x -D ${LDAP_BINDDN} -w ${LDAP_ADMIN_SECRET} -H ldapi:/// -f ${ldif} |
| 55 | + done |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +## Init |
| 60 | + |
| 61 | +reconfigure_slapd |
| 62 | + |
| 63 | +chown -R openldap:openldap /etc/ldap |
| 64 | +slapd -h "ldapi:///" -u openldap -g openldap |
| 65 | + |
| 66 | +configure_tls |
| 67 | +configure_logging |
| 68 | +load_initial_data |
| 69 | + |
| 70 | +kill -INT `cat /run/slapd/slapd.pid` |
| 71 | + |
| 72 | +exit 0 |
| 73 | + |
0 commit comments