#!/bin/bash

#  Authors     [Robert Meolic (meolic@uni-mb.si)]
#  Revision    [$Revision: 30 $]
#  Date        [$Date: 2013-04-05 15:35:44 +0200 (pet, 05 apr 2013) $]
#
#  Copyright   [This file is part of Bdd Scout package.
#               Copyright (C) 2008, 2013 UM-FERI
#               UM-FERI, Smetanova ulica 17, SI-2000 Maribor, Slovenia
#
#               Biddy 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.
#
#               Biddy 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., 51 Franklin Street, Fifth Floor,
#               Boston, MA 02110-1301 USA.]

VERSION=`sed "" VERSION`
NAME="bddscout"
OS=`uname | sed "s/_.*//;s/[0-9]//g"`

mkdir -p "distribution"

if [ -e "distribution/version-$VERSION" ]
then
  echo "CANNOT CHANGE AN EXISTING VERSION!"
  exit 0
fi

echo ""
echo "************************"
echo "CREATING NEW VERSION ..."
echo "************************"
echo ""

mkdir "distribution/version-$VERSION"
mkdir "distribution/version-$VERSION/$NAME-$VERSION"

cp VERSION CHANGES COPYING "distribution/version-$VERSION/$NAME-$VERSION"
cp README README.Linux "distribution/version-$VERSION/$NAME-$VERSION"
cp bddscout.h bddscout.c bddscoutMain.c bddscout.tcl "distribution/version-$VERSION/$NAME-$VERSION"
cp pkgIndex.tcl "distribution/version-$VERSION/$NAME-$VERSION"
cp bddscoutIFIP.c bddscoutIFIP.tcl "distribution/version-$VERSION/$NAME-$VERSION"
cp pkgExtensionIFIP.tcl "distribution/version-$VERSION/$NAME-$VERSION"
cp Makefile Makefile.Linux "distribution/version-$VERSION/$NAME-$VERSION"
cp example.bdd example.bf "distribution/version-$VERSION/$NAME-$VERSION"
cp ../bddview/bddview.tcl ../bddview/example.bddview "distribution/version-$VERSION/$NAME-$VERSION"
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/IFIP
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/cath
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/ex
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/hachtel
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/plasco
cp IFIP/README IFIP/*.txt "distribution/version-$VERSION/$NAME-$VERSION"/IFIP
cp IFIP/cath/* "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/cath
cp IFIP/ex/* "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/ex
cp IFIP/hachtel/* "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/hachtel
cp IFIP/plasco/* "distribution/version-$VERSION/$NAME-$VERSION"/IFIP/plasco

mkdir "distribution/version-$VERSION/$NAME-$VERSION"/debian
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/debian/source
cp debian/c* "distribution/version-$VERSION/$NAME-$VERSION"/debian
cp debian/r* "distribution/version-$VERSION/$NAME-$VERSION"/debian
cp debian/*.dirs "distribution/version-$VERSION/$NAME-$VERSION"/debian
cp debian/source/* "distribution/version-$VERSION/$NAME-$VERSION"/debian/source

pushd "distribution/version-$VERSION/$NAME-$VERSION"
dch -M --create --package "$NAME" -v "$VERSION"
cp "debian/changelog" "../changelog.deb"
popd

mkdir "distribution/version-$VERSION/$NAME-$VERSION"/rpm
mkdir "distribution/version-$VERSION/$NAME-$VERSION"/rpm/SPECS
sed -e "s/THISVERSION/$VERSION/g" -e "s/THISRELEASE/0/g" \
    "rpm/SPECS/bddscout.spec" \
    > "distribution/version-$VERSION/$NAME-$VERSION/rpm/SPECS/bddscout.spec"

pushd "distribution/version-$VERSION"
echo "* `LC_ALL=en_GB date +"%a %b %d %Y"` - meolic" > changelog.rpm
echo "- Initial release." >> changelog.rpm
vi changelog.rpm
popd

pushd "distribution/version-$VERSION"
tar -czf "$NAME-$VERSION.tar.gz" "$NAME-$VERSION"
mv "$NAME-$VERSION.tar.gz" "$NAME"_"$VERSION.initial.tar.gz"
rm -fr "$NAME-$VERSION"
popd

echo ""
echo "**********************"
echo "TGZ PACKAGE COMPLETED!"
echo "**********************"
echo ""
