# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Hans-Nikolai Viessmann <hans AT viess DOT mn>

pkgname=plocate
pkgver=1.1.23
pkgrel=1
pkgdesc="Alternative to locate, faster and compatible with mlocate's database."
arch=('x86_64' 'aarch64')
url="https://plocate.sesse.net"
license=('GPL-2.0-or-later' 'GPL-2.0-only')
depends=('zstd' 'liburing' 'systemd')
makedepends=('meson')
conflicts=('mlocate')
provides=('mlocate' 'locate')
replaces=('mlocate')
backup=('etc/updatedb.conf')
source=("${url}/download/${pkgname}-${pkgver}.tar.gz"
        'plocate-fix-updatedb.timer.patch'
        'plocate.sysusers'
        'plocate.tmpfiles'
        'updatedb.conf')
sha256sums=('06bd3b284d5d077b441bef74edb0cc6f8e3f0a6f58b4c15ef865d3c460733783'
            'f519c901e2fb4195e25025a745db41c4167156be698738b198cbd5651cd9d9e6'
            '1713a8fc8b81f4a390bf8597c4c0e917474379002dcc984aad2f44218d10c82a'
            'adda399ac42f0faa002caab5bf932777c0006ae7c4387add859c9f77321b4202'
            'd00796741e2194032d0185b40de70ff5c8a11fda416a70434eb0aa2020981f91')

prepare() {
    cd $pkgname-$pkgver
    patch -Np1 < "$srcdir/plocate-fix-updatedb.timer.patch"
}

build() {
    cd $pkgname-$pkgver
    arch-meson \
        -Dinstall_cron=false \
        -Dinstall_systemd=true\
        -Dlocategroup=locate \
        ../build
    meson compile -C ../build
}

package() {
    cd $pkgname-$pkgver
    DESTDIR="$pkgdir" meson install -C ../build

    chgrp 21 "${pkgdir}/usr/bin/plocate"
    chmod 2755 "${pkgdir}/usr/bin/plocate"

    install -Dm644 ../plocate.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/plocate.conf"
    install -Dm644 ../plocate.sysusers "$pkgdir/usr/lib/sysusers.d/plocate.conf"
    install -Dm644 ../updatedb.conf "${pkgdir}/etc/updatedb.conf"
    ln -sf /usr/bin/plocate "$pkgdir/usr/bin/mlocate"
    ln -sf /usr/bin/plocate "$pkgdir/usr/bin/locate"

    install -d "${pkgdir}/usr/lib/systemd/system/timers.target.wants"
    ln -s ../plocate-updatedb.timer "${pkgdir}/usr/lib/systemd/system/timers.target.wants/plocate-updatedb.timer"
}
