#!/bin/bash
#
# Script to create a debian package for SNFServer integrated with
# postfix.
#
# Usage:  create_snf-server-postfix_debian X.Y.Z
#
# where X.Y.Z is the version of SNFServer.
#
# $Id: configure.in,v 1.33 2008/02/08 15:10:17 adeniz Exp $
#
# Author: Alban Deniz
#
# Copyright (C) 2013 by MicroNeil Corporation. All rights reserved.
# See www.armresearch.com for the copyright terms.
#
#######################################################################

VERSION=$1

# Temporary directory.
TEMPDIR=tempDir

# Output message and exit.
error_exit() {
    echo Error running \'$1\' in directory $(pwd).
    exit 1
}

# Prepare the directory.
rm -rf $TEMPDIR
if [ $? -ne 0 ]
then
    error_exit "rm -rf $TEMPDIR"
fi

# Copy package files.
cp -dr Packages/Ubuntu/snf-server-postfix $TEMPDIR
if [ $? -ne 0 ]
then
    error_exit "cp -dr Packages/Ubuntu/snf-server-postfix $TEMPDIR"
fi

# Remove .svn directories.
rm -rf $(find $TEMPDIR -name .svn -type d)
if [ $? -ne 0 ]
then
    error_exit "rm -rf $(find $TEMPDIR -name .svn -type d)"
fi

# Create control file.
ControlContents="Section: mail
Priority: optional
Maintainer: support <support@armresearch.com>
Package: snf-server-postfix
Version: $VERSION-1
Architecture: all
Depends: snf-server, postfix
Description: snf-server-postfix integrates snf-server with postfix.
 snf-server is a plug-in for an MTA (Mail Transport Agent, such as
 sendmail or postfix) that does spam detection and IP address
 scanning.  snf-server-postfix must be installed after snf-server.
"
echo "$ControlContents" > $TEMPDIR/DEBIAN/control

if [ $? -ne 0 ]
then
    error_exit "echo $ControlContents > $TEMPDIR/DEBIAN/control"
fi

# Create the package.
dpkg-deb -b $TEMPDIR snf-server-postfix_$VERSION-1_all.deb
if [ $? -ne 0 ]
then
    error_exit "dpkg-deb -b $TEMPDIR snf-server-postfix_$VERSION-1_all.deb"
    exit $ERROR_EXIT
fi

# Success.
exit 0


