#!/bin/ash -efu

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

verbose "has started executing."

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

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

mki-install tar

cat >"$chroot/tmp/packimage.sh"<<EOF
#!/bin/sh -efu
cd /.image/

args=
[ ! -d .in ]       || args="\$args --exclude .in"
[ ! -d .host ]     || args="\$args --exclude .host"
[ ! -f .fakedata ] || args="\$args --exclude .fakedata"

exec tar --numeric-owner \$args -jcf '/.our/$outname' .
EOF

mki_exec_once "$chroot/tmp/packimage.sh"
mki-copy-our2out
