# $Id: PKGBUILD 326467 2018-06-08 06:31:40Z bisson $
# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: lydgate

pkgname=mlocate
pkgver=0.26.git.20170220
_commit=c98bf6595703456558a6f9c163c746cdaa9e591f
pkgrel=1
pkgdesc='Merging locate/updatedb implementation'
url='https://pagure.io/mlocate'
arch=('x86_64')
license=('GPL')
backup=('etc/updatedb.conf')
depends=('glibc')
makedepends=('git')
source=("git+https://pagure.io/mlocate.git#commit=$_commit"
        'git://git.savannah.gnu.org/gnulib.git#commit=5861339993f3014cfad1b94fc7fe366fc2573598'
	'sysusers.d'
	'updatedb.conf'
	'updatedb.timer'
	'updatedb.service')
sha256sums=('SKIP'
            'SKIP'
            '1713a8fc8b81f4a390bf8597c4c0e917474379002dcc984aad2f44218d10c82a'
            'ea65bb68bb854803965ac16c770ba2567256e2066d68c272f1a1974ffc5c5ee7'
            '2e813effb651fae101d93722827553c6b9b9d42e898e808db4991eafdd330e02'
            '83c7a508bad5dccd55a158cf8b8029d680f82cf8b1d21074279def14d9ad4dee')

prepare() {
	cd "${srcdir}/${pkgname}"
	sed -i '/^groupname /s/mlocate/locate/' Makefile.am
	../gnulib/gnulib-tool --import # See file: ./HACKING
	autoreconf --install
}

build() {
	cd "${srcdir}/${pkgname}"
	./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/lib
	make
}

check() {
	cd "${srcdir}/${pkgname}"
	make check
}

package() {
	cd "${srcdir}/${pkgname}"

	make DESTDIR="${pkgdir}" install

	chgrp 21 "${pkgdir}/usr/bin/locate"
	chmod 2755 "${pkgdir}/usr/bin/locate"
	ln -s locate "${pkgdir}/usr/bin/slocate"

	install -dm755 "${pkgdir}/var/lib"
	install -dm750 -g21 "${pkgdir}/var/lib/locate"
	
	install -Dm644 ../updatedb.conf "${pkgdir}/etc/updatedb.conf"
	install -Dm644 ../sysusers.d "${pkgdir}/usr/lib/sysusers.d/locate.conf"
	install -Dm644 ../updatedb.timer "${pkgdir}/usr/lib/systemd/system/updatedb.timer"
	install -Dm644 ../updatedb.service "${pkgdir}/usr/lib/systemd/system/updatedb.service"

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