# Template file for 'initramfs-tools'
pkgname=initramfs-tools
_localver=110		# This is the XBPS version
_distver=0.99		# This should match debian version
version=${_distver}.${_localver}
short_desc="Tools for generating an initramfs"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://code.google.com/p/xbps"
license="GPL-2"
long_desc="
 This package contains tools to create and boot an initramfs for packaged
 Linux kernel. The initramfs is a gzipped cpio archive. At boot time, the
 kernel unpacks that archive into RAM, mounts and uses it as initial root
 file system. The mounting of the real root file system occurs in early user
 space. Having the root on EVMS, MD, LVM2, LUKS or NFS is also supported.
 Any boot loader with initrd support is able to load an initramfs archive."

noextract=yes
noarch=yes
triggers="initramfs-tools"
conf_files="
/etc/$pkgname/initramfs.conf
/etc/$pkgname/update-initramfs.conf
/etc/$pkgname/modules"

make_dirs="
/etc/$pkgname/hooks				0755	0	0
/etc/$pkgname/conf.d				0755	0	0
/etc/$pkgname/scripts/init-bottom		0755	0	0
/etc/$pkgname/scripts/init-premount		0755	0	0
/etc/$pkgname/scripts/init-top			0755	0	0
/etc/$pkgname/scripts/local-bottom		0755	0	0
/etc/$pkgname/scripts/local-top 		0755	0	0
/usr/share/$pkgname/conf.d			0755	0	0
/usr/share/$pkgname/hooksconf.d 		0755	0	0
/usr/share/$pkgname/modules.d			0755	0	0
/usr/share/$pkgname/scripts/init-premount	0755	0	0
/usr/share/$pkgname/scripts/local-top		0755	0	0
/var/lib/$pkgname				0755	0	0
"

Add_dependency full cpio
Add_dependency full util-linux
Add_dependency full gawk
Add_dependency full findutils
Add_dependency full sed
Add_dependency full grep
Add_dependency full gzip
Add_dependency full bzip2
Add_dependency full xz
Add_dependency full udev
Add_dependency full module-init-tools
Add_dependency full busybox	">=1.19.2" # loadkmap
Add_dependency full klibc-resume

do_install()
{
	# /etc config files
	vinstall $FILESDIR/conf/initramfs.conf 644 etc/$pkgname
	vinstall $FILESDIR/conf/update-initramfs.conf 644 etc/$pkgname

	# Data
	vinstall $FILESDIR/init 744 usr/share/$pkgname
	for f in functions local nfs; do
		vinstall $FILESDIR/scripts/$f 644 usr/share/$pkgname/scripts
	done
	vmkdir usr/share/$pkgname/scripts/init-top
	install -m755 $FILESDIR/scripts/init-top/* \
		$DESTDIR/usr/share/$pkgname/scripts/init-top
	vmkdir usr/share/$pkgname/scripts/local-premount
	install -m755 $FILESDIR/scripts/local-premount/* \
		$DESTDIR/usr/share/$pkgname/scripts/local-premount
	vmkdir usr/share/$pkgname/hooks
	install -m755 $FILESDIR/hooks/* $DESTDIR/usr/share/$pkgname/hooks
	install -m644 $FILESDIR/hook-functions $DESTDIR/usr/share/$pkgname
	vinstall $FILESDIR/conf/modules 644 etc/$pkgname

	# Examples
	vmkdir usr/share/doc/$pkgname/examples
	install -m644 $FILESDIR/docs/* $DESTDIR/usr/share/doc/$pkgname/examples
	
	# Manpages
	vmkdir usr/share/man/man5
	install -m 644 $FILESDIR/*.5 $DESTDIR/usr/share/man/man5
	vmkdir usr/share/man/man8
	install -m 644 $FILESDIR/*.8 $DESTDIR/usr/share/man/man8

	# Scripts
	vmkdir usr/sbin
	install -m 755 $FILESDIR/mkinitramfs $DESTDIR/usr/sbin
	install -m 755 $FILESDIR/update-initramfs $DESTDIR/usr/sbin
	sed -i -e "s|@VERSION@|${version}|g" $DESTDIR/usr/sbin/update-initramfs

	# bash_completion.d
	install -Dm644 $FILESDIR/bash_completion.d/initramfs-tools \
		${DESTDIR}/etc/bash_completion.d/initramfs-tools

	# Kernel hooks
	vinstall ${FILESDIR}/kernel.d/${pkgname}.postinst \
		755 etc/kernel.d/post-install 10-${pkgname}
	vinstall ${FILESDIR}/kernel.d/${pkgname}.postrm \
		755 etc/kernel.d/post-remove 10-${pkgname}
}