#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=clamav
pkgver=1.0.1
pkgrel=01
pkgdesc='Anti-virus toolkit for Unix w/o systemd'
url='https://www.clamav.net/'
arch=('x86_64')
depends=('bzip2' 'libltdl' 'libxml2' 'curl' 'pcre2' 'json-c' 'libmspack'
         'ncurses' libncursesw.so libcurl.so libjson-c.so libbz2.so)
makedepends=('libmilter' 'cmake' 'ninja' 'python' 'cargo')
checkdepends=('check')
backup=('etc/clamav/clamd.conf'
        'etc/clamav/freshclam.conf'
        'etc/clamav/clamav-milter.conf'
        'etc/logrotate.d/clamav')
provides=(libclamav.so libclamunrar.so libclamunrar_iface.so)
source=(https://www.clamav.net/downloads/production/${pkgname}-${pkgver}.tar.gz{,.sig}
        clamav.logrotate
        clamav.sysusers
        clamav.tmpfiles)

prepare() {
  cd ${pkgname}-${pkgver}
  sed -E 's|^(Example)$|#\1|' -i etc/{clamd,freshclam,clamav-milter}.conf.sample
  sed -E 's|#(User) .+|\1 clamav|' -i etc/{clamd,freshclam,clamav-milter}.conf.sample
  sed -E 's|#(LogFile) .+|\1 /var/log/clamav/clamd.log|' -i etc/clamd.conf.sample
  sed -E 's|#(LogTime) .+|\1 yes|' -i etc/clamd.conf.sample etc/clamav-milter.conf.sample
  sed -E 's|#(PidFile) .+|\1 /run/clamav/clamd.pid|' -i etc/clamd.conf.sample
  sed -E 's|#(TemporaryDirectory) .+|\1 /tmp|' -i etc/{clamd,clamav-milter}.conf.sample
  sed -E 's|#(LocalSocket) .+|\1 /run/clamav/clamd.ctl|' -i etc/clamd.conf.sample
  sed -E 's|#(UpdateLogFile) .+|\1 /var/log/clamav/freshclam.log|' -i etc/freshclam.conf.sample
  sed -E 's|#(DatabaseMirror) .+|\1 database.clamav.net|' -i etc/freshclam.conf.sample
  sed -E 's|#(NotifyClamd) .+|\1 /etc/clamav/clamd.conf|' -i etc/freshclam.conf.sample
  sed -E 's|#(PidFile) .+|\1 /run/clamav/freshclam.pid|' -i etc/freshclam.conf.sample
  sed -E 's|#(LogFile) .+|\1 /var/log/clamav/clamav-milter.log|' -i etc/clamav-milter.conf.sample
  sed -E 's|#(PidFile) .+|\1 /run/clamav/clamav-milter.pid|' -i etc/clamav-milter.conf.sample
  sed -E "s|(\\[Unit\\])|\\1\\nWants=network-online.target\\nAfter=network-online.target|" -i freshclam/clamav-freshclam.service.in
}

build() {
  cd ${pkgname}-${pkgver}
  cmake \
    -DCMAKE_BUILD_TYPE='None' \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SBINDIR=bin \
    -DAPP_CONFIG_DIRECTORY=/etc/clamav \
    -DDATABASE_DIRECTORY=/var/lib/clamav \
    -DENABLE_EXTERNAL_MSPACK=ON \
    -Wno-dev \
    -B build \
    -G Ninja \
    -S .
  ninja -C build
}

check() {
  cd ${pkgname}-${pkgver}
  ninja -C build test
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install

  mv "${pkgdir}"/etc/clamav/freshclam.conf{.sample,}
  mv "${pkgdir}"/etc/clamav/clamd.conf{.sample,}
  mv "${pkgdir}"/etc/clamav/clamav-milter.conf{.sample,}

  install -Dm 644 ../clamav.sysusers "${pkgdir}"/usr/lib/sysusers.d/clamav.conf
  install -Dm 644 ../clamav.tmpfiles "${pkgdir}"/usr/lib/tmpfiles.d/clamav.conf
  install -Dm 644 ../clamav.logrotate "${pkgdir}"/etc/logrotate.d/clamav
}

#---- license gpg-key sha256sums ----

license=('GPL')

validpgpkeys=('E34DB95B374B31570496CD3F609B024F2B3EDD07') # Talos (Talos, Cisco Systems Inc.) <research@sourcefire.com>

sha256sums=(0872dc1b82ff4cd7e8e4323faf5ee41a1f66ae80865d05429085b946355d86ee  # clamav-1.0.1.tar.gz
	af109eebd75a460b9a8f2336081c0f0027af786e2e49704249dc29e03781c035  # clamav-1.0.1.tar.gz.sig
	c36e3ddf790fa6ea90169038ae08521a31652a372017e6e38858e28fc63b3f74  # clamav.logrotate
	01a896c3a1cd34b323594403fd82a9e353b5aa848b8462137b621959558199e8  # clamav.sysusers
	8e216c7e4763a273a120930787dcc444ea221bb719eed180a9d15b4c1d603a84) #  clamav.tmpfiles

 
##  ba8571a42240425627a551ee63e47d150726f5af551564404dbc8747187cffb3  clamav-1.0.1-01-x86_64.pkg.tar.lz


