#!/bin/ash -efu

. "${0%/*}"/mki-sh-functions

verbose "has started executing."

COPY_TREE="${COPY_TREE:?Data required}"

[ -d "$chroot" ] ||
	fatal "$dir: not look like a work directory of hasher."

for d in $COPY_TREE; do
	d="$(readlink -ve "$d")"

	get_copy_args "$d" "$chroot/"

	if [ -d "$d" ]; then
		find "$d" -mindepth 1 -maxdepth 1 \
			-execdir cp $cp_args -aft "$chroot/.in/" -- '{}' '+'
	else
		cp $cp_args -aft "$chroot/.in/" -- "$d"
	fi
done

mki-run -- /.host/find /.in -mindepth 1 -maxdepth 1 \
	-execdir cp $verbose -alft /.image/ -- '{}' '+'

find "$chroot/.in/" -mindepth 1 -maxdepth 1 \
	-execdir rm -rf -- '{}' '+'
