#!/bin/bash
#  
#  Copyright (c) 2002 Steve Slaven, All Rights Reserved.
#  
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of
#  the License, or (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#  MA 02111-1307 USA
#  

echo "Making misc. dist, version comes from .version (which is not included in dist)"
echo ".version format is my-project.0.0.0 ==> my-project.0.0.0.tgz"

if [ -f .version ]
then
	VERS=`cat .version`
	echo "VERSION: $VERS"
else
	echo ".version file not found... exiting"
	exit
fi

echo "Press <enter>"

read JUNK

echo "Deleting backup files *~"
find . -iname '*~' -exec rm {} \;

if [ -d CVS ]
then
	echo "Assuming CVS setup"
	echo "Updating changes..."
	if [ -f Changes ]
	then
		rm Changes
	fi

	cvs2cl.pl -f Changes
fi

# This is executed from the source directory
if [ -f .bootstrap ]
then
	if [ -x .bootstrap ]
	then
		echo "Executing bootstrap (cleaning) script"
		.bootstrap
	else
		echo ".bootstrap not executable..."
	fi
fi

echo "Deleting old archive..."
test -f $VERS.tar.gz && rm -f $VERS.tar.gz

echo "Making dest tree..."
HERE=`pwd`
cd /tmp

mkdir $VERS

cd $VERS
cp -a $HERE/* .

if [ -d CVS ]
then
	echo "CVS detected, deleting CVS related files..."
	find . -type d -name CVS -exec rm -r {} \;
fi

# This is executed in the source 
if [ -f $HERE/.poststrap ]
then
	if [ -x $HERE/.poststrap ]
	then
		echo "Executing poststrap (cleaning) script"
		$HERE/.poststrap
	else
		echo ".poststrap not executable..."
	fi
fi

cd /tmp

tar czvf $HERE/$VERS.tar.gz $VERS

rm -rf /tmp/$VERS

echo "Done!"
