#!/bin/sh -eu

. sh-functions

cd "$rootdir"

mkdir $verbose -p -- \
	./conf \
	./dev \
	./etc/modprobe.d \
	./etc/udev/rules.d \
	./"$kernel_modules_dir" \
	./lib/udev \
	./mnt \
	./root \
	./proc \
	./sys \
	./tmp \
	./var/lock \
	#

[ -z "${PUT_DIRS-}"  ] || put-tree $PUT_DIRS
[ -z "${PUT_FILES-}" ] || put-file $PUT_FILES

# initrd specific files
put-tree "$datadir"

:>>./etc/fstab

if [ ! -x ./bin/sh ]; then
	for n in bash dash mksh ash; do
		[ -x ./bin/$n ] || continue
		verbose "Setting $n as /bin/sh ..."
		ln -s $n ./bin/sh
		break
	done
fi

if [ -f /etc/modprobe.conf ]; then
	verbose "Copying /etc/modprobe.conf ..."
	put-file /etc/modprobe.conf
fi

if [ -d /etc/modprobe.d ]; then
	verbose "Copying files from /etc/modprobe.d ..."
	find -L /etc/modprobe.d \
		\( \
			\! -name '*.rpm*' -a \
			\! -name '*~' \
		\) \
		-exec put-file '{}' '+'
fi

for d in lib etc; do
	[ -d "/$d/udev/initramfs-rules.d" ] ||
		continue
	verbose "Copying files from /$d/udev/initramfs-rules.d ..."
	find -L "/$d/udev/initramfs-rules.d" \
			-name '*.rules' \
		-exec cp -aLt ./etc/udev/rules.d -- '{}' '+'
	break
done
