# Maintainer: DeepChirp <deepchirp@archlinuxcn.org>
# Contributor: Jisu-Woniu <jswn@jswn9945.xyz>

pkgname=peerbanhelper
pkgver=9.4.3
pkgrel=1
pkgdesc="A tool to auto ban peers on the Bittorrent network"
arch=('any')
url="https://github.com/PBH-BTN/PeerBanHelper"
license=('GPL-3.0-or-later')
depends=('java-runtime>=25' 'sh')
makedepends=('git' 'java-environment>=25' 'nodejs' 'pnpm')
source=("${pkgname}::git+https://github.com/PBH-BTN/PeerBanHelper.git#tag=v${pkgver}" # Use git source to show commit hash in WebUI
        "${pkgname}.sh"
        "${pkgname}.sysusers"
        "${pkgname}.tmpfiles"
        "${pkgname}.service")
sha256sums=('98edf1216eb6ccfed0474d5d478dd6dbc1854757520c69bd574773e5198c2827'
            'a416eeaccf6747b678c118795eb6d70815d75c091627239fc7e8dfc3c850e019'
            '394ee8f74dd630f375c34cf5160059078516033b0867ad43b1c43377b4104bde'
            '5ecff7c76c8b24ed23176fd00bb6a2c242d3e7d7242f3d46b55a05f099ec6d4a'
            '5fd05e499bcb94796ad6ef4017648f2d53f0f604111dc6fc47623bfd17e482a7')

build() {
    cd "${pkgname}"

    pushd webui
    pnpm install --frozen-lockfile
    pnpm run build
    popd

    cp -r webui/dist src/main/resources/static
    ./gradlew clean build --no-daemon
}

package() {
    cd "${pkgname}"

    install -Dm644 "build/libs/PeerBanHelper.jar" "${pkgdir}/usr/share/java/${pkgname}/${pkgname}.jar"
    install -Dm644 build/libraries/*.jar -t "${pkgdir}/usr/share/java/${pkgname}/libraries"

    install -Dm755 "${srcdir}/${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"
    install -Dm644 "${srcdir}"/${pkgname}.sysusers "${pkgdir}"/usr/lib/sysusers.d/${pkgname}.conf
    install -Dm644 "${srcdir}"/${pkgname}.tmpfiles "${pkgdir}"/usr/lib/tmpfiles.d/${pkgname}.conf
    install -Dm644 "${srcdir}/${pkgname}.service" -t "${pkgdir}/usr/lib/systemd/system"

    install -Dm644 "pkg/deb/etc/peerbanhelper/config.yml" -t "${pkgdir}/usr/share/peerbanhelper/defaults"
    install -Dm644 "pkg/deb/etc/peerbanhelper/profile.yml" -t "${pkgdir}/usr/share/peerbanhelper/defaults"
}
