#!/bin/sh

PATH=/sbin:$PATH
export PATH

IMAGE=rescue.img
DIR=rescue
SIZE=3500

MNTPOINT=/tmp/mkimage.mnt-$$

if [ "$1" != "-f" ]; then
    if [ -f $IMAGE ]; then
	echo "$IMAGE already exists." >&2
	exit 1
    fi
fi

rm -f $IMAGE.nogz
dd if=/dev/zero of=$IMAGE.nogz bs=1k count=$SIZE
mke2fs -q $IMAGE.nogz $SIZE <<EOF
y
EOF

mkdir -p $MNTPOINT

mount -o loop -t ext2 $IMAGE.nogz $MNTPOINT

(cd $DIR; find . | cpio -vp $MNTPOINT)

df $MNTPOINT

umount $MNTPOINT
echo -n "gzipping image..."
gzip -9 < $IMAGE.nogz > ../../../images/$IMAGE
echo " done."

rm -rf $MNTPOINT 

size=`cat ../../../images/$IMAGE | wc -c`
echo "Rescue disk $size bytes"
filler=`expr 1474560 - $size`
dd if=/dev/zero bs=1 count=$filler >> ../../../images/$IMAGE
