#!/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=syslog-ng
pkgver=4.0.1
pkgrel=01
pkgdesc="Next-generation syslogd with advanced networking and filtering capabilities - w/o systemd and ipv6"
arch=('x86_64')
url="https://www.syslog-ng.com/products/open-source-log-management/"
depends=('awk' 'glib2' 'libnsl' 'json-c' 'curl' 'libnet' 'openssl')
makedepends=('libxslt' 'mongo-c-driver' 'librabbitmq-c' 'python' 'libesmtp' 'hiredis'
             'libdbi' 'libmaxminddb' 'net-snmp' 'librdkafka' 'libcap')
checkdepends=('python-nose' 'python-ply')
optdepends=('logrotate: for rotating log files'
            'libdbi: for the SQL plugin'
            'librabbitmq-c: for the AMQP plugin'
            'mongo-c-driver: for the MongoDB plugin'
            'libesmtp: for the SMTP plugin'
            'hiredis: for the Redis plugin'
            'libmaxminddb: for the GeoIP2 plugin'
            'net-snmp: for the SNMP plugin'
            'librdkafka: for the Kafka C plugin'
            'python: for Python-based plugins')
conflicts=('eventlog')
replaces=('eventlog')
backup=('etc/syslog-ng/scl.conf'
        'etc/syslog-ng/syslog-ng.conf'
        'etc/logrotate.d/syslog-ng'
        'etc/default/syslog-ng')
source=(https://github.com/balabit/syslog-ng/releases/download/syslog-ng-$pkgver/$pkgname-$pkgver.tar.gz
        syslog-ng.conf syslog-ng.logrotate)

prepare() {
  cd $pkgname-$pkgver
#  sed -i -e 's,/bin/,/usr/bin/,' -e 's,/sbin/,/bin/,' contrib/systemd/syslog-ng@.service
#  sed -i -e 's|/var/run|/run|g' contrib/systemd/syslog-ng@default
}

build() {
  cd $pkgname-$pkgver

  # https://archlinux.org/todo/lto-fat-objects/
  export CFLAGS+=" -ffat-lto-objects"
  export CXXFLAGS+=" -ffat-lto-objects"

  ./autogen.sh
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc/syslog-ng \
    --libexecdir=/usr/lib \
    --sbindir=/usr/bin \
    --localstatedir=/var/lib/syslog-ng \
    --datadir=/usr/share \
    --with-pidfile-dir=/run \
    --enable-spoof-source \
    --disable-ipv6 \
    --disable-systemd \
    --with-systemdsystemunitdir=no \
    --enable-manpages \
    --enable-all-modules \
    --disable-java \
    --disable-java-modules  \
    --disable-mqtt \
    --disable-riemann \
    --with-python=3 \
    --with-jsonc=system
  make
}

check() {
  cd $pkgname-$pkgver
  make check || /usr/bin/true # unit test requires criterion
}

package() {
  make -C $pkgname-$pkgver DESTDIR="$pkgdir" install
  install -dm755 "$pkgdir/var/lib/syslog-ng" "$pkgdir/etc/syslog-ng/patterndb.d"
  install -Dm644 "$srcdir/syslog-ng.conf" "$pkgdir/etc/syslog-ng/syslog-ng.conf"
  install -Dm644 "$srcdir/syslog-ng.logrotate" "$pkgdir/etc/logrotate.d/syslog-ng"
  install -Dm644 "$srcdir"/$pkgname-$pkgver/contrib/systemd/syslog-ng@default "$pkgdir"/etc/default/syslog-ng
}

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

license=('GPL2' 'LGPL2.1')

sha256sums=(c16eafe447191c079f471846182876b7919d3d789af8c1f9fe55ab14521ceb2c  # syslog-ng-4.0.1.tar.gz
	d2e3328e2ac344ccddf1b38eab226f36c11ade1971c0c8c8ac8cd4d97c8b02e8 # syslog-ng.conf
	93c935eca56854011ea9e353b7a1da662ad40b2e8452954c5b4b5a1d5b2d5317) # syslog-ng.logrotate

