# $Id: PKGBUILD 144513 2015-10-20 10:41:10Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Antonio Rojas <nqn1976 @ gmail.com>
# Based on owncloud-git PKGBUILD by Alexander Ovsyannikov

pkgname=owncloud
pkgver=8.2.0
pkgrel=1
pkgdesc="A cloud server to store your files centrally on a hardware controlled by you"
arch=('any')
url="http://owncloud.org/"
license=('GPL')
depends=('php-gd')
optdepends=('php-apache: to use the Apache web server'
	    'php-sqlite: to use the SQLite database backend'
	    'php-pgsql: to use the PostgreSQL database backend'
	    'php-ldap: LDAP authentication'
	    'php-intl'
	    'php-apcu'
	    'php-xcache'
	    'mariadb: to use the MySQL database backend'
	    'smbclient: to mount SAMBA shares'
	    'php-mcrypt'
#	    'php-imagick: file preview'
	    'ffmpeg: file preview'
	    'libreoffice: file preview')
makedepends=()
options=('!strip')
backup=('etc/webapps/owncloud/apache.example.conf')
validpgpkeys=('E3036906AD9F30807351FAC32D5D5E97F6978A26')
_watch="https://owncloud.org/changelog/"
#source=("http://download.owncloud.org/community/$pkgname-${pkgver}.tar.bz2"{,.asc}
source=("$pkgname-$pkgver.tar.gz::https://github.com/owncloud/core/archive/v$pkgver.tar.gz"
	"$pkgname-3rdparty-$pkgver.tar.gz::https://github.com/owncloud/3rdparty/archive/v$pkgver.tar.gz"
	"$pkgname-apps-$pkgver.tar.gz::https://github.com/owncloud/apps/archive/v$pkgver.tar.gz"
	"$pkgname-updater-$pkgver.tar.gz::https://github.com/owncloud/updater/archive/v$pkgver.tar.gz"
	"$pkgname-templateeditor-$pkgver.tar.gz::https://github.com/owncloud/templateeditor/archive/v$pkgver.tar.gz"
	"$pkgname-firstrunwizard-$pkgver.tar.gz::https://github.com/owncloud/firstrunwizard/archive/v$pkgver.tar.gz"
	"$pkgname-files_texteditor-$pkgver.tar.gz::https://github.com/owncloud/files_texteditor/archive/v$pkgver.tar.gz"
	"$pkgname-files_locking-$pkgver.tar.gz::https://github.com/owncloud/files_locking/archive/v$pkgver.tar.gz"
	"$pkgname-files_pdfviewer-$pkgver.tar.gz::https://github.com/owncloud/files_pdfviewer/archive/v$pkgver.tar.gz"
	"$pkgname-activity-$pkgver.tar.gz::https://github.com/owncloud/activity/archive/v$pkgver.tar.gz"
	'apache.example.conf')
md5sums=('7dd4277b4ce8ff198208e1748dfe28ca'
         '8fc10f6f0f783e90cad88d6340d3a838'
         'dcba5a81b4c25a8976fe5e493c0669be'
         '4fd72b301c65b7e39d63ab370bcdc456'
         '722e249fbb93faeece0518df1048473a'
         '41985af3d703b0dd741b299113960a20'
         '320de98cf72a8427cb9d6ffceff57d7a'
         '29e90e7bcb663ab9e56a143ac9755517'
         '04aed2e80433b576a5398997ca0bba35'
         '8618272f71661586967069427f207a00'
         '64c6edf88bcbb37d063e4bf77b39237f')

prepare() {
  cd $srcdir/core-$pkgver
  sed -i "s|'appstoreenabled'.*|'appstoreenabled' => false,|" config/config.sample.php
  rm -rf $srcdir/core-$pkgver/3rdparty
  mv $srcdir/3rdparty-$pkgver $srcdir/core-$pkgver/3rdparty
  mv $srcdir/apps-$pkgver/* $srcdir/core-$pkgver/apps
  for i in files_locking files_pdfviewer files_texteditor firstrunwizard \
           templateeditor updater activity; do
    mv $srcdir/$i-$pkgver $srcdir/core-$pkgver/apps/$i
  done
  find . -type f -name .gitattributes -delete
  find . -type f -name .gitkeep -delete
  find . -type f -name .gitignore -delete
  find . -type f -name .gitmodules -delete
  find . -type f -name .travis.yml -delete
  find . -type d -name .git -exec rm -rf {} \;
  find ./apps -maxdepth 1 -type f -delete
}

package() {
  # install license
  install -d ${pkgdir}/usr/share/licenses/${pkgname}
  cp ${srcdir}/core-$pkgver/COPYING-* ${pkgdir}/usr/share/licenses/${pkgname}

  # install project
  install -d ${pkgdir}/usr/share/webapps/
  cp -a ${srcdir}/core-$pkgver ${pkgdir}/usr/share/webapps/${pkgname}
  rm -rf ${pkgdir}/usr/share/webapps/${pkgname}/tests

  # install apache config file
  install -d  ${pkgdir}/etc/webapps/${pkgname}
  install -m 644 ${srcdir}/apache.example.conf  ${pkgdir}/etc/webapps/${pkgname}

  # move config to /etc
  mv ${pkgdir}/usr/share/webapps/owncloud/config ${pkgdir}/etc/webapps/${pkgname}/config
  chown -R http:http ${pkgdir}/etc/webapps/${pkgname}
  ln -s /etc/webapps/${pkgname}/config ${pkgdir}/usr/share/webapps/owncloud/config
  chown -R root:http ${pkgdir}/usr/share/webapps/${pkgname}

  find ${pkgdir}/usr/share/webapps/owncloud -type f -exec chmod 0644 {} \;
  find ${pkgdir}/usr/share/webapps/owncloud -type d -exec chmod 0755 {} \;
#  find ${pkgdir}/etc/webapps/owncloud -type f -print0 | xargs -0 chmod 0640
#  find ${pkgdir}/etc/webapps/owncloud -type d -print0 | xargs -0 chmod 0750

  chmod a+x ${pkgdir}/usr/share/webapps/${pkgname}/occ
}
