# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Ebubekir KARUL <ebubekirkarul@yandex.com>
# Contributor: s1gma,shirokuro

pkgbase=scapy
pkgname=('scapy' 'python-scapy' 'python2-scapy')
pkgver=2.4.3
pkgrel=1
pkgdesc='Powerful interactive packet manipulation program written in Python'
url='http://www.secdev.org/projects/scapy/'
arch=('any')
license=('GPL2')
makedepends=('tcpdump' 'python2' 'python')
checkdepends=('python2-cryptography' 'python2-pyx' 'python2-matplotlib'
              'python-cryptography' 'python-pyx' 'python-matplotlib'
              'graphviz' 'sox')
source=(https://github.com/secdev/scapy/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('40a44ec7924dab19c6d0954fee409b9bea68df405ef9074741f34bee18038923')
sha512sums=('579e3f326f90e10b2839aee805949e14ecab9431f360ef75e60080a971653e1f48a240d812b8ace77754b01b07a2ddb8533d1e6b18ee8804280bf9b2c237cede')

prepare() {
  cp -a ${pkgbase}-${pkgver}{,-py2}
  cd ${pkgbase}-${pkgver}-py2
  sed -e 's|env python|env python2|g' -i doc/scapy/*.rst run_scapy $(find . -name '*.py')
}

build() {
  (cd ${pkgbase}-${pkgver}-py2
    python2 setup.py build
  )
  (cd ${pkgbase}-${pkgver}
    python setup.py build
  )
}

check() {
  # Run only main tests, without network access
  (cd ${pkgbase}-${pkgver}-py2/test
    ./run_tests_py2 -K netaccess -F
  )
  (cd ${pkgbase}-${pkgver}/test
    ./run_tests_py3 -K netaccess -F
  )
}

package_scapy() {
  depends=('python' 'python-scapy')
  pkgdesc+=' (tools)'
  cd ${pkgbase}-${pkgver}
  python setup.py install -O1 --skip-build --root="${pkgdir}" --prefix=/usr
  install -d "${pkgdir}/usr/share/doc"
  ln -sf /usr/share/doc/python-scapy "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}/usr/lib"
}

package_python-scapy() {
  pkgdesc+=' (library)'
  depends=('tcpdump' 'python')
  optdepends=('python-cryptography: WEP, IPsec and SSL/TLS support'
              'python-pyx: psdump() and pdfdump() functions'
              'python-matplotlib: plotting support'
              'graphviz: conversations() method support'
              'sox: for VOIP support')
  cd ${pkgbase}-${pkgver}
  python setup.py install -O1 --skip-build --root="${pkgdir}" --prefix=/usr
  install -Dm 644 doc/scapy/*.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}"{/usr/bin,/usr/share/man}
}

package_python2-scapy() {
  pkgdesc+=' (library)'
  depends=('tcpdump' 'python2')
  optdepends=('python2-cryptography: WEP, IPsec and SSL/TLS support'
              'python2-pyx: psdump() and pdfdump() functions'
              'python2-matplotlib: plotting support'
              'graphviz: conversations() method support'
              'sox: for VOIP support')
  cd ${pkgbase}-${pkgver}-py2
  python2 setup.py install -O1 --skip-build --root="${pkgdir}" --prefix=/usr
  install -Dm 644 doc/scapy/*.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}"{/usr/bin,/usr/share/man}
}

# vim: ts=2 sw=2 et:
