# Contributor: Phillip Smith <fukawi2@NO-SPAM.gmail.com>
pkgname=sqlgrey
pkgver=1.6.8
pkgrel=1
pkgdesc="Postfix greylisting policy service with auto-white-listing written in Perl with SQL database as storage backend."
arch=(any)
url="http://sqlgrey.sourceforge.net/"
license=('GPL')
depends=('perl' 'perl-net-server' 'perl-io-multiplex' 'perl-dbi' 'perl-date-calc' 'postfix>=2.1')
optdepends=('perl-dbd-pg: for using postgresql as backend database' 'perl-dbd-mysql: for using mysql as backend database')
backup=('etc/sqlgrey/sqlgrey.conf' 'etc/sqlgrey/clients_ip_whitelist.local' 'etc/sqlgrey/clients_fqdn_whitelist.local')
install=$pkgname.install
source=("http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.bz2"
        "rc.$pkgname")
md5sums=('513ddb38e5a9760773d8e1a2b27e31a1'
         '028c1b536ef89fa2eb6cbc7fb4708395')

build() {
  # UID / GID 111 = sqlgrey
	cd $srcdir/$pkgname-$pkgver

	make || return 1
}

package() {
	cd $srcdir/$pkgname-$pkgver

  make ROOTDIR=${pkgdir} install || return 1
	
  msg "Installing rc.d script..."
  install -D -m755 $srcdir/$pkgname.rc $pkgdir/etc/rc.d/$pkgname || return 1
  
  msg "Creating .local config files..."
  touch $pkgdir/etc/sqlgrey/clients_ip_whitelist.local
  touch $pkgdir/etc/sqlgrey/clients_fqdn_whitelist.local
  cat > $pkgdir/etc/sqlgrey/clients_ip_whitelist.local <<EOD
  # This is the local configuration for whitelisted IP addresses for sqlgrey.
  # Add any IP addresses you need whitelisted to this file. One IP address per line.
  # To add a /24 address space, omit the last octet of the address.
  # For example, to whitelist 202.14.166.0/24, add the line:
  #   202.14.166
EOD

  cat > $pkgdir/etc/sqlgrey/clients_fqdn_whitelist.local <<EOD
  # This is the local configuration for whitelisted hostnames for sqlgrey.
  #
  # hostname.domain.com # whole system name (least CPU intensive)
  # *.domain.com        # whitelist any fqdn in the domain 'domain.com'
  # /regexp/            # whitelist any fqdn matching the regexp (by far most CPU intensive)

  # Note you need the following two lines to allow both
  # <lots of mtas>.example.com and example.com
  # *.example.com
  # example.com 
EOD

  msg "Setting permissions..."
  chown -R 111:111 $pkgdir/etc/sqlgrey || return 1

  msg "Cleaning up..."
  rm -Rf $pkgdir/etc/init.d || return 1
}

# vim:set ts=2 sw=2 et:
