#!/bin/bash
#
# This program is part of the three backup (tbackup) package,
# (c) 1993,1994 Koen Holtman.

export bupbin=/usr/lib/tbackup/bin
export bupdir=/usr/lib/tbackup
export PATH=$bupbin\:$PATH
export ttytitle=guess

source tinit

#get method names and parameters
source getguesspars

#add name and date to descr file
echo "Made with tbackup ($version)" >>descr
printf "by %s@%s.%s, on " `whoami` `hostname` `domainname` >>descr
date >>descr

source makelogtty

#exit if pars argument given.
if [ "$only_params" = "y" ]; then
 cp /tmp/tbup/allpars /etc/tbackup/allpars
 echo
 echo The supplied parameters are recorded in the file /etc/tbackup/allpars.
 echo
 echo Cleaning up....
 cd /tmp
 rm -rf /tmp/tbup
 eval $rmbulkdir
 exit 0
fi


echo
echo Guess description:
gawk '{ print "     " $0; }' descr
if [ $makeindexfile = y ]; then
 echo "Guess index file is $indexfilename."
fi

echo
echo "Guess in progress..."
echo

# make named pipes

mkfifo -m 700 choice


# execute guess
# choosemethod and packmethod are supposed to start background tasks.
# writemethod should return if the archive is written.

cd /tmp/tbup
source $choosemethod\.cx

source doguess


#do not finalise choose method here.


echo >logttydev
echo "---------Guess completed---------" >logttydev


# if making one, stop flowpause etc that take care of index file.
if [ $makeindexfile = y ]; then
  kill $holdfifopid
fi

echo "Cleaning up..."
cd /tmp

#sleep 1 added to prevent race condition (?) in the kernel.
sleep 1

rm -rf /tmp/tbup
eval $rmbulkdir
eval $resetfloppy
sync

echo
echo "Guess completed."
