# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: alphazo <alphazo@gmail.com>

pkgname=sshuttle
pkgver=1.0.5
pkgrel=3
pkgdesc='Transparent proxy server that forwards all TCP packets over ssh'
arch=('any')
url="https://github.com/sshuttle/sshuttle"
license=('GPL2')
depends=('python-psutil' 'iptables' 'openssh' 'net-tools')
makedepends=('python-sphinx' 'python-setuptools-scm')
checkdepends=('python-pytest-cov' 'python-pytest-runner' 'python-mock')
backup=('etc/sshuttle/tunnel.conf' 'etc/sshuttle/prefixes.conf')
source=("https://github.com/sshuttle/$pkgname/archive/v$pkgver/$pkgname-$pkgver.tar.gz"
        'sshuttle.service' 'prefixes.conf' 'tunnel.conf')
sha512sums=('d58cff77625eca0ffba44bd19553bb2043df99dac4e204b3269ffe1be6dae38009eb6ac42e575322b903945b406d6008f70360e0597bed3913c0ebf0562e9a68'
            'c22504798f6220cd6b0946d6975375437c52753a241cd2a6a03d3aeb005ed1d78e6356dde23716e2514ccf6d7f1c6aace43956dbeede1bf028753b9bdcdd8b7d'
            'cc5a5dee7991c7641fa8a4fb356e1977aa9d1cbfed63cb5ebf8732c4de76be841f66d9267472e70578b176f528d8cfb4f75e634d5d915f4c8bcdc0b801db8a13'
            'acd3d0024d4604cc6a96609286c3f27bce2f0b70a068f58a2110dacc235b22ba7cd83c8989f46d0a9391eda7d272040bb3b1b2c547ae3fa0c9f61bef0a187dda')

export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver

prepare() {
  cd $pkgname-$pkgver
  sed -i '/flake8/d' setup.py
}

build() {
  cd $pkgname-$pkgver
  python setup.py build

  cd docs
  make man
}

check() {
  cd $pkgname-$pkgver
  python setup.py pytest
}

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

  install -Dm644 docs/_build/man/sshuttle.1 "$pkgdir"/usr/share/man/man1/sshuttle.1

  install -d "$pkgdir"/etc/sshuttle
  install -m644 "$srcdir"/{tunnel.conf,prefixes.conf} "$pkgdir"/etc/sshuttle
  install -Dm644 "$srcdir"/sshuttle.service "$pkgdir"/usr/lib/systemd/system/sshuttle.service
}
