2021-02-24 20:12:03 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Script to restore LSexample from source
|
|
|
|
#
|
|
|
|
# Installation:
|
|
|
|
# ln -s /path/to/ldapsaisie/src/lsexample/restore_lsexample /usr/local/sbin/
|
|
|
|
#
|
|
|
|
|
|
|
|
# Configuration
|
2021-02-24 20:20:11 +01:00
|
|
|
SRC_DIR="$( realpath "$( dirname "$( realpath "$0" )" )/../" )"
|
2021-02-24 20:12:03 +01:00
|
|
|
SLAPD_CONF_DIR=/etc/ldap/slapd.d
|
|
|
|
SLAPD_DB_DIR=/var/lib/ldap
|
|
|
|
SLAPD_USER=openldap
|
|
|
|
SLAPD_GROUP=openldap
|
2021-07-21 19:42:22 +02:00
|
|
|
SYS_SCHEMA_DIR=/etc/ldap/schema
|
2021-02-24 20:12:03 +01:00
|
|
|
|
|
|
|
# Deducted configuration
|
2021-07-21 19:42:22 +02:00
|
|
|
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"
|
2021-02-24 20:12:03 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Start restoration
|
|
|
|
#
|
|
|
|
|
|
|
|
# Stop slapd
|
2021-07-21 19:42:22 +02:00
|
|
|
/usr/sbin/service slapd stop
|
2021-02-24 20:12:03 +01:00
|
|
|
|
|
|
|
# Purge old DB data
|
2021-07-21 19:42:22 +02:00
|
|
|
rm -fr $SLAPD_DB_DIR $SLAPD_CONF_DIR
|
|
|
|
mkdir -p $SLAPD_DB_DIR $SLAPD_CONF_DIR
|
2021-02-24 20:12:03 +01:00
|
|
|
|
2021-07-21 19:42:22 +02:00
|
|
|
# Install slapd.d configuration
|
|
|
|
slapadd -n0 -F $SLAPD_CONF_DIR -l $SLAPD_CONF_LDIF
|
2021-02-24 20:12:03 +01:00
|
|
|
|
2021-07-21 19:42:22 +02:00
|
|
|
# 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
|
2021-02-24 20:12:03 +01:00
|
|
|
|
|
|
|
# Fix rights on restored data
|
2021-07-21 19:42:22 +02:00
|
|
|
chown $SLAPD_USER:$SLAPD_GROUP -R $SLAPD_DB_DIR $SLAPD_CONF_DIR
|
2021-02-24 20:12:03 +01:00
|
|
|
|
|
|
|
# Start slapd
|
2021-07-21 19:42:22 +02:00
|
|
|
/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
|