#!/usr/bin/env bash

set -e

eval `ultrapossum-config init`
trap "`eval ultrapossum-config term`" 0

soname=`getvalue $DIRECTORY/ultrapossum-environ SLAPD_BERKLEYDB_SONAME 2> /dev/null`

if test "x$soname" = "x"; then
  soname=$SLAPD_BERKLEYDB_SONAME_OLD
fi

progress "Configuring berkleydb environment for $soname... "
case "x$soname" in
  xlibdb-4.2.so)
    dump="db4.2_dump"
    archive="db4.2_archive"
  ;;
  xlibdb-4.1.so)
    dump="db4.1_dump"
    archive="db4.1_archive"
  ;;
  x)
    echo "E: can't recognize what version of berkley db is used" 1>&2
    exit 1
  ;;
  x*)
    echo "E: Unsupported soname: $soname" 1>&2
    exit 1
  ;;
esac
progress "Configuring berkleydb environment for $soname... done"

for f in `$archive -h $DIRECTORY -sa`
do
  progress "Dumping $f... "
  $dump $f | gzip -c > `basename $f`.gz
  progress "Dumping $f... done"
done

