#!/bin/bash

# WOW this is a hack

if [ -z "$DLG_ROOT" ]; then
  export DLG_ROOT=`pwd`
fi

if [ -r $DLG_ROOT/config ]; then
  . $DLG_ROOT/config
else
  echo "Error! Unable to source global config!"
  echo ""
  exit 1
fi

if [ -r $DLG_ROOT/SCRIPTS/dropline-functions.sh ]; then
  . $DLG_ROOT/SCRIPTS/dropline-functions.sh
else
  echo "Error! Unable to source dropline-functions.sh!"
  echo ""
  exit 1
fi

if [ -z $@ ]; then
less $DLG_ROOT/ChangeLog.Dagmar
exit
cat <<XusagedocsX
Exportengine Utlity v0.90
  Usage: $0 [packagename]

  Exports copies of the "important" parts of the build engine to the named
  directory.

XusagedocsX
exit
fi

DESTDIR=$@

  spew 1 "Destination directory: $DESTDIR"

  spewdo "removedir $DESTDIR/SCRIPTS"
  spewdo "removedir $DESTDIR/SCRIPTS"
  spewdo "mkdir -p $DESTDIR/SCRIPTS"
  spewdo "mkdir -p $DESTDIR/SCRIPTS"

OLDPWD=`pwd`
cd $DLG_ROOT
for filename in `find SCRIPTS -name ChangeLog | awk -F/ '{ print $2 }'`; do
  spewdo "mkdir -p $DESTDIR/SCRIPTS/$filename"
  spewdo "mkdir -p $DESTDIR/SOURCES/$filename"
  spewdo "cp -adR SCRIPTS/$filename/* $DESTDIR/SCRIPTS/$filename"
  spewdo "cp -adR SOURCES/$filename/* $DESTDIR/SOURCES/$filename 2>/dev/null"
done

spewdo "cp SCRIPTS/dropline-functions.sh $DESTDIR/SCRIPTS/"
spewdo "cp -a autopsy $DESTDIR"
spewdo "cp -a config $DESTDIR"
spewdo "cp -a exportengine $DESTDIR"
spewdo "cp -a ChangeLog.* $DESTDIR"

cd $OLDPWD
