#!/bin/ash -efu
#
# mki-pack-custom
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

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

verbose "has started executing."

type="${MKI_PACKTYPE:?pack type required}"

outname="${MKI_OUTNAME:-outname}"
outname="${outname##*/}"

imgsubdir="${MKI_IMAGESUBDIR:-}"
imgsubdir="${imgsubdir#/}"

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

if [ -x "$type" ]; then
	message "$type: executable file."

	install -m755 -- "$type" "$chroot/.host/script.sh"

	run_chrooted "$chroot" <<-EOF
	#!/bin/sh -efu
	WORKDIR=/.image
	OUTNAME='/.our/$outname'
	SUBDIR='$imgsubdir'
	export WORKDIR OUTNAME SUBDIR
	/.host/script.sh
	EOF
else
	fatal "$type: unknown pack type."
fi

mki-copy-our2out
