# Maintainer: Paul Mattal <paul@archlinux.org>
# Contributor: Manolis Tzanidakis <manolis@archlinux.org>

pkgname=squirrelmail
pkgver=1.4.21
pkgrel=1
pkgdesc="Webmail for Nuts!"
arch=('any')
license=('GPL')
url="http://www.squirrelmail.org"
depends=('php' 'perl' 'imap-server')
makedepends=('findutils')
backup=('srv/http/squirrelmail/.htaccess' 'srv/http/squirrelmail/config/config.php')
install="$pkgname.install"
source=("http://download.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz")
md5sums=('1e53a47b0544c37705079cb961ef05dc')
#options=('force')

build() {
  msg "Nothing to compile for #pkgname"
}

package() {
  _INSTDIR="/srv/http/$pkgname"
  _DATADIR="/var/lib/$pkgname/data"
  _ATTACHDIR="/var/lib/$pkgname/attachments"
  
  # install
  mkdir -p $pkgdir/$_INSTDIR
  cp -ra $srcdir/squirrelmail-$pkgver/* $pkgdir/$_INSTDIR/
  
  # remove CVS dirs
  find $pkgdir -type d -name CVS -exec rm -rf {} \;
  
  # customize config (data and attachments in /var/lib/squirrelmail)
  cd $pkgdir/$_INSTDIR/config
  cp -p config_default.php config.php
  sed -e "s|/var/local/squirrelmail/data/|$_DATADIR|" \
    -e "s|attachment_dir = '/var/local/squirrelmail/attach/';|attachment_dir = '$_ATTACHDIR';|" \
    -i config.php
  
  # create data and attachments directories, set ownership/permissions
  # ideally we would set attachments differently to root:-1 with 0730, but
  # I don't know how to get chgrp to take "-1" properly; perhaps someday
  # I'll figure out how to make this work
  mkdir -p $pkgdir/$_DATADIR
  mkdir -p $pkgdir/$_ATTACHDIR
  chown -R http:http $pkgdir/$_DATADIR
  chown -R http:http $pkgdir/$_ATTACHDIR
  chmod 0700 $pkgdir/$_DATADIR
  chmod 0300 $pkgdir/$_ATTACHDIR
  
  # restrict access to squirrelmail by default
  cat > $pkgdir/$_INSTDIR/.htaccess <<EOT
deny from all
allow from 127.0.0.0/8
EOT
}

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