# Contributor:
# Maintainer:
pkgname=lizardfs
pkgver=2.6.0
pkgrel=2
pkgdesc="a highly reliable, scalable and efficient distributed file system"
url="https://github.com/lizardfs/lizardfs/"
arch=""
license="GPL-3.0"
depends=""
depends_dev=""
makedepends="$depends_dev boost-dev cmake fuse-dev zlib-dev asciidoc python2"
pkgusers="mfs"
pkggroups="mfs"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-master $pkgname-metalogger
	$pkgname-chunkserver $pkgname-client $pkgname-cgi $pkgname-cgiserv
	$pkgname-adm"
source="lizardfs-$pkgver.tar.gz::https://github.com/lizardfs/lizardfs/archive/v$pkgver.tar.gz
	fix-headers.patch
	0001-common-Add-multi-platform-endian-conversion-function.patch

	lizardfs-cgiserv.initd
	lizardfs-chunkserver.initd
	lizardfs-master.initd
	lizardfs-metalogger.initd
	"

_builddir="$srcdir"/lizardfs-$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	mkdir -p build
}

build() {
	cd "$_builddir"/build
	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX="/" \
		-DENABLE_TESTS=NO \
		-DENABLE_DEBIAN_PATHS=YES \
		|| return 1
	make || return 1
}

package() {
	cd "$_builddir"/build
	make DESTDIR="$pkgdir" install || return 1
	chown -R mfs:mfs "$pkgdir"/var/lib/mfs
	for i in $source; do
		case $i in
		*.initd)
			install -Dm755 "$srcdir"/$i \
				"$pkgdir"/etc/init.d/${i%.*} || return 1
			;;
		esac
	done
}

