#!/bin/sh
#
# Welcome to the DTC install maker !
# Maintainer: Thomas GOIRAND <thomas [ at ] goirand.fr>
# please do not ship with you packages
# this is only a small coder tool...
#

VERS=`cat version`
RELS=`cat release`
VERSION=$VERS"-"$RELS
UNIX_TYPE=debian

DEST_TREE=debian

cd ..
dpkg-buildpackage

exit 0



# Make the directories
mkdir -p ${DEST_TREE}/usr/share/dtc/etc/zones
mkdir -p ${DEST_TREE}/DEBIAN
mkdir -p ${DEST_TREE}/usr/share/dtc

# Make the basic archive
./buildRelease $UNIX_TYPE ${DEST_TREE}/usr/share/dtc

# Copy DTC's files in the good directories
mkdir -p ${DEST_TREE}/usr/share/doc
mv ${DEST_TREE}/usr/share/dtc/doc ${DEST_TREE}/usr/share/doc/dtc
ln -s ../doc/dtc ${DEST_TREE}/usr/share/dtc/doc
rm ${DEST_TREE}/usr/share/doc/dtc/LICENSE ${DEST_TREE}/usr/share/doc/dtc/INSTALL
gzip -f -9 ${DEST_TREE}/usr/share/doc/dtc/changelog
gzip -f -9 ${DEST_TREE}/usr/share/doc/dtc/changelog.Debian

# Store DTC's package name and version in the control file
echo "Package: dtc
Version: "$VERSION >${DEST_TREE}/DEBIAN/control
cat sources/debian/control >>${DEST_TREE}/DEBIAN/control

# Make the config file directory and script using standard
# plus debian specific scripts
cp -f sources/debian/prerm sources/debian/config sources/debian/postinst sources/debian/templates ${DEST_TREE}/DEBIAN
cat sources/setup_mysql_db.sh >>${DEST_TREE}/DEBIAN/postinst
cat sources/create_chroot.sh >>${DEST_TREE}/DEBIAN/postinst
cat sources/configure_deamons.sh >>${DEST_TREE}/DEBIAN/postinst
cat sources/uninstall_deamons.sh >>${DEST_TREE}/DEBIAN/prerm

find ./${DEST_TREE} -type d | xargs chmod 755

FAKEROOT=`which fakeroot`
if ! [ -x ""${FAKEROOT} ]; then
	echo "You need to \"apt-get install fakeroot\" to build the dtc pacakge"
	exit 1
fi

fakeroot ./buildDebianPackage ${DEST_TREE}

mv ${DEST_TREE}.deb "dtc_"$VERSION"_all.deb"

echo " -- Succesfully made dtc_"$VERSION"_all.deb ---"

echo "Package: dtc-postfix-courier
Version: "$VERSION >${DEST_TREE}/DEBIAN/control
cat sources/debian/control_postfix_courier >>${DEST_TREE}/DEBIAN/control

fakeroot ./buildDebianPackage ${DEST_TREE}
mv ${DEST_TREE}.deb "dtc-postfix-courier_"$VERSION"_all.deb"
echo " -- Succesfully made dtc-postfix-courier_"$VERSION"_all.deb ---"
