#!/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-alpha
pkgver=0.4.7.10.r93.g982c504
pkgrel=1
pkgdesc="An anonymizing overlay network (development version) no-zstd no-systemd"
arch=('x86_64')
url="https://www.torproject.org"
conflicts=('tor' 'tor-git')
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')
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')

# https://gitweb.torproject.org/tor.git/tag/
source=("git+https://git.torproject.org/tor.git#branch=${_branch:-main}"
#source=("git+https://git.torproject.org/tor.git#commit=^d376585751d535a4ad2ab0424acd6b29168cca86 # refs/tags/^tor-0.4.7.5-alpha
        {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-html-manual \
        --disable-systemd \
        --disable-zstd \
        --disable-ipv6 \
        --disable-zstd-advanced-apis \
        --enable-lzma \
        --enable-xz \
        --enable-pic \
        --with-malloc="${_malloc:-system}" #\
        #--disable-module-relay \
        #--disable-unittests
    make
}

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

package() {
    cd tor
    make DESTDIR="$pkgdir" install

    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.tmpfiles"  "$pkgdir/usr/lib/tmpfiles.d/tor.conf"
    install -Dm644 "$srcdir/tor.sysusers"  "$pkgdir/usr/lib/sysusers.d/tor.conf"
    install -Dm644 LICENSE                 "$pkgdir/usr/share/licenses/tor-git/LICENSE"
}

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

license=('BSD')

sha256sums=(SKIP
	72ed5d90c54d9d5354af0d9fc7eb1412c548cc308868b85a99278abe8ccbf145 # nodes.conf
	eab04421822cce29a3c5065b707b0033fdab6dedd140a49ea902daf36bb767e0 # bridge.conf
	b6d5027754831bb4230c748affa245e5e7ee4f801214bca19ea6418cb84fd417 # transparent_proxy.conf
	9156f0d768119e7c8390be625cc591af90304198ad5dc5b0b4a036e7cc92fa07 # isolation.conf
	1f32a363443437a08d133494732008b98a9dc520173a97d53ce832edfb923f7b # torrc
	5756d919fb7a9c7063fb6311b8056c6695576ed12658098325aef7758824c960 # tor.logrotate
	06c00318d84ead3f939b267c7ae9e4cc1cd90c534d0b57ddd2595fee9065ee7f # tor.tmpfiles
	632cd25223ac163aed2a848784108d5310e641e1eb839375813c7c406ecee9d0) # tor.sysusers
