Created
April 7, 2023 19:22
-
-
Save Fraserbc/e24a892d5cb154af8fd0961bc0621c53 to your computer and use it in GitHub Desktop.
Convert from .schema to a .ldif useable with ldapadd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
schema_file=$1 | |
if [[ -z $schema_file ]]; then | |
echo "$0 [Schema File]" | |
exit -1 | |
fi | |
schema=$(basename "${schema_file%.*}") | |
# Use slaptest to convert from .schema to ldif database | |
mkdir tmp/ | |
cp $schema_file tmp/$schema.schema | |
cd tmp/ | |
echo "include $schema.schema" > slapd.conf | |
mkdir slapd.d/ | |
slaptest -f slapd.conf -F slapd.d/ | |
# Extract the schema as ldif | |
slapcat -n 0 -F slapd.d/ -a "cn={*}$schema" \ | |
| grep -v ^structuralObjectClass: \ | |
| grep -v ^entryUUID: \ | |
| grep -v ^creatorsName: \ | |
| grep -v ^createTimestamp: \ | |
| grep -v ^entryCSN: \ | |
| grep -v ^modifiersName: \ | |
| grep -v ^modifyTimestamp: \ | |
| sed "s/{.*}$schema/$schema/" > $schema.ldif | |
mv $schema.ldif .. | |
# Cleanup files | |
cd .. | |
rm -r tmp/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment