mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Simplify ldap restore hook
This commit is contained in:
parent
8c351ad176
commit
956e860ff7
1 changed files with 47 additions and 54 deletions
|
@ -1,15 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
backup_dir="${1}/conf/ldap"
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
|
||||
# We need to execute this script as root, since the ldap
|
||||
# service will be shut down during the operation (and sudo
|
||||
# won't be available)
|
||||
/bin/bash $(readlink -f $0) $1
|
||||
|
||||
else
|
||||
|
||||
service slapd stop || true
|
||||
systemctl stop slapd
|
||||
|
||||
# Create a directory for backup
|
||||
TMPDIR="/tmp/$(date +%s)"
|
||||
|
@ -28,7 +21,7 @@ else
|
|||
mv "${TMPDIR}/ldap" /var/lib/ldap)
|
||||
chown -R openldap: /etc/ldap/slapd.d /var/lib/ldap
|
||||
|
||||
service slapd start
|
||||
systemctl start slapd
|
||||
rm -rf "$TMPDIR"
|
||||
|
||||
# Print an error message and exit
|
||||
|
@ -42,7 +35,8 @@ else
|
|||
cp -a "${backup_dir}/ldap.conf" /etc/ldap/ldap.conf
|
||||
cp -a "${backup_dir}/slapd.ldif" /etc/ldap/slapd.ldif
|
||||
# Legacy thing but we need it to force the regen-conf in case of it exist
|
||||
cp -a "${backup_dir}/slapd.conf" /etc/ldap/slapd.conf
|
||||
[ ! -e "${backup_dir}/slapd.conf" ] \
|
||||
|| cp -a "${backup_dir}/slapd.conf" /etc/ldap/slapd.conf
|
||||
slapadd -F /etc/ldap/slapd.d -b cn=config \
|
||||
-l "${backup_dir}/cn=config.master.ldif" \
|
||||
|| die 1 "Unable to restore LDAP configuration"
|
||||
|
@ -58,4 +52,3 @@ else
|
|||
|
||||
service slapd start
|
||||
rm -rf "$TMPDIR"
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue