# Maintainer: Pierre Lalet <pl@ivre.rocks>
#
# Arch Linux package file

# This file is part of IVRE.
# Copyright 2011 - 2026 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IVRE is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.

pkgbase=ivre-git
_pkgname=ivre
pkgname=('ivre-git' 'ivre-web-git' 'ivre-docs-git' 'python-ivre-git')
pkgver=0.9.22.dev_master_161
pkgrel=1
pkgdesc='Network recon framework based on Nmap, Masscan, Zgrab2, Nuclei, httpx, Zeek (Bro), Argus, Netflow,... Build your own alternatives to Shodan and GreyNoise, run your Passive DNS service, and much more!'
arch=('any')
url='https://ivre.rocks/'
license=('GPL-3.0-or-later')
makedepends=('git' 'python' 'python-build' 'python-installer' 'python-setuptools' 'python-setuptools-scm')
branch="`git branch | awk '/^*/ {print $2}'`"
source=("git+file://`readlink -f ../../../`#branch=$branch")
sha512sums=('SKIP')

pkgver() {
  cd "$srcdir/$_pkgname"

  python -m setuptools_scm | sed "s/\.dev/.dev_${branch//-/_}_/"
}

build() {
  cd "$srcdir/$_pkgname"
  python -m build --wheel --no-isolation
}

package_ivre-git() {
  depends=('python-ivre-git')
  optdepends=('ivre-docs-git: Documentation'
              'ivre-web-git: Web server'
              'nmap: Network scan'
              'masscan: Network scan'
              'zmap: Network scan'
              'zeek: Network traffic analysis'
              'argus: Network traffic analysis'
              'nfdump: Netflow analysis'
              'imagemagick: Screenshots via Nmap scripts'
              'phantomjs: HTTP screenshots via Nmap script'
              'ffmpeg: RTSP Screenshots via Nmap script')
  provides=('ivre')
  conflicts=('ivre')

  cd "$srcdir/$_pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  rm -r "$pkgdir/usr/lib" \
     "$pkgdir/usr/share/doc" \
     "$pkgdir/usr/share/ivre/dokuwiki" \
     "$pkgdir/usr/share/ivre/web"

  install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" doc/license*
}

package_ivre-docs-git() {
  provides=('ivre-docs')
  conflicts=('ivre-docs')
  pkgdesc+=' (documentation)'

  cd "$srcdir/$_pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  cp README.md "$pkgdir/usr/share/doc/ivre/"
  mv "$pkgdir/usr/share/ivre/web/static/doc" "$pkgdir/usr/share/doc/ivre/html"
  rm -r "$pkgdir/usr/bin" "$pkgdir/usr/lib" \
     "$pkgdir/usr/share/ivre" \
     "$pkgdir/usr/share/bash-completion"
}

package_ivre-web-git() {
  depends=('python-ivre-git' 'python-bottle')
  optdepends=('apache: Web server'
              'mod_wsgi: Web server'
              'dokuwiki: Web server (notebook)')
  provides=('ivre-web')
  conflicts=('ivre-web')
  pkgdesc+=' (web application)'
  backup=('etc/httpd/conf/extra/ivre.conf')

  cd "$srcdir/$_pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  rm -r "$pkgdir/usr/bin" "$pkgdir/usr/lib" \
     "$pkgdir/usr/share/doc" \
     "$pkgdir/usr/share/bash-completion" \
     "$pkgdir/usr/share/ivre/zeek" \
     "$pkgdir/usr/share/ivre/data" \
     "$pkgdir/usr/share/ivre/docker" \
     "$pkgdir/usr/share/ivre/geoip" \
     "$pkgdir/usr/share/ivre/honeyd" \
     "$pkgdir/usr/share/ivre/patches"

  install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" doc/license*
  install -Dm0644 "pkg/apache/ivre.conf" "$pkgdir/etc/httpd/conf/extra/ivre.conf"
}

package_python-ivre-git() {
  depends=('python' 'python-pymongo')
  optdepends=('python-sqlalchemy: experimental PostgreSQL & SQLite backends'
              'python-psycopg2: experimental PostgreSQL backend'
              'python-elasticsearch: experimental Elasticsearch backend'
              'python-elasticsearch-dsl: experimental Elasticsearch backend'
              'python-tinydb: experimental file-based backend (no DB server)'
              'python-pillow: trim screenshots on insertion'
              'tesseract: extract words from screenshots on insertion'
              'python-cryptography: extract data from public keys ("ivre getmoduli")'
              'python-scapy: compute JA3 fingerprints from reverse-ssl services'
              'python-matplotlib: create graphs from command line tools'
              'python-dbus: 3D traceroute graphs'
              'mongodb: database server'
              'postgresql: database server (experimental backend)')
  provides=('python-ivre')
  conflicts=('python-ivre')
  pkgdesc+=' (library)'

  cd "$srcdir/$_pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  rm -r "$pkgdir/usr/bin" \
     "$pkgdir/usr/share"

  install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" doc/license*
  sed -i "s/\.dev/.dev_${branch//-/_}_/" \
      "$pkgdir"/usr/lib/python*/site-packages/ivre/_version.py
}
