#!/bin/sh

P=/tmp/ports.tar.gz
#D=/dev/mirror/gm0
D0=/dev/ad4
D1=/dev/ad8
mp0=/mnt/tmp/0
mp1=/mnt/tmp/1
if [ -n "$1" -a -n "$2" ]; then
    Te=$1
    Tr=$2
else
    exit 2
fi

Te0=`mktemp -t timetmp` || exit 1
Te1=`mktemp -t timetmp` || exit 1
Tr0=`mktemp -t timetmp` || exit 1
Tr1=`mktemp -t timetmp` || exit 1

unset LANG

set -e

newfs ${D0} >/dev/null &
newfs ${D1} >/dev/null &
wait

mount ${D0} ${mp0}
mount ${D1} ${mp1}

time -p -o $Te0 tar -C ${mp0} -xf $P &
time -p -o $Te1 tar -C ${mp1} -xf $P &
wait

sync ; sync ; sync ; sync ; sync
time -p -o $Tr0 rm -rf ${mp0}/ports &
time -p -o $Tr1 rm -rf ${mp1}/ports &
wait

sync ; sync ; sync ; sync ; sync
umount ${mp0} &
umount ${mp1} &
wait

# Since we have two par. runs we know take the numbers from the one that
# took the longest.  For this test it doesn't matter too much when each
# of the jobs finished, compared to each other.

# Note we assume all numbers have the same number of decimans after .
Te0r=`grep real $Te0 | cut -f 2 -d ' ' | tr -d .`
Te1r=`grep real $Te1 | cut -f 2 -d ' ' | tr -d .`
if [ $Te0r -gt $Te1r ]; then
	mv $Te0 $Te
else
	mv $Te1 $Te
fi

Tr0r=`grep real $Tr0 | cut -f 2 -d ' ' | tr -d .`
Tr1r=`grep real $Tr1 | cut -f 2 -d ' ' | tr -d .`
if [ $Tr0r -gt $Tr1r ]; then
	mv $Tr0 $Tr
else
	mv $Tr1 $Tr
fi

