#!/bin/sh

usage() # $1 = exit status
{
    echo "Dumps pool meta data catalogue to YAML format."
    echo
    echo "Usage: $(basename $0) [OPTION]... DIR"
    echo
    echo "Valid options are:"
    echo "   -d <path to dcache installation>   default is /opt/d-cache"
    echo
    echo "DIR is the pool meta data directory."
    exit $1
}

DCACHE_HOME="/opt/d-cache/"

# Parse options
while getopts d: opt "$@"; do
    case $opt in
        d) DCACHE_HOME="$OPTARG";;
    esac
done
shift `expr $OPTIND - 1`

# Directory argument must be left
if [ $# -ne 1 ]; then
    usage 1
fi

. ${DCACHE_HOME}/share/lib/loadConfig.sh

CLASSPATH="$(getProperty dcache.paths.classpath)"

# Dump to yaml
"${JAVA}" -cp "${CLASSPATH}" org.dcache.pool.repository.meta.db.BerkeleyDBMetaDataRepository "$1"