#!/bin/sh
# This script respects its own file name to find out the CDD it belongs to
# Names should be builded like <CDD>-task-files
# The intended use is to create according symlinks to this file

NAME=`basename $0`
if [ _"$NAME" = _"cdd-task-lister" ] ; then
    exit
fi

# the base dir for CDD conffiles, where script expects to find dirs named like
# each registered CDDs
CONFBASE=${CONFBASE:-/etc/cdd}

# a local per CDD conf is sourced later, after argument parsing
. ${CONFBASE}/cdd.conf

CDD=`echo $NAME | sed 's/-task-files//'`

# Now that we know the selected CDD, we can check if there is a local
# configuration for it (ie different backend from the default one)
test -n "${CDD}" -a  -f ${CONFBASE}/${CDD}/${CDD}.conf &&
	. ${CONFBASE}/${CDD}/${CDD}.conf

if [ -n "${DBBACKEND}" ]; then
	set -e
	checkCDD ${CDD} || cddFail $? "Custom distribution ${CDD} does not exist"
fi

# Check consistency of passed argouments
if [ $# -ne 1 ] ; then
    # printing usage makes no sense here
    exit 67 # EX_USAGE
fi

cat /usr/share/cdd/tasksel/${CDD}/$1
