#!/bin/ash -efu

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

verbose "has started executing."

case "$PROG" in
	*-image-*) dir="$subdir" ;;
esac

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

hasher_args="${VERBOSE:+-v} ${QUIET:+-q} ${HSH_EXCLUDE_DOCS:+--excludedocs} ${HSH_NUMBER:+--number="$HSH_NUMBER"}"

reqlist=
for r in "$@"; do
	if [ -f "$r" ]; then
		reqlist="$reqlist $(grep -v '^[[:space:]]*#' "$r")"
	else
		reqlist="$reqlist $r"
	fi
done

if [ -n "$reqlist" ]; then
	printf '%s\n' "$reqlist" |
		tr ' ' '\n' |
		xargs -r env -i PATH="$PATH" hsh-install $hasher_args -- "$dir"
fi
