#!/bin/sh
#
# Write partition-image back to disk
#
# Copyright (c) 2003-2006 Hubert Feyrer <hubert@feyrer.de>
#

disk=$1
part=$2
file=$3

if [ "$part" = "" -o "$file" = "" -o ! -f "$file" ]; then
	echo "Usage: $0 disk partition file"
	echo "e.g.   $0 wd0 e wd0e.gz"
	echo "e.g.   GZIP=1 $0 wd0 e wd0e.gz"
	exit 1
fi

#        size   offset     fstype   [fsize bsize   cpg]
#   a:   205632        0     4.2BSD     1024  8192    16   # (Cyl.    0 - 203)

set `disklabel $disk | sed -n '/^.'${part}':/p'`
size=$2
offset=$3

echo partition $part: size=$size, offset=$offset


echo "gzip -cd $file | dd of=/dev/${disk}d bs=512 count=$size seek=$offset"

for i in 5 4 3 2 1 ; do
	echo $i ; sleep 1
done

echo ""
echo Data written:
progress -zf $file dd of=/dev/${disk}d bs=512 count=$size seek=$offset
