# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=roundcubemail
pkgver=1.6.11
pkgrel=1
pkgdesc="A PHP web-based mail client"
arch=('any')
url="https://roundcube.net/"
license=('GPL')
depends=('php-interpreter')
options=('emptydirs')
makedepends=('git')
optdepends=('python: password change script'
            'perl: for change_ldap_pass.pl helper'
	    'php-gd')
backup=('etc/webapps/roundcubemail/.htaccess'
        'etc/webapps/roundcubemail/apache.conf')
install=roundcube.install
validpgpkeys=('F3E4C04BB3DB5D4215C45F7F5AB2BAA141C4F7D5')
source=("https://github.com/roundcube/roundcubemail/releases/download/$pkgver/roundcubemail-$pkgver-complete.tar.gz"{,.asc}
        "apache.conf")
sha512sums=('842d6b0f9bfdb0661de798fb83ccfbf202583214cf478fb7092529785f31b9aa8d7a1fcd63c1d6b967e396e1e2a7750669e238d112875befb3f017b6034acacc'
            'SKIP'
            '0e80317ae6f040386b0980d0764bc8a9aa5f7cbf028a210a896763cb7a7fea6d91600eda588922a0eb6d519f2ec1e0a2f723bd7ab554c8b1ad4af49a95101f6e')

prepare() {
  cd "$srcdir"/roundcubemail-${pkgver}
  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
  cd "$pkgdir"/usr/share/webapps
  cp -ra "$srcdir"/roundcubemail-${pkgver} 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 -Dm0644 "$srcdir"/apache.conf "$pkgdir"/etc/webapps/roundcubemail/apache.conf
  chown 33:33 "$pkgdir"/etc/webapps/roundcubemail/config/config.inc.php.sample
  chmod 0640 "$pkgdir"/etc/webapps/roundcubemail/config/config.inc.php.sample

  install -dm0750 -o 33 -g 33 "$pkgdir"/var/cache/roundcubemail
  install -dm0750 -o 33 -g 33 "$pkgdir"/var/log/roundcubemail

  rm -rf temp logs
}
