#!/bin/bash

VERS=`cat version`
RELS=`cat release`
VERSION=$VERS"-"$RELS
BSDVERSION=$VERS"."$RELS

FTP_ROOT_LOCATION=/home/ftp
FTP_PUB_LOCATION=$FTP_ROOT_LOCATION"/pub/dtc"

echo "--- Making all packages ---"
mkdir -p $FTP_ROOT_LOCATION"/debian/dists/stable/main/binary-i386/"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/debian"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/bsd"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/cvs"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/gentoo"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/RPMS"
mkdir -p $FTP_ROOT_LOCATION"/home/pub/dtc/generic"

./clean
./makeDebian
./makeTarball
./makeBSD
fakeroot ./makeRedhat
./makeGentoo

echo "--- Copying file to debian repository ---"
cp -fv "dtc_"$VERSION"_all.deb" $FTP_ROOT_LOCATION"/debian/dists/stable/main/binary-i386/"
cp -fv "dtc-postfix-courier_"$VERSION"_all.deb" $FTP_ROOT_LOCATION"/debian/dists/stable/main/binary-i386/"
echo "--- Rebuilding debian package listing ---"
curdir=`pwd`
cd $FTP_ROOT_LOCATION"/debian"
dpkg-scanpackages dists/stable/main/binary-i386 /dev/null | gzip -9 >dists/stable/main/binary-i386/Packages.gz
cd $curdir
echo "--- Copying files to ftp server tree ---"
cp -fv "dtc_"$VERSION"_all.deb" $FTP_PUB_LOCATION"/debian"
cp -fv "dtc-"$BSDVERSION".tar.gz" $FTP_PUB_LOCATION"/bsd/"
cp -fv "dtcBSDport-"$BSDVERSION".tar.gz" $FTP_PUB_LOCATION"/bsd/"
cp -fv "dtc_"$VERSION"-generic_all.tar.gz" $FTP_PUB_LOCATION"/generic"
cp -fv "/root/rpmbuild/RPMS/noarch/dtc-"$VERS"-"$RELS".noarch.rpm" $FTP_PUB_LOCATION"/RPMS"
cp -fv "dtc_"$VERSION"-gentoo_all.tar.gz" $FTP_PUB_LOCATION"/gentoo"
