# Description: Bans IP that makes too many password failures.
# URL: http://www.fail2ban.org/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: python3-setuptools
# Optional: python3-pyinotify whois

name=fail2ban
version=1.1.0
release=3
source=(https://github.com/fail2ban/$name/archive/$version/$name-$version.tar.gz
  2fed408c05ac5206b490368d94599869bd6a056d.patch
  50ff131a0fd8f54fdeb14b48353f842ee8ae8c1a.patch
  3728.patch
  fail2ban.rc
  paths-crux.conf)

build() {
  cd $name-$version

  patch -Np1 -i $SRC/2fed408c05ac5206b490368d94599869bd6a056d.patch
  patch -Np1 -i $SRC/50ff131a0fd8f54fdeb14b48353f842ee8ae8c1a.patch
  patch -Np1 -i $SRC/3728.patch

  find . -mindepth 2 -type f -exec sed -i -e 's|/var\(/run/fail2ban\)|\1|g' {} +

  /usr/bin/python3 setup.py build
  /usr/bin/python3 setup.py install --root=$PKG --prefix=/usr --skip-build
  /usr/bin/python3 -mcompileall $PKG

  install -Dm750 $SRC/fail2ban.rc $PKG/etc/rc.d/fail2ban
  install -Dm664 $SRC/paths-crux.conf $PKG/etc/fail2ban/paths-crux.conf

  find $PKG -iname "*README*" -exec rm '{}' \+

  install -Dm644 -t $PKG/usr/share/man/man1 man/*.1
  install -Dm644 -t $PKG/usr/share/man/man5 man/*.5

  find $PKG -type f -exec \
    sed -i -e '1 s|^#!/usr/bin/python$|#!/usr/bin/python3|' \
    -e '1 s|^#!python$|#!/usr/bin/python3|' {} +

  prt-get isinst bash-completion && install -Dm644 files/bash-completion \
    $PKG/usr/share/bash-completion/completions/fail2ban

  rm -r $PKG/etc/fail2ban/paths-{arch,debian,fedora,freebsd,opensuse,osx}.conf
  rm -r $PKG/usr/share/doc
}
