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

pkgbase=audit
pkgname=('audit' 'python-audit')
pkgver=3.0.8
pkgrel=01
pkgdesc="Userspace components of the audit framework w/o systemd"
url='https://people.redhat.com/sgrubb/audit'
arch=(x86_64)
makedepends=(glibc krb5 libcap-ng libldap swig linux-lts-headers python)
options=(emptydirs)
#options=(emptydirs debug)  # comment above options uncomment this to have debug packages produced
source=($url/$pkgname-$pkgver.tar.gz
	$pkgbase-3.0.8-config_paths.patch)

 prepare() {
  # replace the use of /sbin with /usr/bin in configs
  patch -Np1 -d $pkgbase-$pkgver -i ../$pkgbase-3.0.8-config_paths.patch
 }



build() {
  cd $pkgbase-$pkgver
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib/audit \
    --enable-gssapi-krb5=yes \
    --enable-systemd=no \
    --with-libcap-ng=yes
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
   make
  [ -n "$SOURCE_DATE_EPOCH" ] && touch -h -d @$SOURCE_DATE_EPOCH bindings/swig/python/audit.py
}

package_audit() {
  depends=(glibc krb5 libkrb5.so libgssapi_krb5.so libcap-ng libcap-ng.so)
  provides=(libaudit.so libauparse.so)
  backup=(
    etc/libaudit.conf
    etc/audit/audit-stop.rules
    etc/audit/auditd.conf
    etc/audit/audisp-remote.conf
    etc/audit/zos-remote.conf
    etc/audit/plugins.d/af_unix.conf
    etc/audit/plugins.d/au-remote.conf
    etc/audit/plugins.d/audispd-zos-remote.conf
    etc/audit/plugins.d/syslog.conf
  )

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver

  # add log dir
  install -vdm 700 "$pkgdir/var/log/$pkgname"

  # remove legacy files
  rm -frv "$pkgdir/usr/lib/audit"

  # remove files provided by python-audit
  rm -frv "$pkgdir/usr/lib/python"*
}

package_python-audit() {
  depends=(audit libaudit.so libauparse.so glibc python)
  pkgdesc+=' (python bindings)'

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver/bindings
}

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

license=(GPL LGPL2.1)

sha256sums=(b5f4d9b9ad69381ee18f33d3d918326aa52861509c901143f8a8c4ed5caa8913 # audit-3.0.8.tar.gz
	c3647e09d1a973595d8e43e373b8644dfb7131328c7fb3e229593af02c72ca42) #  audit-3.0.8-config_paths.patch
