#!/bin/sh

. config_build
. "$SCRIPTS"/misc/lib/lib_fail

if [ "$CLOOP" != "yes" ]; then
	exit 0
fi

echo "----------------------------------"
echo "     building the cloop image     "
echo "----------------------------------"
echo 
echo

# now copy the _cd tree to $TMPDIR
mkdir $TMPDIR/iso           || fail
mkdir $TMPDIR/iso/boot      || fail
mkdir $TMPDIR/_cd           || fail
cp -a $ROOTFS/* $TMPDIR/_cd || fail

# delete some files that are no longer needed
rm -rf $TMPDIR/_cd/dev/*         || fail
rm -rf $TMPDIR/_cd/var/*         || fail
rm -rf $TMPDIR/_cd/boot/boot.img || fail
mknod  $TMPDIR/_cd/dev/console c 5 1 || fail

cp $TMPDIR/_cd/README $TMPDIR/iso || fail

# now build the isofs image file
mkisofs -R $TMPDIR/_cd | create_compressed_fs - 65536 > $TMPDIR/rootfs.cloop.img || fail
mkisofs -R $TMPDIR/rootfs.cloop.img > $TMPDIR/iso/boot/rootfs.cloop_iso9660.img  || fail

mv $ROOTFS/boot/boot.img $TMPDIR/iso/boot/boot.img || fail

# clean up
rm -rf $TMPDIR/_cd          || fail
rm $TMPDIR/rootfs.cloop.img || fail

echo
