# Template file for 'bacula-common'
pkgname="bacula-common"
version="9.0.4"
revision=3
build_style=gnu-configure
_common_desc="Bacula - A Network Backup Tool "
short_desc="${_common_desc} (common libs)"
maintainer="Matthias Fulz <mfulz@olznet.de>"
license="AGPL-3"
homepage="http://www.bacula.org"
distfiles="${SOURCEFORGE_SITE}/bacula/bacula-${version}.tar.gz"
checksum=cafa2d9a9e89a77d3b79984972487e72fb90d949269c77a74a68e97a9d28996f
configure_args="
 --with-openssl --with-sqlite3 --with-mysql --with-postgresql
 --enable-smartalloc --sysconfdir=/etc/bacula
 --with-scriptdir=/etc/bacula/scripts
 --with-working-dir=/run/bacula"
makedepends="sqlite-devel libmariadbclient-devel postgresql-libs-devel
 libressl-devel ncurses-devel zlib-devel acl-devel"
wrksrc="${pkgname%-*}-${version}"
shlib_provides="libbaccats-${version}.so"
alternatives="bacula-db-backend:/usr/lib/libbaccats-${version}.so:/usr/lib/libbaccats-sqlite3-${version}.so"

case "$XBPS_TARGET_MACHINE" in
	armv[56]*) makedepends+=" libatomic-devel" ;;
esac

post_install() {
	rm "${DESTDIR}/usr/bin/bacula"
	rm -rf "${DESTDIR}/usr/share/doc"
	rm "${DESTDIR}/usr/share/man/man1/bat.1.gz"
}

bacula-console_package() {
	short_desc="Bacula - A Network Backup Tool (management cli)"
	conf_files="/etc/${pkgname%-*}/bconsole.conf"
	depends="bacula-common"
	pkg_install() {
		vmove "etc/${pkgname%-*}/bconsole.conf"
		vmove "etc/${pkgname%-*}/scripts/bconsole"
		vmove "usr/bin/bconsole"
		vmove "usr/share/man/man8/bconsole.8.gz"
	}
}

bacula-fd_package() {
	short_desc="Bacula - A Network Backup Tool (file daemon)"
	conf_files="/etc/${pkgname%-*}/${pkgname}.conf"
	depends="bacula-common"
	pkg_install() {
		vmove "etc/${pkgname%-*}/${pkgname}.conf"
		vmove "usr/bin/${pkgname}"
		vmove "usr/lib/bpipe-fd.so"
		vmove "usr/share/man/man8/${pkgname}.8.gz"
		vsv "${pkgname}"
	}
}

bacula-sd_package() {
	short_desc="Bacula - A Network Backup Tool (storage daemon)"
	conf_files="/etc/${pkgname%-*}/${pkgname}.conf"
	depends="bacula-common"
	pkg_install() {
		vmove "etc/${pkgname%-*}/${pkgname}.conf"
		for x in ${pkgname} bextract bls bcopy bscan btape; do
			vmove "usr/bin/$x"
			vmove "usr/share/man/man8/$x.8.gz"
		done
		vsv "${pkgname}"
	}
}

bacula-dir_package() {
	short_desc="Bacula - A Network Backup Tool (director daemon)"
	conf_files="/etc/${pkgname%-*}/${pkgname}.conf"
	depends="bacula-common"
	pkg_install() {
		vmove "etc/${pkgname%-*}/${pkgname}.conf"
		vmove "etc/${pkgname%-*}/scripts/query.sql"
		vmove "etc/${pkgname%-*}/scripts/create_${pkgname%-*}_database"
		vmove "etc/${pkgname%-*}/scripts/delete_catalog_backup"
		vmove "etc/${pkgname%-*}/scripts/drop_${pkgname%-*}_database"
		vmove "etc/${pkgname%-*}/scripts/drop_${pkgname%-*}_tables"
		vmove "etc/${pkgname%-*}/scripts/grant_${pkgname%-*}_privileges"
		vmove "etc/${pkgname%-*}/scripts/make_${pkgname%-*}_tables"
		vmove "etc/${pkgname%-*}/scripts/make_catalog_backup.pl"
		vmove "etc/${pkgname%-*}/scripts/make_catalog_backup"
		vmove "etc/${pkgname%-*}/scripts/update_${pkgname%-*}_tables"
		vmove "usr/bin/bsmtp"
		vmove "usr/share/man/man1/bsmtp.1.gz"
		for x in ${pkgname} bregex bwild dbcheck; do
			vmove "usr/bin/$x"
			vmove "usr/share/man/man8/$x.8.gz"
		done
		vsv "${pkgname}"
	}
}

bacula-common-mariadb_package() {
	short_desc="${_common_desc} (MariaDB support)"
	depends="bacula-common"
	alternatives="bacula-db-backend:/usr/lib/libbaccats-${version}.so:/usr/lib/libbaccats-mysql-${version}.so"
	pkg_install() {
		vmove "usr/lib/libbaccats-mysql-${version}.so"
		vmove "usr/lib/libbaccats-mysql.so"
		for file in etc/bacula/scripts/*mysql*; do
			vmove "$file"
		done
	}
}

bacula-common-postgresql_package() {
	short_desc="${_common_desc} (PostgreSQL support)"
	depends="bacula-common"
	alternatives="bacula-db-backend:/usr/lib/libbaccats-${version}.so:/usr/lib/libbaccats-postgresql-${version}.so"
	pkg_install() {
		vmove "usr/lib/libbaccats-postgresql-${version}.so"
		vmove "usr/lib/libbaccats-postgresql.so"
		for file in etc/bacula/scripts/*postgresql*; do
			vmove "$file"
		done
	}
}
