#!/bin/sh
# Show gauge based on df (disk free)
# Faster than du method, but can be used on a partition only
# Call this:
# du DEVICE TOTAL_SIZE MSG

DEVICE=$1
tot=$2
NAME=$3
line=$(df $DEVICE | grep $DEVICE)
start=$(echo $line | cut -f 3 -d ' ')
mbtot=`expr $tot / 1024`
pct=1
oldpct=1
(
while [ ! "$pct" = "100" ]; do
    line=$(df $DEVICE | grep $DEVICE)
    tst=$(echo $line | cut -f 3 -d ' ')
    progress=`expr $tst - $start`
    mbprog=`expr $progress / 1024`
    pct=`expr 100 '*' $progress / $tot`
    if [ "$pct" -gt "99" ] ; then
	tot=`expr $tot + $tot / 300`
	pct=99
    fi
    #echo $progress = $tst - $start 
    echo "XXX"
    echo $pct
    echo "\nInstalling $NAME ($mbprog of $mbtot MB)"
    echo "XXX"
    ps aux | grep "tar -x" >/dev/null
    if [ $? != 0 ]; then
	echo "XXX"
	pct=100
	echo $pct
	echo "\nInstall of $NAME is complete!"
	echo "XXX"
	echo "Install $NAME = $mbprog MB" >> /tmp/setup.log 
	exit
    fi
    sleep 2
done 
) | dialog --backtitle "Vector Linux Install" --title " Please Wait...." --gauge "" 8 66 0
