#!/bin/bash
#
#	readfsz {fs.z|-}
#
#	This script reads the compressed file system image from
#	/dev/fd0.  It tries to extract the starting block from the
#	kernel image, and if successful, writes the image to the
#	specified file (or stdout if the filename is `-').  Note
#	that there is no way to determine how big the image is,
#	so the output will be from the starting block to the end of
#	the disk.
#

[ $# -ne 1 ] && {
	echo "Usage: `basename $0` {fs.z|-}"
	exit 1
}

[ "$1" != - -a ! -f "$1" ] && {
	echo "`basename $0`: $1 not found"
	exit 2
}

fs=$1
[ "$fs" = - ] && fs=

start=`dd if=/dev/fd0 bs=1 count=2 skip=502 | hexdump -e '"%d"'`

[ -z "$start" ] && {
	echo "`basename $0`: couldn't find start of CRAM"
	exit 4
}

dd if=/dev/fd0 ${fs:+of=}$fs bs=1024 skip=$start
