#!/bin/bash

PACKAGE="unixcw"
VERSION="3.0.1"


# setup
REPO=`pwd`
cd ../../build
BUILD=`pwd`


echo "REPO = " $REPO
echo "BUILD = " $BUILD

if [ "$REPO" == x"" ]; then
    echo "REPO is empty"
    exit
elif [ "$REPO" == x"/" ]; then
    echo "REPO is root directory"
    exit
fi

if [ "$BUILD" == x"" ]; then
    echo "BUILD is empty"
    exit
elif [ "$BUILD" == x"/" ]; then
    echo "BUILD is root directory"
    exit
fi



# clean up old files, prepare brand new, empty dir
rm -rf $BUILD/*




# prepare $PACKAGE_X.Y.Z.debian.tar.gz
cd $REPO
cp -rp debian $BUILD/
cd $BUILD
tar cvfz $PACKAGE\_$VERSION.debian.tar.gz debian
rm -rf debian




cd $REPO
cp -rp ../$PACKAGE $BUILD
cd $BUILD/$PACKAGE/
./_clean_up distclean
rm -rf _build_debian _clean_up
rm -rf .git



cd $BUILD
mv $PACKAGE $PACKAGE-$VERSION
tar cvfz $PACKAGE\_$VERSION.orig.tar.gz $PACKAGE-$VERSION --exclude=debian


# go to final build dir and start building Debian package
cd $PACKAGE-$VERSION
echo ""
echo `pwd`
debuild -us -uc
