# $Id: PKGBUILD 73660 2012-07-12 19:34:35Z foutrelis $
# Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
# Contributor: Malte Rabenseifner <malte@zearan.de>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: FUBAR <mrfubar@gmail.com>

pkgname=('shorewall' 'shorewall6' 'shorewall-core')
pkgver=4.5.6
pkgrel=1
arch=('any')
url="http://www.shorewall.net/"
license=('GPL')
source=(http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.6/$pkgname-$pkgver.tar.bz2
        http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.6/shorewall6-$pkgver.tar.bz2
        http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.6/shorewall-core-$pkgver.tar.bz2)
sha256sums=('09676324d3f959a7632b6b8823d8374b47f027a40e4b6cae2441e742424684f6'
            '8a2107c0443c374d4a6e0cc4acc9d8826c5e51467dac31483482214054cdcefc'
            '0a0c73315300e941a6f020a35a8378eccd34ddc92f8488977afce9819e0f5de1')

build() {
  for product in shorewall{,6,-core}; do
    pushd "$srcdir/$product-$pkgver"
    ./configure HOST=archlinux SBINDIR=/usr/sbin INITSOURCE=init.archlinux.sh \
      SYSTEMD=/usr/lib/systemd/system
    popd
  done
}

package_shorewall() {
  pkgdesc="An iptables-based firewall for Linux systems"
  depends=('shorewall-core' 'perl')
  backup=(etc/shorewall/{accounting,actions,blacklist,blrules,clear,ecn,findgw,hosts,init,initdone,interfaces,lib.private,maclist,masq,nat,netmap,notrack,params,policy,providers,proxyarp,refresh,refreshed,restored,routestopped,rtrules,rules,scfilter,secmarks,shorewall.conf,start,started,stop,stopped,tcclasses,tcclear,tcdevices,tcfilters,tcinterfaces,tcpri,tcrules,tos,tunnels,zones})

  cd "$srcdir/$pkgname-$pkgver"

  do_install
}

package_shorewall6() {
  pkgdesc="An iptables-based firewall for Linux systems (with IPv6 support)"
  depends=('shorewall')
  backup=(etc/shorewall6/{accounting,actions,blacklist,blrules,clear,hosts,init,interfaces,maclist,netmap,notrack,params,policy,providers,proxyndp,refresh,refreshed,restored,routestopped,rtrules,rules,scfilter,secmarks,shorewall6.conf,start,started,stop,stopped,tcclasses,tcclear,tcdevices,tcfilters,tcinterfaces,tcpri,tcrules,tos,tunnels,zones})

  cd "$srcdir/$pkgname-$pkgver"

  do_install 6
}

package_shorewall-core() {
  pkgdesc="Core Shorewall libraries"
  depends=('iptables' 'iproute2')

  cd "$srcdir/$pkgname-$pkgver"

  DESTDIR="$pkgdir" ./install.sh
}

do_install() {
  local _name_suffix=$1

  sed -i -e 's|^MODULE_SUFFIX=ko$|&.gz|' \
         -e 's|/subsys||' \
      "configfiles/shorewall$_name_suffix.conf"

  DESTDIR="$pkgdir" ./install.sh

  # Fix /sbin path reference in init scripts
  sed -i 's|/sbin|/usr/sbin|' \
    "$pkgdir/etc/rc.d/shorewall$_name_suffix" \
    "$pkgdir/usr/lib/systemd/system/shorewall$_name_suffix.service"

  install -d "$pkgdir/usr/share/doc/shorewall$_name_suffix/"
  cp -r Samples$_name_suffix "$pkgdir/usr/share/doc/shorewall$_name_suffix/"

  chmod 755 "$pkgdir/etc/rc.d/shorewall$_name_suffix"
  chmod -R 644 "$pkgdir/etc/shorewall$_name_suffix/"
  chmod 755 "$pkgdir/etc/shorewall$_name_suffix/"
  chmod 644 "$pkgdir/usr/share/shorewall$_name_suffix/modules"
  chmod 644 "$pkgdir/usr/share/shorewall$_name_suffix/helpers"

  # Fix systemd service file permissions
  chmod 644 "$pkgdir/usr/lib/systemd/system/shorewall$_name_suffix.service"
}

# vim:set ts=2 sw=2 et:
