From 400b2b8444806a77ed32acf1e342a637e78c4451 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 30 Dec 2024 21:11:14 +1100 Subject: [PATCH] Enable set up of environment with data in specific dirs, used by PLA --- docker/Dockerfile | 2 +- docker/init-docker | 59 +++++++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9dd6155..9a612eb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,7 +14,7 @@ ADD tls /etc/openldap/tls RUN sed -i -e 's/dc=my-domain,dc=com/c=AU/' /etc/openldap/slapd.ldif \ && sed -i -e 's/openldap-data/data/' /etc/openldap/slapd.ldif \ && mv /var/lib/openldap/openldap-data /var/lib/openldap/data \ - && mkdir /etc/openldap/slapd.d /etc/openldap/schema/add.d /etc/openldap/schema/modify.d \ + && mkdir /etc/openldap/slapd.d /etc/openldap/schema/add.d /etc/openldap/schema/modify.d /etc/openldap/schema/data.d \ && ln -s ../misc.ldif /etc/openldap/schema/add.d/01-misc.ldif \ && ln -s ../custom/samba.ldif /etc/openldap/schema/add.d/02-samba.ldif \ && ln -s ../custom/wurley.ldif /etc/openldap/schema/add.d/10-wurley.ldif \ diff --git a/docker/init-docker b/docker/init-docker index 722349d..db4d7cb 100755 --- a/docker/init-docker +++ b/docker/init-docker @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e NAME="OPENLDAP" @@ -9,6 +9,11 @@ SLAPD_INIT=${SLAPD_INIT:="/etc/openldap/slapd.ldif"} SLAPD_DEBUG=${SLAPD_DEBUG:-0} SLAPD_URLS=${SLAPD_URLS:-"ldapi:/// ldap:/// ldaps:///"} SLAPD_OPTIONS="${SLAPD_OPTIONS} -d ${SLAPD_DEBUG}" +SLAPD_SCHEMA_BASE=${SLAPD_SCHEMA_BASE:-"/etc/openldap/schema"} + +SLAPD_CUSTOM_BASES=${SLAPD_CUSTOM_BASES:-"/ldap/bases"} +SLAPD_CUSTOM_SCHEMA=${SLAPD_CUSTOM_SCHEMA:-"/ldap/schema"} +SLAPD_CUSTOM_DATA=${SLAPD_CUSTOM_DATA:-"/ldap/data"} function stop { echo "Stopping ${NAME}" @@ -19,7 +24,7 @@ function mp() { set +e mountpoint -q $1 local mp=$? - set -e + set - return ${mp} } @@ -29,36 +34,56 @@ if [ -z "$@" ]; then # If /etc/openldap is an external mount point if [ -e ${SLAPD_CONFIG}/olcDatabase=\{0\}config.ldif ]; then echo "* [${SLAPD_CONFIG}] exists, ready to go" - else + else + shopt -s nullglob echo "- [${SLAPD_CONFIG}] rebuilding schema configuration" + # Check if we have any custom schema to add + [ -d ${SLAPD_SCHEMA_BASE}/add.d ] || mkdir ${SLAPD_SCHEMA_BASE}/add.d + if [ -d ${SLAPD_CUSTOM_SCHEMA} ]; then + for f in ${SLAPD_CUSTOM_SCHEMA}/*.ldif; do + echo "- Adding SCHEMA item [${f}]" + ln -s ${f} ${SLAPD_SCHEMA_BASE}/add.d + done + fi + + # Check if we have any custom data to add + [ -d ${SLAPD_SCHEMA_BASE}/data.d ] || mkdir ${SLAPD_SCHEMA_BASE}/data.d + if [ -d ${SLAPD_CUSTOM_DATA} ]; then + for f in ${SLAPD_CUSTOM_DATA}/*.ldif; do + echo "- Adding DATA item [${f}]" + ln -s ${f} ${SLAPD_SCHEMA_BASE}/data.d + done + fi + + # Add our bases + for f in ${SLAPD_CUSTOM_BASES}/*.ldif; do + echo "- Processing BASE item [${f}]" + echo "" >> ${SLAPD_INIT} + cat ${f} >> ${SLAPD_INIT} + done slapadd -n 0 -F ${SLAPD_BASE} -l ${SLAPD_INIT} # Add custom schema definitions - for f in /etc/openldap/schema/add.d/*.ldif; do - [ -e "${f}" ] || continue - - echo "- Processing SCHEMA item [${f}]" + for f in ${SLAPD_SCHEMA_BASE}/add.d/*.ldif; do + echo "- Processing SCHEMA add item [${f}]" slapadd -b cn=config -l ${f} done - for f in /etc/openldap/schema/modify.d/*.ldif; do - [ -e "${f}" ] || continue - - echo "- Processing SCHEMA item [${f}]" + [ -d ${SLAPD_SCHEMA_BASE}/modify.d ] || mkdir ${SLAPD_SCHEMA_BASE}/modify.d + for f in ${SLAPD_SCHEMA_BASE}/modify.d/*.ldif; do + echo "- Processing SCHEMA modify item [${f}]" slapmodify -b cn=config -l ${f} done # Add custom data definitions - for f in /etc/openldap/data/init.d/*.ldif; do - [ -e "${f}" ] || continue - - echo "- Processing DATA items [${f}]" - slapadd -b cn=config -l ${f} + for i in 01 03 04 05 06 07; do + echo "- Processing DATABASE item(s) for DB [${i}]" + cat ${SLAPD_SCHEMA_BASE}/data.d/${i}-* | slapadd -n ${i} done - chown -R ldap:ldap ${SLAPD_CONFIG}* + chown -R ldap:ldap ${SLAPD_CONFIG}* /var/lib/openldap/ fi [ -x /usr/sbin/slapd ] && /usr/sbin/slapd -u ldap -h "${SLAPD_URLS}" $SLAPD_OPTIONS &