ldapsaisie/lsexample/restore_lsexample
Benjamin Renard e099a27533 Add dynamic groups support (with cache members attributes)
Add LSaddon dyngroup with feature to handle update static cache members
attributes on users or dyngroup URI changes. The update process could
also be runned using CLI update_dyngroups_members_cache command
(allowing cron task configuration).

LSexample also evoluate to add example of dynamic groups implementation.
On this occasion, the restore_lsexample script was completely rewrited.
2021-07-21 19:42:22 +02:00

71 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
#
# Script to restore LSexample from source
#
# Installation:
# ln -s /path/to/ldapsaisie/src/lsexample/restore_lsexample /usr/local/sbin/
#
# Configuration
SRC_DIR="$( realpath "$( dirname "$( realpath "$0" )" )/../" )"
SLAPD_CONF_DIR=/etc/ldap/slapd.d
SLAPD_DB_DIR=/var/lib/ldap
SLAPD_USER=openldap
SLAPD_GROUP=openldap
SYS_SCHEMA_DIR=/etc/ldap/schema
# Deducted configuration
SLAPD_CONF_LDIF="$SRC_DIR/lsexample/slapd-config.ldif"
LS_SCHEMA_LDIF="$SRC_DIR/lsexample/schema/ls.ldif"
SAMBA_SCHEMA_LDIF="$SRC_DIR/lsexample/schema/samba.ldif"
SLAPD_DB_LDIF="$SRC_DIR/lsexample/db.ldif"
#
# Start restoration
#
# Stop slapd
/usr/sbin/service slapd stop
# Purge old DB data
rm -fr $SLAPD_DB_DIR $SLAPD_CONF_DIR
mkdir -p $SLAPD_DB_DIR $SLAPD_CONF_DIR
# Install slapd.d configuration
slapadd -n0 -F $SLAPD_CONF_DIR -l $SLAPD_CONF_LDIF
# Install schemas
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/core.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/cosine.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/nis.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/inetorgperson.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/ppolicy.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SYS_SCHEMA_DIR/dyngroup.ldif
slapadd -n0 -F/etc/ldap/slapd.d -l$SAMBA_SCHEMA_LDIF
slapadd -n0 -F/etc/ldap/slapd.d -l$LS_SCHEMA_LDIF
# Fix rights on restored data
chown $SLAPD_USER:$SLAPD_GROUP -R $SLAPD_DB_DIR $SLAPD_CONF_DIR
# Start slapd
/usr/sbin/service slapd start
cat << EOF > /etc/ldapvi.conf
profile default
unpaged-help: yes
ldap-conf: yes
profile config
host: ldapi://
sasl-mech: EXTERNAL
base: cn=config
profile ls
host: ldapi://
sasl-mech: EXTERNAL
base: o=ls
EOF
# Add database
ldapvi -p config --verbose --ldapmodify --ldapvi --add $SLAPD_DB_LDIF