#!/bin/bash
#
# Welcome to the DTC install maker !
# This will produce the Mac OS X package
# 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=osx
PKG_NAME=dtc
FOLDER=$PKG_NAME"-"$UNIX_TYPE"-"$VERSION
ARCHIVE=$FOLDER"-all.tar.gz"
echo " --- Making DTC Mac OS X package ---"

# This block should be common to most unix packages :
echo "===> Copying files"
rm -rf dtc
mkdir -p dtc/etc/zones
mkdir -p dtc/shared/imgcache
cp -rf ../admin ../client ../shared ../email ../doc dtc/
echo "<?php
\$conf_dtc_version= \""$VERS"\";
\$conf_dtc_release= \""$RELS"\";
\$conf_unix_type= \""$UNIX_TYPE"\";
?>" > dtc/shared/dtc_version.php
find dtc/ -iname 'CVS' -exec rm -rf {} \; &>/dev/null
find dtc/ -iname '*~' -exec rm -rf {} \; &>/dev/null
if ! [ -e dtc/admin/gfx ]
then
	ln -s ../shared/gfx dtc/admin/gfx
fi
if ! [ -e dtc/email/gfx ]
then
	ln -s ../shared/gfx dtc/email/gfx
fi
if ! [ -e dtc/client/gfx ]
then
	ln -s ../shared/gfx dtc/client/gfx
fi
if ! [ -e dtc/admin/imgcache ]
then
        ln -s ../shared/imgcache dtc/admin/imgcache
fi
if ! [ -e dtc/client/imgcache ]
then
        ln -s ../shared/imgcache dtc/client/imgcache
fi
if ! [ -e dtc/email/imgcache ]
then
        ln -s ../shared/imgcache dtc/email/imgcache
fi
# Copy the table dump in the admin directory
cp sources/dtc_db.php sources/restor_db.php dtc/admin

chown -R root:0 dtc

# Specific Mac OS X package actions :
mkdir -p $FOLDER/usr/share
mv dtc $FOLDER/usr/share
mkdir -p $FOLDER/Crypt
cp sources/osx/Crypt/CBC.php sources/osx/Crypt/HCEMD5.php $FOLDER/Crypt
cp sources/osx/mod_log_sql.so $FOLDER/mod_log_sql.so
cp sources/osx/mod_log_sql_mysql.so $FOLDER/mod_log_sql_mysql.so
cp sources/osx/install.sh $FOLDER

cp sources/osx/uninstall.sh $FOLDER
cat sources/uninstall_deamons.sh >>$FOLDER"/uninstall.sh"
chmod +x $FOLDER"/uninstall.sh"
echo "===> Packaging"
tar -czf $ARCHIVE $FOLDER

echo " -- Succesfully made "$ARCHIVE" ---"
