#!/usr/bin/env bash
# This file is part of BlackArch Linux ( http://blackarch.org ).
# See COPYING for license details.

pkgname=owtf-git
pkgrel=1
pkgdesc='The Offensive (Web) Testing Framework.'
url='https://www.owasp.org/index.php/OWASP_OWTF'
license=('custom')
arch=('any')
depends=('net-tools' 'postgresql' 'python2-jinja'\
    'python2-markdown>=2.5.1' 'python2-tornado>=4.0.2'\
    'python2-pycurl>=7.19.5' 'python2-rdflib>=4.1.2'\
    'python2-pexpect>=3.3' 'python2-lxml>=3.4.0'\
    'java-environment' 'python2-pyopenssl>=0.14'\
    'python2-beautifulsoup4>=4.3.2' 'python2-sqlalchemy>=0.9.7'\
    'python2-six>=1.8.0' 'python2-psycopg2>=2.5.4' 'python2-pip')
optdepends=('tor' 'proxychains-ng' 'skipfish' 'metagoofil'\
    'set' 'wpscan' 'theharvester' 'metasploit' 'whatweb'\
    'cms-explorer' 'whapiti' 'arachini' 'dnsrecon' 'dirbuster'\
    'w3af' 'lbd' 'nikto' 'tlssled' 'httprint' 'hydra' 'wafw00f'\
    'websecurify' 'hoppy')
makedepends=('git')
options=('!strip')
source=("git+https://github.com/owtf/owtf#branch=develop" 'default.cfg.patch')
sha1sums=('SKIP' 'SKIP')

pkgver() {
    cd "$srcdir/owtf"

    echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {

    pip install PTP python-owasp-zap-v2 PyVirtualDisplay selenium

    cd "$srcdir/owtf"

    patch -Np1 -i "$srcdir/default.cfg.patch"

    mkdir -p "$pkgdir/usr/bin"
    mkdir -p "$pkgdir/usr/share/owtf"

    cp -pr * "$pkgdir/usr/share/owtf"

    sed -i -e "s|#![ ]*/usr/bin/python$|#!/usr/bin/python2|" \
        -e "s|#![ ]*/usr/bin/env python$|#!/usr/bin/env python2|" \
        -e "s|#![ ]*/bin/python$|#!/usr/bin/python2|" \
        $(find $pkgdir -name '*.py')

    cat > "$pkgdir/usr/bin/owtf" << EOF
#!/bin/sh
cd /usr/share/owtf
exec python2 ./owtf.py "\$@"
EOF

    chmod +x "$pkgdir/usr/bin/owtf"
}
