#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=tor-git 
pkgver=0.4.7.10.r280.g9e17af9 
pkgrel=01
pkgdesc='An anonymizing overlay network. w/o zstd and systemd'
arch=(x86_64) 
url="https://www.torproject.org" 
conflicts=('tor') 
provides=('tor') 
backup=('etc/tor/torrc'
        'etc/tor/torrc.d/nodes.conf'
        'etc/tor/torrc.d/bridge.conf'
        'etc/tor/torrc.d/isolation.conf'
        'etc/tor/torrc.d/transparent_proxy.conf')

depends=('openssl' 'libevent' 'libseccomp' 'xz')
makedepends=('asciidoc' 'git')
checkdepends=('python')
optdepends=('torsocks: allow transparent SOCKS proxying'
            'obfs4proxy: obfuscating pluggable transport proxy'
            'meek: obfuscating pluggable transport proxy')

[[ $_malloc = 'jemalloc' ]] && depends+=('jemalloc')
[[ $_malloc = 'tcmalloc' ]] && depends+=('gperftools')

source=("git+https://git.torproject.org/tor.git#branch=${_branch:-main}"
        {nodes,bridge,transparent_proxy,isolation}.conf
        'torrc' 'tor.logrotate' 'tor.tmpfiles' 'tor.sysusers')

pkgver () {
    cd tor
    git describe --long --tags --abbrev=7 "origin/${_branch:-main}" \
        |sed -e 's/tor.//g;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    cd tor
    ./autogen.sh
}

build() {
  cd tor

    ./configure --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --disable-zstd \
    --disable-zstd-advanced-apis \
    --disable-systemd \
    --disable-html-manual \
    --disable-ipv6 \
    --enable-lzma \
    --enable-xz \
    --with-malloc="${_malloc:-system}" \
    --disable-module-relay \
    --disable-unittests \
    --enable-pic
  make
}

check() {
    cd tor
    make check ||true
}

package() {
    cd tor

    make DESTDIR="$pkgdir" install

    install -Dm644 "$srcdir/tor.sysusers"  "$pkgdir/usr/lib/sysusers.d/tor.conf"
    install -Dm644 "$srcdir/tor.tmpfiles"  "$pkgdir/usr/lib/tmpfiles.d/tor.conf"

    rm -f "$pkgdir/etc/tor/tor-tsocks.conf"
    rm -f "$pkgdir/usr/bin/torify"

    install -dm755 "$pkgdir/etc/tor"
    install -dm750 "$pkgdir/etc/tor/torrc.d"

    install -Dm640 "$srcdir/torrc"                  "$pkgdir/etc/tor/torrc"
    install -Dm640 "$srcdir/nodes.conf"             "$pkgdir/etc/tor/torrc.d/nodes.conf"
    install -Dm640 "$srcdir/bridge.conf"            "$pkgdir/etc/tor/torrc.d/bridge.conf"
    install -Dm640 "$srcdir/isolation.conf"         "$pkgdir/etc/tor/torrc.d/isolation.conf"
    install -Dm640 "$srcdir/transparent_proxy.conf" "$pkgdir/etc/tor/torrc.d/transparent_proxy.conf"

    install -Dm644 "$srcdir/tor.logrotate" "$pkgdir/etc/logrotate.d/tor"
#    install -Dm644 "$srcdir/tor.service"   "$pkgdir/usr/lib/systemd/system/tor.service"
    install -Dm644 LICENSE                 "$pkgdir/usr/share/licenses/${pkgname}/LICENSE"
}


#---- license gpg-key sha256sums ----


license=('BSD') 
validpgpkeys=(2133BC600AB133E1D826D173FE43009C4607B1FB  # Nick Mathewson
              F65CE37F04BA5B360AE6EE17C218525819F78451  # Roger Dingledine
              1C1BC007A9F607AA8152C040BEA7B180B1491921) # Alexander Færøy <ahf@0x90.dk>

sha256sums=(SKIP  # tor
	72ed5d90c54d9d5354af0d9fc7eb1412c548cc308868b85a99278abe8ccbf145  # nodes.conf
	90a588c3c2dc7826172341453f76739e8f48df7b0c858adebd12e97f047bde26  # bridge.conf
	7fbb63e9411eee2176964449a3d6809d16e1120152c6ff201ecea1d1f97f102b  # transparent_proxy.conf
	748b7264b49b12d5252d688b8859820046413938c5fde91578da0d5b95594c2e  # isolation.conf
	1f32a363443437a08d133494732008b98a9dc520173a97d53ce832edfb923f7b  # torrc
	d447227fcc2756778a1be143b8975d67b25ea15688cde2291185b3c71d0f6e34  # tor.logrotate
	06c00318d84ead3f939b267c7ae9e4cc1cd90c534d0b57ddd2595fee9065ee7f  # tor.tmpfiles
	231405d1fbbcc68168248f93edd19ae14b60f66bb4d1c8e46ead1d4cd8e0ae7c) #  tor.sysusers


