add custom ldif dir
diff --git a/README.md b/README.md
index 14589c9..77ddf5e 100644
--- a/README.md
+++ b/README.md
@@ -107,20 +107,28 @@
#### Seed ldap database with ldif
This image can load ldif files at startup with either `ldapadd` or `ldapmodify`.
-Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif/`
-directory. Files containing `changeType:` attributes will be loaded with `ldapmodify`.
+Mount `.ldif` in `/container/service/slapd/assets/config/bootstrap/ldif` directory if you want to overwrite image default boostrap ldif files or in `/container/service/slapd/assets/config/bootstrap/ldif/custom` (recommended) to extend image config.
-The startup script provide some substitution in bootstrap ldif files: `{{
-LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
+Files containing `changeType:` attributes will be loaded with `ldapmodify`.
+
+The startup script provide some substitution in bootstrap ldif files:
+`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported. Other `{{ * }}`
substitution are left as is.
Since startup script modifies `ldif` files, you **must** add `--copy-service`
-argument to entrypoint.
+argument to entrypoint if you don't want to overwrite them.
- docker run \
+
+ # single file example:
+ docker run \
--volume ./bootstrap.ldif:/container/service/slapd/assets/config/bootstrap/ldif/50-bootstrap.ldif \
osixia/openldap:1.1.9 --copy-service
+ #directory example:
+ docker run \
+ --volume ./lidf:/container/service/slapd/assets/config/bootstrap/ldif/custom \
+ osixia/openldap:1.1.9 --copy-service
+
### Use an existing ldap database
This can be achieved by mounting host directories as volume.
diff --git a/image/service/slapd/assets/config/bootstrap/ldif/custom/README.md b/image/service/slapd/assets/config/bootstrap/ldif/custom/README.md
new file mode 100644
index 0000000..d47a1d5
--- /dev/null
+++ b/image/service/slapd/assets/config/bootstrap/ldif/custom/README.md
@@ -0,0 +1,9 @@
+Add your custom ldif files here if you don't want to overwrite image default boostrap ldif.
+at run time you can also mount a data volume with your ldif files to /container/service/slapd/assets/config/bootstrap/ldif/custom
+
+The startup script provide some substitution in bootstrap ldif files:
+`{{LDAP_BASE_DN }}` and `{{ LDAP_BACKEND }}` values are supported.
+Other `{{ * }}` substitution are left as is.
+
+Since startup script modifies `ldif` files,
+you **must** add `--copy-service` argument to entrypoint if you don't want to overwrite them.
diff --git a/image/service/slapd/startup.sh b/image/service/slapd/startup.sh
index 5ac279e..bc11f44 100755
--- a/image/service/slapd/startup.sh
+++ b/image/service/slapd/startup.sh
@@ -62,6 +62,17 @@
fi
}
+ function ldap_add_or_modify (){
+ local LDIF_FILE=$1
+ sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $LDIF_FILE
+ sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $LDIF_FILE
+ if grep -iq changetype $LDIF_FILE ; then
+ ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $LDIF_FILE 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $LDIF_FILE 2>&1 | log-helper debug
+ else
+ ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $LDIF_FILE |& log-helper debug
+ fi
+ }
+
#
# Global variables
#
@@ -224,16 +235,16 @@
sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/02-security.ldif
# process config files (*.ldif) in bootstrap directory (do no process files in subdirectories)
- log-helper info "Add bootstrap ldif..."
+ log-helper info "Add image bootstrap ldif..."
for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif -mindepth 1 -maxdepth 1 -type f -name \*.ldif | sort); do
log-helper debug "Processing file ${f}"
- sed -i "s|{{ LDAP_BASE_DN }}|${LDAP_BASE_DN}|g" $f
- sed -i "s|{{ LDAP_BACKEND }}|${LDAP_BACKEND}|g" $f
- if grep -iq changetype $f ; then
- ldapmodify -Y EXTERNAL -Q -H ldapi:/// -f $f 2>&1 | log-helper debug || ldapmodify -h localhost -p 389 -D cn=admin,$LDAP_BASE_DN -w $LDAP_ADMIN_PASSWORD -f $f 2>&1 | log-helper debug
- else
- ldapadd -Y EXTERNAL -Q -H ldapi:/// -f $f |& log-helper debug
- fi
+ ldap_add_or_modify "$f"
+ done
+
+ log-helper info "Add custom bootstrap ldif..."
+ for f in $(find ${CONTAINER_SERVICE_DIR}/slapd/assets/config/bootstrap/ldif/custom -type f -name \*.ldif | sort); do
+ log-helper debug "Processing file ${f}"
+ ldap_add_or_modify "$f"
done
# read only user