# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
setvar pkgname = 'repmgr'
setvar pkgver = '3.3.2'
setvar pkgrel = '2'
setvar pkgdesc = ""Replication Manager for PostgreSQL""
setvar url = ""http://www.repmgr.org/""
setvar arch = ""all""
setvar license = ""GPL-3""
setvar depends = ""postgresql-client""
setvar makedepends = ""postgresql-dev""
setvar pkgusers = ""postgres""
setvar subpackages = ""$pkgname-doc $pkgname-daemon""
setvar source = ""$pkgname-$pkgver.tar.gz::https://github.com/2ndQuadrant/$pkgname/archive/v$pkgver.tar.gz
	repmgr.conf.patch
	repmgrd.initd""
setvar builddir = ""$srcdir/$pkgname-$pkgver""
setvar options = ""!checkroot""

proc build {
	cd $builddir
	make USE_PGXS=1
}

proc check {
	cd $builddir
	./repmgr --version
	./repmgrd --version
}

proc package {
	cd $builddir

	make USE_PGXS=1 DESTDIR="$pkgdir" install

	install -D -m 640 -o postgres -g postgres \
		repmgr.conf.sample "$pkgdir"/etc/repmgr.conf

	cd $pkgdir

	mkdir -p usr/share/doc/$pkgname
	cp "$builddir"/*.md "$builddir"/docs/*.md usr/share/doc/$pkgname/
}

proc daemon {
	setvar pkgdesc = ""A management and monitoring daemon for PostgreSQL Replication Manager""
	setvar depends = "$pkgname"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/repmgrd "$subpkgdir"/usr/bin/

	install -D -m 755 "$srcdir"/repmgrd.initd "$subpkgdir"/etc/init.d/repmgrd
}

setvar sha512sums = ""98fba8fc0d9074e496c66762dbec45734fe279f39c9c51adb3e66dca929ac37f66a609789c8c658545856fd81f5afc5b35f6b5e389e52bce8c04ce8c52acd8dd  repmgr-3.3.2.tar.gz
235a17d54ccce9e23b59919c0406fc3618f722e4f7559af6102c561668319a47beca7b70a9564432cb45bbbee091de9fc748935e7c771f1c84cfd40ab6e401a7  repmgr.conf.patch
4ea90fc4b07898235eb3fd441a9f9857d2309e8c124e8e274ddcb44750db7aa2f59f03ac284ecba9150c1e17a8ae173cc5f493abfdc2b66cac3444802379c6e0  repmgrd.initd""