#!/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

# Here comes script parameters !
UNIX_TYPE=$1	# debian, gentoo, etc...
BUILD_DIR=$2	# Example: debian/usr/share/dtc
# PKG_FILENAME=$3	// Example: "dtcGentoo_"$VERSION"_all";

echo " --- Making DTC $UNIX_TYPE package --- "
echo " ===> Copying files"
rm -rf $BUILD_DIR
mkdir $BUILD_DIR
mkdir -p $BUILD_DIR/etc/zones
# echo cp -rf ../admin ../client ../shared ../email ../doc $BUILD_DIR
cp -rf ../admin ../client ../shared ../email ../doc $BUILD_DIR
cp ../admin/signature.txt ../shared/messages_header.txt $BUILD_DIR/etc
rm -rf $BUILD_DIR/shared/imgcache
mkdir -p $BUILD_DIR/shared/imgcache

# Remove bad files from package
find $BUILD_DIR/ -iname '*~' -exec rm -rf {} \; &>/dev/null
rm -rf $BUILD_DIR/shared/mysql_config.php

echo "<?php
\$conf_dtc_version= \""$VERS"\";
\$conf_dtc_release= \""$RELS"\";
\$conf_unix_type= \""$UNIX_TYPE"\";
?>" > $BUILD_DIR/shared/dtc_version.php

if ! [ -f sources/dtc_db.php ]; then
	curdir=`pwd`
	cd sources
	echo "Dumping your DTC SQL structures."
	echo -n "Please enter your mysql password: "
	read conf_dbpass
	php backup_db.php $conf_dbpass
	cd $curdir
fi
cp sources/dtc_db.php sources/restor_db.php $BUILD_DIR/admin

if ! [ -e $BUILD_DIR/admin/gfx ]; then
	ln -s ../shared/gfx $BUILD_DIR/admin/gfx
fi
if ! [ -e $BUILD_DIR/email/gfx ]; then
	ln -s ../shared/gfx $BUILD_DIR/email/gfx
fi
if ! [ -e $BUILD_DIR/client/gfx ]
then
        ln -s ../shared/gfx $BUILD_DIR/client/gfx
fi
if ! [ -e $BUILD_DIR/admin/imgcache ]; then
	ln -s ../shared/imgcache $BUILD_DIR/admin/imgcache
fi
if ! [ -e $BUILD_DIR/client/imgcache ]; then
	ln -s ../shared/imgcache $BUILD_DIR/client/imgcache
fi
if ! [ -e $BUILD_DIR/email/imgcache ]; then
	ln -s ../shared/imgcache $BUILD_DIR/email/imgcache
fi

