# Contributor: Laszlo Gombos <laszlo.gombos@gmail.com>
# Maintainer: Conrad Hoffmann <ch@bitfehler.net>
pkgname=dracut
pkgver=060
pkgrel=1
_commit=856e7acdb1462803c2517c8d64afb2e34c73c735
pkgdesc="An event driven initramfs infrastructure"
url="https://github.com/dracutdevs/dracut/wiki"
arch="all !riscv64" # textrel
license="GPL-2.0-or-later"
makedepends="asciidoc musl-fts-dev kmod-dev bash coreutils blkid findmnt eudev"
subpackages="$pkgname-modules-network:network $pkgname-modules:modules $pkgname-dev $pkgname-doc $pkgname-bash-completion $pkgname-tests $pkgname-core:core"
options="!check" # There is a test suite, but it requires root/sudo
triggers="$pkgname.trigger=/usr/share/kernel/*"
source="$pkgname-$pkgver.tar.gz::https://github.com/dracutdevs/dracut/archive/$_commit.tar.gz
	README.alpine
	10-alpine.conf
	initramfs-shell.patch
	"
provides="initramfs-generator"
provider_priority=100 # low, somewhat experimental
builddir="$srcdir"/$pkgname-$_commit

build() {
	./configure --sysconfdir="/etc"
	CFLAGS="$CFLAGS -D__GLIBC_PREREQ=" CWD="$(pwd)" make
}

package() {
	DESTDIR="$pkgdir" make install
	depends="$pkgname-core $pkgname-modules-network"
	rm -rf test/container test/TEST*SYSTEMD*
	mv test "$pkgdir"/usr/lib/dracut/
	install -Dm644 "$srcdir"/README.alpine -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 "$srcdir"/10-alpine.conf -t "$pkgdir"/usr/lib/dracut/dracut.conf.d/
}

network() {
	pkgdesc="network dracut modules"
	depends="dracut-modules dhclient iputils"

	for f in 35network-legacy 40network 45url-lib \
		90kernel-network-modules 90qemu-net 90livenet \
		95cifs 95fcoe 95fcoe-uefi 95iscsi 95nbd 95nfs 95ssh-client; do
		amove usr/lib/dracut/modules.d/$f
	done

	if [ "$CARCH" = "s390x" ]; then
		amove usr/lib/dracut/modules.d/95zfcp
		amove usr/lib/dracut/modules.d/95znet
	fi
}

modules() {
	pkgdesc="local dracut modules"
	depends="dracut-core eudev util-linux-misc sed losetup"
	rm -rf "$pkgdir"/usr/lib/dracut/modules.d/*systemd*
	rm -rf "$pkgdir"/usr/share/man/man8/*.service.*
	rm -rf "$pkgdir"/usr/lib/kernel

	# systemd or distro dependent additional dracut modules
	for f in 06rngd 06dbus-broker 06dbus-daemon 09dbus 35connman \
		35network-manager 45ifcfg 62bluetooth 80lvmmerge \
		91fido2 91pcsc 91pkcs11 91tpm2-tss 99memstrack 99squash; do
		rm -rf "$pkgdir"/usr/lib/dracut/modules.d/$f
	done

	if [ "$CARCH" != "s390x" ]; then
		for f in 80cms 81cio_ignore 91zipl 95dasd 95dasd_mod \
			95dasd_rules 95dcssblk 95qeth_rules 95zfcp \
			95zfcp_rules 95znet; do
			rm -rf "$pkgdir"/usr/lib/dracut/modules.d/$f
		done
	else
		rm -rf "$pkgdir"/usr/lib/dracut/modules.d/00warpclock
	fi

	amove usr/lib/dracut/modules.d
}

core() {
	pkgdesc="core tools for dracut"
	depends="bash coreutils blkid findmnt grep"
	amove etc usr
}

tests() {
	pkgdesc="dracut tests"
	depends="dracut-modules e2fsprogs make qemu-img qemu-system-x86_64 sfdisk sudo"
	amove usr/lib/dracut/test
}

sha512sums="
0cd2fefcd624758063c77836989260a3d5b0d533004c2395124c8200c31602f5d7d0b8c9491de37ce4afb2c5009b2cf944ddd3bb9e0e11120d84176cb1e7423c  dracut-060.tar.gz
fa1d65d8987d9b5846f5cd7989bc373ca4f9d787a3025284ce55e2d5439dce29f70bd75ff5e07bfa783548e080859ec8972b6887ec58993bc54a8dcc849066d6  README.alpine
8688380dd77949d039a22a0dfb34c67cedd48b45a346a2e5f8b9ce9bd9872a8b1b9e06a51edf75d548b5072243afdb08d7ad25616a82cd030de432bb9e14da47  10-alpine.conf
54d6292a5360145c135f670a5f69cf317e2e03c34495efc7c134c0bf68e09ae27c8cf9fc7434b9742f6dc6e230b0161566c25796956a4fdf35700cd34d1626e8  initramfs-shell.patch
"
