mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone
103552
#!/bin/sh
103552
# Author: Jan Vcelak <jvcelak@redhat.com>
103552
103552
. /usr/libexec/openldap/functions
103552
103552
function help()
103552
{
103552
	error "usage: %s [-f config-file] [-F config-dir]\n" "`basename $0`"
103552
	exit 2
103552
}
103552
103552
load_sysconfig
103552
103552
while getopts :f:F: opt; do
103552
	case "$opt" in
103552
	f)
103552
		SLAPD_CONFIG_FILE="$OPTARG"
103552
		;;
103552
	F)
103552
		SLAPD_CONFIG_DIR="$OPTARG"
103552
		;;
103552
	*)
103552
		help
103552
		;;
103552
	esac
103552
done
103552
shift $((OPTIND-1))
103552
[ -n "$1" ] && help
103552
103552
# check source, target
103552
103552
if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
103552
	error "Source configuration file '%s' not found." "$SLAPD_CONFIG_FILE"
103552
	exit 1
103552
fi
103552
103552
if grep -iq '^dn: cn=config$' "$SLAPD_CONFIG_FILE"; then
103552
	SLAPD_CONFIG_FILE_FORMAT=ldif
103552
else
103552
	SLAPD_CONFIG_FILE_FORMAT=conf
103552
fi
103552
103552
if [ -d "$SLAPD_CONFIG_DIR" ]; then
103552
	if [ `find "$SLAPD_CONFIG_DIR" -maxdepth 0 -empty | wc -l` -eq 0 ]; then
103552
		error "Target configuration directory '%s' is not empty." "$SLAPD_CONFIG_DIR"
103552
		exit 1
103552
	fi
103552
fi
103552
103552
# perform the conversion
103552
103552
tmp_convert=`mktemp --tmpdir=/var/run/openldap`
103552
103552
if [ `id -u` -eq 0 ]; then
103552
	install -d --owner $SLAPD_USER --group `id -g $SLAPD_USER` --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
103552
	if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
103552
		run_as_ldap "/usr/sbin/slapadd -F \"$SLAPD_CONFIG_DIR\" -n 0 -l \"$SLAPD_CONFIG_FILE\"" &>>$tmp_convert
103552
	else
103552
		run_as_ldap "/usr/sbin/slaptest -f \"$SLAPD_CONFIG_FILE\" -F \"$SLAPD_CONFIG_DIR\"" &>>$tmp_convert
103552
	fi
103552
	retcode=$?
103552
else
103552
	error "You are not root! Permission will not be set."
103552
	install -d --mode 0750 "$SLAPD_CONFIG_DIR" &>>$tmp_convert
103552
	if [ $SLAPD_CONFIG_FILE_FORMAT = ldif ]; then
103552
		/usr/sbin/slapadd -F "$SLAPD_CONFIG_DIR" -n 0 -l "$SLAPD_CONFIG_FILE" &>>$tmp_convert
103552
	else
103552
		/usr/sbin/slaptest -f "$SLAPD_CONFIG_FILE" -F "$SLAPD_CONFIG_DIR" &>>$tmp_convert
103552
	fi
103552
	retcode=$?
103552
fi
103552
103552
if [ $retcode -ne 0 ]; then
103552
	error "Configuration conversion failed:"
103552
	cat $tmp_convert >&2
103552
fi
103552
103552
rm $tmp_convert
103552
exit $retcode