# Contributor:
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname="backuppc"
_realname="BackupPC"
pkgver=3.3.2
pkgrel=0
pkgdesc="High-performance, enterprise-grade backup system"
url="http://backuppc.sourceforge.net/"
arch="noarch"
license="GPL-2.0-or-later"
depends="perl busybox rsync perl-archive-zip perl-io-compress
	perl-libwww perl-file-rsync samba-client"
pkgusers="backuppc"
pkggroups="backuppc"
install="$pkgname.pre-install"
source="http://downloads.sourceforge.net/project/$pkgname/$pkgname/$pkgver/$_realname-$pkgver.tar.gz
	$pkgname.initd

	configure.pl.patch
	fix-pidfile-path.patch
	fix-socket-path.patch
	"
builddir="$srcdir/$_realname-$pkgver"

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/etc/BackupPC \
		 "$pkgdir"/var/www/cgi-bin \
		 "$pkgdir"/var/www/htdocs/BackupPC || return 1

	perl configure.pl \
		--batch \
		--backuppc-user=backuppc \
		--bin-path bzip2=/usr/bin/bzip2 \
		--bin-path cat=/bin/cat \
		--bin-path df=/bin/df \
		--bin-path tar=/bin/tar \
		--bin-path hostname=/bin/hostname \
		--bin-path nmblookup=/usr/bin/nmblookup \
		--bin-path perl=/usr/bin/perl \
		--bin-path ping=/bin/ping \
		--bin-path rsync=/usr/bin/rsync \
		--bin-path sendmail=/usr/sbin/sendmail \
		--bin-path smbclient=/usr/bin/smbclient \
		--bin-path split=/usr/bin/split \
		--bin-path ssh=/usr/bin/ssh \
		--compress-level=3 \
		--dest-dir="$pkgdir" \
		--config-dir /etc/BackupPC \
		--cgi-dir /var/www/cgi-bin \
		--data-dir /var/lib/BackupPC \
		--hostname backuppc \
		--html-dir /var/www/htdocs/BackupPC \
		--html-dir-url /BackupPC \
		--install-dir /usr/share/BackupPC \
		--log-dir /var/log/BackupPC \
		--uid-ignore \
		--no-set-perms || return 1

	install -m755 configure.pl \
		"$pkgdir"/usr/share/BackupPC/bin/configure.pl || return 1
	install -D -m755 "$srcdir"/backuppc.initd \
		"$pkgdir"/etc/init.d/backuppc || return 1

	chmod 775 "$pkgdir"/usr/share/BackupPC/bin/*

	local dir; for dir in etc var/log var/lib; do
		chown -R backuppc:backuppc "$pkgdir"/$dir/BackupPC || return 1
		chmod 755 "$pkgdir"/$dir || return 1
	done

	ln -s /var/www/cgi-bin/BackupPC_Admin "$pkgdir"/var/www/htdocs/index.cgi || return 1
}

sha512sums="26176398cc619be05f864b56cb1d259f5eb6814bbe0fd30bd1527f6705dff175999c2b4e8a8767db0c5e0826065788f17d3ccdb5dbb608b62a7f56035fdc052b  BackupPC-3.3.2.tar.gz
a38361fd0e54a4c0100a7bf94b09483e5ba246dc45d6955d275542dd5662d8da11d9580685195b7d4dfa9a07c0487a52a14a95340737e70889ffe5c5e26d5ff8  configure.pl.patch
15fdb58e038160775fe4deebf6c8adbc128a37da2a866ef00e1eea202c396220cdd1c0547a45f11127dbdc957eaed5188cb87a05467d25647fb462be28c51ce7  fix-pidfile-path.patch
4391bdfaa3044a4eecec617fbcba1bf21bdd9389e3d3a73f62e74e6b818de40fc1600e26b358cf35a6bac01086ed12a3ff7abba64e67d11c7a91b2046c239189  fix-socket-path.patch
288bba10ca4dd585638625321395e0a40aca30169a122c443f7c6fcd55143e6fcdfa5d39595bacf06cc4960b6e17992a57ec3d3a7ddd9b140e44da4ebdd019d3  backuppc.initd"
