source: n4d-ldap/trunk/fuentes/install/usr/sbin/reset-slapd @ 149

Last change on this file since 149 was 149, checked in by hectorgh, 4 years ago

adding project files

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/bin/bash
2
3usage(){
4        echo $0
5}
6
7die(){
8    echo $@
9    exit 1
10}
11
12
13capture_diagnostics() {                                                 # {{{
14# Run the command passed and capture the diagnostic output in a temporary
15# file. You can dump that file using release_diagnostics.
16
17        # Create the temporary file
18        local tmpfile
19        tmpfile=`mktemp`
20        exec 7<>"$tmpfile"
21        rm "$tmpfile"
22
23        # Run the program and capture stderr. If the program fails the
24        # function fails with the same status.
25        echo $tmpfile
26        "$@" 2>&7 || { rc=$?; echo $rc ; return $rc ;}
27}
28
29
30# You must root
31[ $UID -eq 0 ] || die "You must a root"
32
33# Load default configuration
34if [ -f "/etc/default/slapd" ]; then
35        . /etc/default/slapd
36fi
37
38# Load the default location of the slapd config file
39if [ -z "$SLAPD_CONF" ]; then
40    SLAPD_CONF="/etc/ldap/slapd.d"
41else
42    if [ ! -d $SLAPD_CONF ]; then
43        SLAPD_CONF="/etc/ldap/slapd.d"
44        sed -i "s%SLAPD_CONF=.*%SLAPD_CONF=$SLAPD_CONF%g" /etd/default/slapd
45    fi
46fi
47
48#Check if all things are correctly
49    [ -e "/usr/share/slapd/slapd.init.ldif" ] || die "Template file /usr/share/slapd/slapd.init.ldif not exists. Please reinstall slapd package"
50
51#
52# TODO
53# This variable must be calculated
54#
55SLAPD_DB_PATH="/var/lib/ldap"
56
57/etc/init.d/slapd stop
58
59#Check if directories has correct permissions
60
61rm -rf ${SLAPD_CONF} || true
62mkdir -p -m 0755 $SLAPD_CONF
63chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_CONF || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
64
65
66# Void all directories
67
68
69rm -rf $SLAPD_DB_PATH || true
70mkdir -m 0700 $SLAPD_DB_PATH || true
71chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_DB_PATH || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
72
73SLAPD_RUN="/run/slapd"
74rm -rf $SLAPD_RUN || true
75mkdir -m 0755 $SLAPD_RUN || true
76chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_RUN || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
77
78backend="hdb"
79backendobjectclass="olcHdbConfig"
80basedn='dc=ma5,dc=lliurex,dc=net'
81adminpass='{SSHA}o4UvsuAZNXNkZPgPwgktIvhEli8IdhFJ'
82
83initldif=`mktemp -t slapadd.XXXXXX`
84cat /usr/share/slapd/slapd.init.ldif > ${initldif}
85
86# Change some defaults
87sed -i -e "s|@BACKEND@|$backend|g" ${initldif}
88sed -i -e "s|@BACKENDOBJECTCLASS@|$backendobjectclass|g" ${initldif}
89sed -i -e "s|@SUFFIX@|$basedn|g" ${initldif}
90sed -i -e "s|@PASSWORD@|$adminpass|g" ${initldif}
91sed -i -e "s|olcSizeLimit: 500|olcSizeLimit: unlimited|g" ${initldif}
92
93capture_diagnostics slapadd -F "${SLAPD_CONF}" -b "cn=config" -l "${initldif}" || die "Have an error when load init configuration on config directory"
94chown -R ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_CONF || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
95/etc/init.d/slapd start
Note: See TracBrowser for help on using the repository browser.