# $Id: PKGBUILD 116306 2014-07-24 12:02:36Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=roundcubemail
pkgver=1.0.2
pkgrel=3
pkgdesc="A PHP web-based mail client"
arch=('any')
url="http://www.roundcube.net"
license=('GPL')
depends=('php')
optdepends=('python2')
backup=('etc/webapps/roundcubemail/.htaccess'
	'etc/webapps/roundcubemail/apache.conf')
install=roundcubemail.install
options=('!strip' 'emptydirs')
source=(http://downloads.sourceforge.net/sourceforge/roundcubemail/roundcubemail-${pkgver/rc/-rc}.tar.gz
	apache.conf)
md5sums=('5028c6f9fa88d0c84b0fde0b84355203'
         'f11b17e2a80b383cde4af963fb307541')

prepare() {
  cd ${srcdir}/roundcubemail-${pkgver/rc/-rc}
  sed -i \
    -e "s|RCUBE_INSTALL_PATH . 'temp.*|'/var/cache/roundcubemail';|" \
    -e "s|RCUBE_INSTALL_PATH . 'logs.*|'/var/log/roundcubemail';|" \
    config/defaults.inc.php \
    program/lib/Roundcube/rcube_config.php
}

package() {
  mkdir -p ${pkgdir}/etc/webapps/roundcubemail
  mkdir -p ${pkgdir}/usr/share/webapps
  mkdir -p ${pkgdir}/var/log
  cd ${pkgdir}/usr/share/webapps
  cp -ra ${srcdir}/roundcubemail-${pkgver/rc/-rc} roundcubemail
  cd roundcubemail

  mv .htaccess $pkgdir/etc/webapps/roundcubemail/
  ln -s /etc/webapps/roundcubemail/.htaccess .htaccess

  mv config $pkgdir/etc/webapps/roundcubemail/
  ln -s /etc/webapps/roundcubemail/config config

  install -dm0750 $pkgdir/var/{log,cache}/roundcubemail
  install -Dm0644 $srcdir/apache.conf $pkgdir/etc/webapps/roundcubemail/apache.conf

#  install -dm0755 $pkgdir/etc/php/conf.d/
#  cat <<EOF >$pkgdir/etc/php/conf.d/$pkgname.ini
#open_basedir = ${open_basedir}:/etc/webapps/roundcubemail:/usr/share/webapps/roundcubemail:/var/log/roundcubemail:/var/cache/roundcubemail
#EOF

  rm -rf temp logs
}
