#!/bin/sh

. ./config.sh

makedirs()
{
  BASE=$1
  DIRECTORIES="$BASE/$CONFIGDIR $BASE/$PLUGINDIR $BASE/$BINDIR $BASE/$DATADIR $BASE/$DOCDIR"
  for d in $DIRECTORIES; do
    mkdir -p $d
  done
}

for module in $MODULES; do
  echo -n "Create module $module..."
  #Read definitions
  . $module.list
  # Create directories
  makedirs $OUTDIR/$module
  #Copy config
  test "$CONFIGFILES" && cp -pR $CONFIGFILES "$OUTDIR/$module/$CONFIGDIR"
  #Copy plugins
  test "$PLUGINS" && cp -pR $PLUGINS "$OUTDIR/$module/$PLUGINDIR"
  #Copy binaries
  test "$BINARIES" && cp -pR $BINARIES "$OUTDIR/$module/$BINDIR"
  #Copy data
  test "$DATA" && cp -pR $DATA "$OUTDIR/$module/$DATADIR"
  #Copy documentation
  test "$DOC" && cp -pR $DOC "$OUTDIR/$module/$DOCDIR"
  echo "ok"
done

echo -n "deleting CVS stuff..."
# delete all CVS dirs and .cvsignore files
rm -rf `find $OUTDIR | grep -E '(CVS|.cvsignore)'`
echo "ok"
