#!/bin/bash
cd /usr/lib/tbackup
export bupbin=/usr/lib/tbackup/bin
export PATH=$bupbin\:$PATH

trap "rm -f /etc/tbackup/Floppy; echo "Aborting..."; exit 1" 2

#ask a value for a parameter.
# arguments: parameter name value 1 value 2
function getab ()
{
while true; do

  printf "(%s/%s) ---> " $2 $3

 enter -f
 read
 
 if [ "$REPLY" = "" ]; then continue; fi
 if [ "$REPLY" = "$2" ]; then break; fi
 if [ "$REPLY" = "$3" ]; then break; fi
done
export $1=$REPLY
}

rm -f /etc/tbackup/Floppy
echo "#If your floppy drive configuration changes, remove this file and" >/etc/tbackup/Floppy
echo "#run \`make install' in /usr/lib/tbackup." >>/etc/tbackup/Floppy


echo 
printf "How many floppy drives do you have? "
getab numdrives 1 2

nr=0
while [ $nr -lt $numdrives ]; do

echo
printf "Is drive number %s a 5.25\" drive or a 3.5\" drive ? " $nr
getab inch 5 3

if [ $inch = 5 ]; then inch=5.25; fi
if [ $inch = 3 ]; then inch=3.5; fi

printf "Is drive number %s a high density drive ? " $nr
getab high y n

if [ $high = n ]; then in=indd; fi
if [ $high = y ]; then in=inhd; fi

grep -v "^#" $bupbin/Floppyinfo | grep $inch | grep $in | \
gawk "{ printf \"/dev/fd$nr%s\\n\",\$0 }" >>/etc/tbackup/Floppy

nr=`expr $nr + 1`
done

echo
cat - <<-'blexta'
Extended floppy densities fit more data on a floppy by going outside
the `factory specifications' of the floppies and drives.  For example,
on 3.5" DD floppies, the normal double density format uses 80 tracks
and 9 sectors per track, the `extended double density' format uses 82
tracks and 10 sectors per track, which fits 820 Kb. on the floppy.

Not all floppies and/or floppy drives are able to go outside their
`factory specifications' and hold extra data.  Also, due to
limitations in the Linux kernel, reading and writing 1.7 Mb. on 3.5"
HD floppies is extremely slow.

If you want maximal safety, I recommend you never use extended floppy
densities.
blexta

echo
echo -n "Do you want to disable the extended density option? "
getab noxdens y n

if [ $noxdens = y ]; then 
 mv -f /etc/tbackup/Floppy /etc/tbackup/Floppy.tmp
 grep -v xdens  /etc/tbackup/Floppy.tmp > /etc/tbackup/Floppy
 rm /etc/tbackup/Floppy.tmp
fi

echo
echo configuration file /etc/tbackup/Floppy written.

fdmake
