# Maintainer: Bernhard J. M. Gruen <bernhard.gruen@googlemail.com>
pkgname=burp
pkgver=2.1.30
pkgrel=2
pkgdesc="A network backup and restore program"
url="http://burp.grke.org"
arch="all"
license="AGPL-3.0-only"
makedepends="
	uthash-dev
	libressl-dev
	zlib-dev
	librsync-dev
	libtool
	automake
	autoconf
	"
checkdepends="
	check-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-server
	"
source="https://github.com/grke/$pkgname/archive/$pkgver.zip
	burp.init
	"
builddir="$srcdir/$pkgname-$pkgver"
# Check is deactivated as it needs --enable-forks in check/check-dev
options="!check"

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	cd "$builddir"
	./configure \
		--prefix=/usr \
		--sbindir=/usr/bin \
		--sysconfdir=/etc/burp \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-acl \
		--disable-xattr
	make
}

check() {
	cd "$builddir"
	make check
}

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install-all

	cd "$pkgdir"
	rm -rf var \
		etc/burp/autoupgrade \
		etc/burp/clientconfdir
	chmod -R go-rwx etc/burp
}

server() {
	pkgdesc="$pkgdesc (server configuration and helper scripts)"
	# bash is needed on the server to run burp_ca, timer and notify scripts
	# I am working on a version that does not need bash anymore
	depends="bash"

	cd "$builddir"

	mkdir -p "$subpkgdir"/var/spool/burp
	chmod 0755 "$subpkgdir"/var/spool
	chmod 0700 "$subpkgdir"/var/spool/burp

	mkdir -p "$subpkgdir"/usr/share/burp/scripts
	mv "$pkgdir"/usr/share/burp/scripts "$subpkgdir"/usr/share/burp
	rm -rf "$pkgdir"/usr/share

	mkdir -p "$subpkgdir"/etc/burp
	mv "$pkgdir"/etc/burp/CA.cnf "$subpkgdir"/etc/burp/CA.cnf
	mv "$pkgdir"/etc/burp/burp-server.conf \
		"$subpkgdir"/etc/burp/burp-server.conf

	install -Dm755 "$srcdir"/burp.init "$subpkgdir"/etc/init.d/burp

	mkdir -p "$subpkgdir"/usr/bin
	local name; for name in bedup bsigs bsparse burp_ca vss_strip; do
		mv "$pkgdir"/usr/bin/$name "$subpkgdir"/usr/bin/$name
	done
}

sha512sums="8a6f8a97ee1ccaef68897be1a667b4320767718dcc7697fc16549adbc207d1c36c721df43434df3add65868d0a310cfe379432272514085125887b8257b13f22  2.1.30.zip
13761c30315d1c647906b91efdc730ae573c3598b7429acc77f5d9e6b31458307b2553e1ef1b317a84c14205a2262af3d896e2674b3524b99cb5b463756a712b  burp.init"
