# $Id: PKGBUILD 107364 2014-03-17 08:25:44Z bpiotrowski $
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>
# Contributor: Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor: michalzxc
# Contributor: nbags <neilbags@gmail.com>

pkgname=fail2ban
pkgver=0.9.0
pkgrel=2
pkgdesc='Bans IPs after too many failed authentication attempts'
url='http://www.fail2ban.org/'
license=('GPL')
arch=('any')
depends=('python2' 'iptables' 'python2-pyinotify' 'whois' 'python2-systemd')
backup=(etc/fail2ban/fail2ban.conf
        etc/fail2ban/jail.conf)
install=fail2ban.install
source=(https://github.com/fail2ban/$pkgname/archive/$pkgver.tar.gz
        service tmpfiles.conf
        failban-0.9.0-fix-indentation.patch)
md5sums=('c8e0df39cbc32ee8646b82be9b7b5e53'
         'b4af226eb2d3029241a70e005ec7b3ac'
         '88d51ecc760ad2e017a165c632f49892'
         '3b22b9d826c82a503df31a24f10d58a6')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i ../failban-0.9.0-fix-indentation.patch
}

package() {
  cd $pkgname-$pkgver
  python2 setup.py install --root "$pkgdir"

  install -Dm644 files/fail2ban.service \
          "$pkgdir"/usr/lib/systemd/system/$pkgname.service
  install -Dm644 files/fail2ban-tmpfiles.conf \
          "$pkgdir"/usr/lib/tmpfiles.d/$pkgname.conf
  install -Dm644 files/bash-completion \
          "$pkgdir"/usr/share/bash-completion/completions/fail2ban

  # avoid conflict with filesystem>=2012.06
  rm -r "$pkgdir"/var/run

  # fix sendmail location
  sed -i 's/sbin/bin/g' "$pkgdir"/etc/fail2ban/action.d/sendmail*.conf

  install -Dm644 man/fail2ban.1 "$pkgdir"/usr/share/man/man1/fail2ban.1
  install -Dm644 man/fail2ban-client.1 \
          "$pkgdir"/usr/share/man/man1/fail2ban-client.1
  install -Dm644 man/fail2ban-regex.1 \
          "$pkgdir"/usr/share/man/man1/fail2ban-regex.1
  install -Dm644 man/fail2ban-server.1 \
          "$pkgdir"/usr/share/man/man1/fail2ban-server.1
  install -Dm644 man/jail.conf.5 "$pkgdir"/usr/share/man/man5/jail.conf.5
}
