# This is a ZoneMinder PKGBUILD file. 
# Contributor: Ross melin <rdmelin@gmail.com>

pkgname=zoneminder
pkgver=1.25.0
pkgrel=2
pkgdesc="Capture, analyse, record and monitor video security cameras."
arch=('i686' 'x86_64')
url="http://www.zoneminder.com"
license=('GPL')
depends=('cambozola' 'apache' 'php' 'mysql' 'pcre' 'openssl' 'ffmpeg' 'perl-php-serialization' 'perl-libwww' 'perl-date-manip' 'perl-unicode-map' 'perl-dbi' 'perl-dbd-mysql' 'perl-io-stringy' 'perl-mime-lite' 'perl-timedate' 'perl-x10' 'perl-time-modules' 'perl-net-smtp-ssl' 'perl-sys-mmap' 'sudo' 'libv4l')
makedepends=()
install=zoneminder.install
source=("http://www2.zoneminder.com/downloads/ZoneMinder-${pkgver}.tar.gz"
zm.rc.d 
Controls_Orbit.sql 
zminit.arch 
customdb 
httpd-zm.conf 
zmfilter.pl 
zmeventbackup
Makefile.patch
run)

build() {
  cd "$srcdir/ZoneMinder-$pkgver"

  cat ../Controls_Orbit.sql >> db/zm_create.sql.in
  ./configure --prefix=/usr \
    --sysconfdir=/etc \
    --with-webuser=http  \
    --with-webgroup=http \
    --with-mysql=/usr  \
    --with-webdir=/srv/zoneminder/www  \
    --with-cgidir=/srv/zoneminder/cgi-bin \
    --bindir=/srv/zoneminder/bin \
    ZM_SSL_LIB=openssl \
    CPPFLAGS=-D__STDC_CONSTANT_MACROS
  # goddamn chown line just mucks everything up, we'll chown it in the install
  # script.
  sed -i '/chown/d' Makefile
  make || return 1
  make DESTDIR="$pkgdir" install || return 1

  install -D -m 700 $startdir/src/zminit.arch  $startdir/pkg/usr/lib/zm/bin/zminit
  install -D -m 700 $startdir/src/zm.rc.d  $startdir/pkg/etc/rc.d/zm
  install -D -m 700 scripts/zmdbbackup  $startdir/pkg/usr/lib/zm/bin/zmdbbackup
  install -D -m 700 scripts/zmdbrestore  $startdir/pkg/usr/lib/zm/bin/zmdbrestore
  install -D -m 700 scripts/zmeventdump  $startdir/pkg/usr/lib/zm/bin/zmeventdump
  install -D -m 700 scripts/zmlogrotate.conf  $startdir/pkg/etc/logrotate.d/zm
  install -D -m 700 $startdir/src/zmeventbackup  $startdir/pkg/etc/cron.hourly/zmeventbackup
  install -D -m 755 scripts/zmfilter.pl $startdir/pkg/usr/lib/zm/bin/zmfilter.pl
  install -D -m 755 scripts/zmupdate.pl $startdir/pkg/usr/lib/zm/bin/zmupdate.pl

  mkdir -p  $startdir/pkg/etc/httpd/conf/extra/
  install -m 644 $startdir/src/httpd-zm.conf $startdir/pkg/etc/httpd/conf/extra/httpd-zm.conf

  install -D -m 700 $startdir/src/customdb $startdir/pkg/usr/lib/zm/upgrade/customdb
  install -D  db/zm*.sql $startdir/pkg/usr/lib/zm/upgrade/

  mkdir -p $startdir/pkg/var/run/zm
  mkdir -p $startdir/pkg/var/lib/zm

  #install runit files
  mkdir -p $pkgdir/etc/sv/zm
  install -D -m 755 $srcdir/run $pkgdir/etc/sv/zm

  ### remove special files
  find $startdir/pkg/ -name "perllocal.pod" \
    -o -name ".packlist"                \
    -o -name "*.bs"                     \
    |xargs -i rm -f {}

}
md5sums=('eaefa14befd482154970541252aa1a39'
         'b20fb25b187eb6abb21321e153a7fb25'
         '5033bc098bf497c8aed1fc1b3c9c5f9c'
         'f9720872736f26d17bc49d8725b75ae4'
         '4ace13d1e20934abe192ef7372c75988'
         '00201eba9c0a5d1ed14b10cc55410698'
         '80c52cc3575073a7462ff6a54886a345'
         '8b40137b6ff54f2fb26104b70edd22e9'
         'bb308c2393e947a224d56862c85a3ad9'
         '0c7024c355ce36828627bed10d965202')