#!/bin/ash -efu

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

cleanup="${CLEANUP_OUTDIR:-}"
level="${MAKELEVEL:-}"

verbose "has started executing."

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

get_copy_args "$outdir/" "$chroot/.our/"

[ -z "$cleanup" -o "$level" = "1" ] ||
	find "$outdir/" -mindepth 1 -maxdepth 1 -execdir rm $verbose -rf -- '{}' '+'

cd "$chroot/.our"
find -mindepth 1 -maxdepth 1 |
	xargs -r cp $cp_args $verbose -aft "$outdir" --

mki-run -- /.host/find /.our -mindepth 1 -maxdepth 1 -execdir rm -rf -- '{}' '+'
