ldapsaisie/lsexample/restore_lsexample

72 lines
1.7 KiB
Text
Raw Normal View History

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
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
SYS_SCHEMA_DIR=/etc/ldap/schema
2021-02-24 20:12:03 +01:00
# 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"
2021-02-24 20:12:03 +01:00
#
# Start restoration
#
# Stop slapd
/usr/sbin/service slapd stop
2021-02-24 20:12:03 +01:00
# Purge old DB data
rm -fr $SLAPD_DB_DIR $SLAPD_CONF_DIR
mkdir -p $SLAPD_DB_DIR $SLAPD_CONF_DIR
2021-02-24 20:12:03 +01:00
# Install slapd.d configuration
slapadd -n0 -F $SLAPD_CONF_DIR -l $SLAPD_CONF_LDIF
2021-02-24 20:12:03 +01: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
chown $SLAPD_USER:$SLAPD_GROUP -R $SLAPD_DB_DIR $SLAPD_CONF_DIR
2021-02-24 20:12:03 +01:00
# 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