_mv_files() {
	local i
	for i in "$@"; do
		case $i in
		*/*) mkdir -p "$subpkgdir"/${i%/*};;
		*) mkdir -p "$subpkgdir";;
		esac
		mv "$pkgdir"/$i "$subpkgdir"/$i || return 1
	done
}

master() {
	pkgdesc="LizardFS master server"
	depends="lizardfs=$pkgver-r$pkgrel"
	cd "$pkgdir"
	_mv_files \
		usr/sbin/mfsmaster \
		usr/sbin/mfsrestoremaster \
		usr/sbin/mfsmetadump \
		usr/sbin/mfsmetarestore \
		etc/mfs/mfsexports.cfg.dist \
		etc/mfs/mfstopology.cfg.dist \
		etc/mfs/mfsgoals.cfg.dist \
		etc/mfs/mfsmaster.cfg.dist \
		etc/mfs/globaliolimits.cfg.dist \
		var/lib/mfs/metadata.mfs.empty \
		etc/init.d/lizardfs-master \
		|| return 1
	chown -R mfs:mfs "$subpkgdir"/var/lib/mfs
}

metalogger() {
	pkgdesc="LizardFS metadata replication server"
	depends="lizardfs=$pkgver-r$pkgrel"
	cd "$pkgdir"
	_mv_files \
		usr/sbin/mfsmetalogger \
		etc/mfs/mfsmetalogger.cfg.dist \
		etc/init.d/lizardfs-metalogger \
		|| return 1
}

chunkserver() {
	pkgdesc="LizardFS data server"
	depends="lizardfs=$pkgver-r$pkgrel"
	cd "$pkgdir"
	_mv_files \
		usr/sbin/mfschunkserver \
		etc/mfs/mfschunkserver.cfg.dist \
		etc/mfs/mfshdd.cfg.dist \
		etc/init.d/lizardfs-chunkserver \
		|| return 1
}

client() {
	pkgdesc="LizardFS client"
	depends="fuse"
	cd "$pkgdir"
	_mv_files \
		usr/bin/mfstools \
		usr/bin/mfsmount \
		usr/bin/mfssnapshot \
		usr/bin/mfsappendchunks \
		usr/bin/mfscheckfile \
		usr/bin/mfsdeleattr \
		usr/bin/mfsdirinfo \
		usr/bin/mfsfileinfo \
		usr/bin/mfsfilerepair \
		usr/bin/mfsgeteattr \
		usr/bin/mfsgetgoal \
		usr/bin/mfsgettrashtime \
		usr/bin/mfsmakesnapshot \
		usr/bin/mfsrepquota \
		usr/bin/mfsrgetgoal \
		usr/bin/mfsrgettrashtime \
		usr/bin/mfsrsetgoal \
		usr/bin/mfsrsettrashtime \
		usr/bin/mfsseteattr \
		usr/bin/mfssetgoal \
		usr/bin/mfssetquota \
		usr/bin/mfssettrashtime \
		etc/mfs/mfsmount.cfg.dist \
		etc/mfs/iolimits.cfg.dist \
		|| return 1

}

cgi() {
	pkgdesc="LizardFS CGI Monitor"
	depends="python2"
	cd "$pkgdir"
	_mv_files \
		usr/share/mfscgi \
		|| return 1
}

cgiserv() {
	pkgdesc="Simple CGI-capable HTTP server to run LizardFS CGI Monitor"
	depends="$pkgname-cgi=$pkgver-r$pkgrel"
	cd "$pkgdir"
	_mv_files \
		usr/sbin/lizardfs-cgiserver \
		usr/sbin/mfscgiserv \
		etc/init.d/lizardfs-cgiserv \
		|| return 1
}

adm() {
	pkgdesc="LizardFS administration utility"
	depends=""
	cd "$pkgdir"
	_mv_files \
		usr/bin/lizardfs-admin \
		usr/bin/lizardfs-probe \
		|| return 1
}

md5sums="9765bca6f8812a6fbca58a04e2f33c6e  lizardfs-2.6.0.tar.gz
a04e01504edff691389236697d9e9f72  fix-headers.patch
8beae2dc879a6e3bc778fa63409dd5be  0001-common-Add-multi-platform-endian-conversion-function.patch
fcd290b193fbedc9035cbd4be46463b7  lizardfs-cgiserv.initd
deffb670f92d3675b8716c79d8ba954f  lizardfs-chunkserver.initd
3185ec14fe09cc7c74dc8c9b00b289e8  lizardfs-master.initd
17022128ce9dce94e632a59fbd2c5f05  lizardfs-metalogger.initd"
sha256sums="f7f7e3c64d4907db318113d224b9296ebcd629028ad3e13894eb592dac8d9161  lizardfs-2.6.0.tar.gz
2db07acf838c6b468d4ea3a5ad831e7cacf95a0067140d03640f9f01fde15175  fix-headers.patch
24a2b699fdf96c8ead795b5ad962502421bbac64a4bc4d7cf68dfaee16cc6b19  0001-common-Add-multi-platform-endian-conversion-function.patch
e080c484e67f6ec25816a5c90b12a3c867a5b123fa73aa9442f76bc5a8e90264  lizardfs-cgiserv.initd
b0157cf08cb22bdee27f9f88a11806341868102177021535e3ee66be5afd311b  lizardfs-chunkserver.initd
1ef583e31532a9012406be0643f432bc059dc22eacc71c9aca1d2cef722e67c7  lizardfs-master.initd
05b091d78fe3f4efab6ba916e0e91b0c628a9eb45244ee793bf473ccac825d6e  lizardfs-metalogger.initd"
sha512sums="a80277cf625e175728147f1850cc6ad234d490589a825bfede23e53720ffef7d8c5d21ed8ce6a31217c8901e04cb5c91ac581da3795a592756c5f8f3257537ff  lizardfs-2.6.0.tar.gz
eaeff3c67951bccb7e3963981c5bae2f582c6cddfadbd604f0151ace49ade0524d51665c7a7821b59c80d61aade05900368c9f7022793131f03e44df6c96c3f8  fix-headers.patch
f5c391717b36315ec62ee71a24d41409a5138d2ba3579e392e9b29c08bb4c8711c4f71440518cc6ee03f13cdb265515cc544f99b5c368717aae1da1a9ca9ca9f  0001-common-Add-multi-platform-endian-conversion-function.patch
2c78af05c2eeba866c25c58d996c64d16a590248660a362e29a52065af93c126c6eb3232c8cdbb797e60cca406608b77f29ce62717446b7c3d1a8d35e0a722d8  lizardfs-cgiserv.initd
f5de527f2c6f729d49c365cbac64d938d8f90de2c78ac2f4fdbb445532fbc6438ed7380b7963f70cfbf99d48282d7da6a8dbb3df9ae84ac7d2fcebda2ce308c8  lizardfs-chunkserver.initd
6234131965bf52ef0bb859a50010b649b10b81786ff302f6ff65429d03026b32d0e1ad2daeab99dea4bd8cc94ac5aed75707d640adf33b4fb79e22185e77ac01  lizardfs-master.initd
76951ecdbaa69cef0fc383bbc3d36b1eb00aced3c98750676ab159a44a9e50d29ebe188080a08a2a09df6c62f6899bb093cf94e9e3e1688826f5ff8dfdc0fa68  lizardfs-metalogger.initd"
