From 42914d26c5addae027cc382ec035a687cd3aaf6d Mon Sep 17 00:00:00 2001
From: Evilham <cvs@evilham.com>
Date: Mon, 9 Dec 2019 19:59:15 +0100
Subject: [PATCH] [new-type] __openldap_server: sudo make nico.happy.

---
 cdist/conf/type/__openldap_server/manifest | 53 ++++++++++++----------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/cdist/conf/type/__openldap_server/manifest b/cdist/conf/type/__openldap_server/manifest
index e10432d6..ffd92626 100644
--- a/cdist/conf/type/__openldap_server/manifest
+++ b/cdist/conf/type/__openldap_server/manifest
@@ -9,11 +9,10 @@ slapd_modules=$(cat "${__object}/parameter/module" || true)
 schemas=$(cat "${__object}/parameter/schema")
 
 
-OS="$(cat "${__global}/explorer/os")"
+os="$(cat "${__global}/explorer/os")"
 
 # Setup OS-dependent vars
-# TODO: treat other OS better, defaulting to Debian-like
-case "${OS}" in
+case "${os}" in
     freebsd)
         PKGS="openldap-server"
         ETC="/usr/local/etc"
@@ -26,7 +25,7 @@ case "${OS}" in
             slapd_modules="back_mdb back_monitor"
         fi
         ;;
-    *)
+    debian|ubuntu|devuan)
         PKGS="slapd ldap-utils"
         ETC="/etc"
         SLAPD_DIR="/etc/ldap"
@@ -37,6 +36,10 @@ case "${OS}" in
             slapd_modules="back_mdb ppolicy syncprov back_monitor"
         fi
         ;;
+    *)
+        echo "Don't know the openldap defaults for: $os" >&2
+        exit 1
+        ;;
 esac
 
 
@@ -106,28 +109,32 @@ done
 # TODO: Implement __start_on_boot for BSD
 require="__package/slapd" __start_on_boot slapd
 
-# TODO: treat other OS better. Defaulting to Debian-like.
-if [ "${OS}" != "freebsd" ]; then
-    require="__package/slapd" __line rm_slapd_conf \
-       --file ${ETC}/default/slapd \
-       --regex 'SLAPD_CONF=.*' \
-       --state absent
+case "${os}" in
+    debian|ubuntu|devuan)
+        require="__package/slapd" __line rm_slapd_conf \
+               --file ${ETC}/default/slapd \
+               --regex 'SLAPD_CONF=.*' \
+               --state absent
 
-    require="__package/slapd" __line rm_slapd_services \
-       --file ${ETC}/default/slapd \
-       --regex 'SLAPD_SERVICES=.*' \
-       --state absent
+        require="__package/slapd" __line rm_slapd_services \
+               --file ${ETC}/default/slapd \
+               --regex 'SLAPD_SERVICES=.*' \
+               --state absent
 
-    require="__line/rm_slapd_conf" __line add_slapd_conf \
-       --file ${ETC}/default/slapd \
-       --line 'SLAPD_CONF=${SLAPD_DIR}/slapd.conf' \
-       --state present
+        require="__line/rm_slapd_conf" __line add_slapd_conf \
+               --file ${ETC}/default/slapd \
+               --line 'SLAPD_CONF=${SLAPD_DIR}/slapd.conf' \
+               --state present
 
-    require="__line/rm_slapd_services" __line add_slapd_services \
-       --file ${ETC}/default/slapd \
-       --line "SLAPD_SERVICES=\"ldap://localhost/ ldap://${name}/\"" \
-       --state present
-fi
+        require="__line/rm_slapd_services" __line add_slapd_services \
+               --file ${ETC}/default/slapd \
+               --line "SLAPD_SERVICES=\"ldap://localhost/ ldap://${name}/\"" \
+               --state present
+        ;;
+    *)
+        # Nothing to do here, move on.
+        ;;
+esac
 
 
 if [ -z "${_skip_letsencrypt_cert}" ]; then