#!/bin/sh

old_ver="$2"
datadir='/var/lib/openldap/openldap-data'

if [ "$(apk version -t "$old_ver" '2.6.0-r0')" = '<' ]; then
	for back in bdb hdb; do
		if apk info -eq openldap-back-$back; then
			if find "$datadir" -iname "*.$back" 2>/dev/null | grep -q .; then
				cat >&2 <<-EOF
				*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
				*! Found *.$back files in $datadir!
				*! OpenLDAP 2.6+ doesn't provide deprecated BDB and HDB backends anymore.
				*! You have to migrate your database to MDB backend before upgrading
				*! openldap!
				*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
				EOF
				exit 1
			fi
		fi
	done
fi

exit 0
