PREIN
/bin/sh
# create ldap user and group
getent group ldap &>/dev/null || groupadd -r -g 55 ldap
getent passwd ldap &>/dev/null || \
useradd -r -g ldap -u 55 -d /var/lib/ldap -s /sbin/nologin -c "OpenLDAP server" ldap
if [ $1 -eq 2 ]; then
# package upgrade
old_version=$(rpm -q --qf=%{version} openldap-servers)
new_version=2.4.35
if [ "$old_version" != "$new_version" ]; then
touch /var/lib/ldap/rpm_upgrade_openldap &>/dev/null
fi
fi
exit 0
PREUN
/bin/sh
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
/usr/bin/systemctl --no-reload disable slapd.service > /dev/null 2>&1 || :
/usr/bin/systemctl stop slapd.service > /dev/null 2>&1 || :
fi
POSTIN
/bin/sh
/sbin/ldconfig
if [ $1 -eq 1 ] ; then
# Initial installation
/usr/bin/systemctl preset slapd.service >/dev/null 2>&1 || :
fi
# generate sample TLS certificate for server (will not replace)
/usr/libexec/openldap/generate-server-cert.sh -o &>/dev/null || :
# generate/upgrade configuration
if [ ! -f /etc/openldap/slapd.d/cn=config.ldif ]; then
if [ -f /etc/openldap/slapd.conf ]; then
/usr/libexec/openldap/convert-config.sh &>/dev/null
mv /etc/openldap/slapd.conf /etc/openldap/slapd.conf.bak
else
/usr/libexec/openldap/convert-config.sh -f /usr/share/openldap-servers/slapd.ldif &>/dev/null
fi
fi
start_slapd=0
# upgrade the database
if [ -f /var/lib/ldap/rpm_upgrade_openldap ]; then
if /usr/bin/systemctl --quiet is-active slapd.service; then
/usr/bin/systemctl stop slapd.service
start_slapd=1
fi
/usr/libexec/openldap/upgrade-db.sh &>/dev/null
rm -f /var/lib/ldap/rpm_upgrade_openldap
fi
# conversion from /etc/sysconfig/ldap to /etc/sysconfig/slapd
if [ $1 -eq 2 ]; then
# we expect that 'ldap' will be renamed to 'ldap.rpmsave' after removing the old package
[ -r /etc/sysconfig/ldap ] || exit 0
source /etc/sysconfig/ldap &>/dev/null
new_urls=
[ "$SLAPD_LDAP" != "no" ] && new_urls="$new_urls ldap:///"
[ "$SLAPD_LDAPI" != "no" ] && new_urls="$new_urls ldapi:///"
[ "$SLAPD_LDAPS" == "yes" ] && new_urls="$new_urls ldaps:///"
[ -n "$SLAPD_URLS" ] && new_urls="$new_urls $SLAPD_URLS"
failure=0
cp -f /etc/sysconfig/slapd /etc/sysconfig/slapd.rpmconvert
sed -i '/^#\?SLAPD_URLS=/s@.*@SLAPD_URLS="'"$new_urls"'"@' /etc/sysconfig/slapd.rpmconvert &>/dev/null || failure=1
[ -n "$SLAPD_OPTIONS" ] && \
sed -i '/^#\?SLAPD_OPTIONS=/s@.*$@SLAPD_OPTIONS="'"$SLAPD_OPTIONS"'"@' /etc/sysconfig/slapd.rpmconvert &>/dev/null || failure=1
if [ $failure -eq 0 ]; then
mv -f /etc/sysconfig/slapd.rpmconvert /etc/sysconfig/slapd
else
rm -f /etc/sysconfig/slapd.rpmconvert
fi
fi
# restart after upgrade
if [ $1 -ge 1 ]; then
if [ $start_slapd -eq 1 ]; then
/usr/bin/systemctl start slapd.service &>/dev/null || :
else
/usr/bin/systemctl condrestart slapd.service &>/dev/null || :
fi
fi
exit 0
POSTUN
/bin/sh
/sbin/ldconfig
/usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
/usr/bin/systemctl try-restart slapd.service >/dev/null 2>&1 || :
fi
Triggers
openldap-servers <
2.4.26-6
/bin/sh
# migration from SysV to systemd
/usr/bin/systemd-sysv-convert --save slapd &>/dev/null || :
/usr/sbin/chkconfig --del slapd &>/dev/null || :
/usr/bin/systemctl try-restart slapd.service &>/dev/null || :
libdb
/bin/sh
# libdb upgrade (setup for %triggerun)
if [ $2 -eq 2 ]; then
# we are interested in minor version changes (both versions of libdb are installed at this moment)
if [ "$(rpm -q --qf="%{version}\n" libdb | sed 's/\.[0-9]*$//' | sort -u | wc -l)" != "1" ]; then
touch /var/lib/ldap/rpm_upgrade_libdb
else
rm -f /var/lib/ldap/rpm_upgrade_libdb
fi
fi
exit 0
libdb
/bin/sh
# libdb upgrade (finish %triggerin)
if [ -f /var/lib/ldap/rpm_upgrade_libdb ]; then
if /usr/bin/systemctl --quiet is-active slapd.service; then
/usr/bin/systemctl stop slapd.service
start=1
else
start=0
fi
/usr/libexec/openldap/upgrade-db.sh &>/dev/null
rm -f /var/lib/ldap/rpm_upgrade_libdb
[ $start -eq 1 ] && /usr/bin/systemctl start slapd.service &>/dev/null
fi
exit 0