#!/bin/rc
# uses a pre-existing wrarena command at /n/9fat/wrcmd to backup a venti
# the expected command looks about like this:
# wrarena -h tcp!192.168.1.123!17034 -o 537665536 /dev/sdC0/arenas 0x12224578
# ventiprog [ventilist]


rfork e
if(! test -e /n/9fat/wrcmd)
	9fat:
if(! test -e /n/9fat/wrcmd)
	exit no.wrcmd

if(! ~ $1 '')
	targetventis=$*

oldcmd=`{cat /n/9fat/wrcmd}
newoff=`{$oldcmd | grep offset |sed 's/.*0x/0x/g'}
if(~ $newoff ''){
	echo 'warning! ventiprog dump unsuccessful, aborting'
	exit no.newoff
}
if(! ~ $targetventis ''){
	for(i in $targetventis){
		nxtcmd=`{echo $oldcmd |sed 's/!.*!/!'$i'!/g'}
		$nxtcmd
	}
}
newcmd=`{echo $oldcmd |sed 's/0x.*/'$newoff'/g'}
echo $oldcmd >>/n/9fat/rootscor
echo $newcmd >>/n/9fat/rootscor
echo $newcmd >/n/9fat/wrcmd
echo $oldcmd
echo $newcmd
exit ''
