#!/bin/sh -e

[ -n "$spt_dir" ] || spt_dir=/usr/share/spt3
. $spt_dir/init

Verbose "Packing chroot in tarball"

chroot_install tar

case "$COMPRESSION" in
gzip|-z)
	TAR_OPTIONS=-z
	[ -z "$IMAGE_NAME" ] && IMAGE_NAME=image.tar.gz
	;;
bzip2|-j)
	TAR_OPTIONS=-j
	[ -z "$IMAGE_NAME" ] && IMAGE_NAME=image.tar.bz2
	;;
*)
	TAR_OPTIONS=
	[ -z "$IMAGE_NAME" ] && IMAGE_NAME=image.tar
	;;
esac

# / -e /.image.tar.gz /.host /.in /.out /.fakedata /usr/lib*/*fakeroot* \
chroot_run \
	tar -c $verbose $TAR_OPTIONS \
	'--exclude=.*' \
	'--exclude=/usr/lib*/*fakeroot*' \
	--numeric-owner -f /.image / \
	|| Fatal "Unable to create a tarball"

mv -f $chroot/.image "$out_dir/$IMAGE_NAME"
