#!/bin/sh

# This script modifies an LDIF so that if the content of the dumped data
# is the same, the LDIF should also be the same.  Its primary use is to
# be able to use diff(1) on LDIF's without spurious changes.

# to be used as a filter, e.g. ldapsearch ... | ldif-normalise | foo
LINIFY="`dirname $0`/ldif-linify"

# 1. linify, remove non-objects, order entries by dn, unlinify
# 2-3. sort the attributes in each entry alphabetically, except dn at start
"$LINIFY" | grep '||dn::* ' | LC_ALL=C sort -f | sed 's/||/\n/g' | \
sed 's/^dn::* /00&/' | awk '/^$/{n++};{printf "%05d %s\n", n, $0}' | \
LC_ALL=C sort | cut -c7- | sed 's/^00\(dn::* \)/\1/'

