# Maintainer: Luke Shumaker <lukeshu@parabola.nu>

pkgname=dbscripts
pkgver=20181010
pkgdesc='Server-side programs for Parabola Pacman repositories'
url='https://git.parabola.nu/packages/dbscripts.git/'
license=('GPL')
backup=(
	etc/$pkgname/config
	etc/$pkgname/config.local
	etc/$pkgname/config.local.archlinux32
	etc/$pkgname/config.local.archlinuxarm
	etc/$pkgname/config.local.community
	etc/$pkgname/config.local.import-ourarches
	etc/$pkgname/config.local.packages
	etc/$pkgname/config.local.parabola
	etc/$pkgname/db-cleanup.conf
	etc/$pkgname/db-import-any.conf
	etc/$pkgname/db-import-archlinuxarm.conf
	etc/$pkgname/db-import-keyring.conf
	etc/$pkgname/torrent.conf
)

pkgrel=1
arch=('any')
depends=('librelib>=20180428' libretools rsync expac mktorrent)
source=("https://repo.parabola.nu/other/$pkgname/$pkgname-$pkgver.tar.gz"{,.sig})
sha256sums=('bbc49a01680326d865e6a5b511e414d9dd8b2b77528ae3606fce772ffcc872da'
            'SKIP')
#validpgpkeys=('99195DD3BB6FE10A2F36ED8445698744D4FFBFC9') # Luke Shumaker
validpgpkeys=('1B8C5E87702444D3D825CC8086ED62396D5DBA58') # Omar Vega Ramos

_gitver='commit=3b4edf8ed6d60f4257a7415eda6bcbedc30221c9'
mksource=("$pkgname-$pkgver::git://git.parabola.nu/packages/dbscripts.git/#$_gitver")
mkmd5sums=('SKIP')

package() {
	mkdir -p "$pkgdir"/opt
	cp -a "$srcdir/$pkgname-$pkgver" "$pkgdir/opt/$pkgname"

	mkdir -p "$pkgdir"/usr/bin
	find "$pkgdir/opt/$pkgname" -maxdepth 1 -type f -executable -not -name 'config-*' -exec ln -sr {} "$pkgdir"/usr/bin \;

	mkdir -p "$pkgdir"/etc/$pkgname
	local file
	for file in "${backup[@]}"; do
		mv -T "$pkgdir/opt/$pkgname/${file##*/}" "$pkgdir/$file"
		if [[ ${file##*/} != config.* ]]; then
			ln -sr "$pkgdir/$file" "$pkgdir/opt/$pkgname"
		fi
	done

	mkdir -p "$pkgdir"/usr/lib/systemd
	mv -T "$pkgdir/opt/$pkgname/systemd" "$pkgdir/usr/lib/systemd/system"

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	ln -sr "$pkgdir"/opt/$pkgname/README.md "$pkgdir"/usr/share/doc/$pkgname
}
