# Make the bulk directory, and a symlink to it in /tmp/tbup

#Only make if not already made.
if [ "$rmbulkdir" = "echo -n" ]; then

# make the bulkdir.

echo "  [Creating directory $bulkdir for temporary storage.]"

if [ -e $bulkdir ]; then
 echo "There already exits a directory $bulkdir !!"
 echo " This means that"
 echo "  1) another tbackup or trestore command is running, if this is the case"
 echo "     you should wait till it has terminated, or"
 echo "  2) a tbackup or trestore command terminated abnormally, in that case, you can"
 echo "     answer yes to the following question."
 echo "  3) someone is using $bulkdir to store data."
 echo "     In this case, answer no to the following question and reconfigure"
 echo "     tbackup and trestore (see README file)."
 echo 

 if [ $batchmode = y ]; then
   echo
   echo "Can't resolve this in batch mode."
   doabort
 fi

 if ! question "Delete old $bulkdir and continue"; then 
    doabort
 fi

rm -r $bulkdir
fi

if [ ! -d `dirname $bulkdir` ]; then
 echo "Can't create $bulkdir, there is no directory `dirname $bulkdir`."
 doabort
fi

#make the dir.

mkdir $bulkdir
#prevent users from extracting (secret) files from the archive parts
#when they appear in bulkdir
chmod 700 $bulkdir

#create link.

ln -s $bulkdir /tmp/tbup/bulk

export rmbulkdir='rm -r $bulkdir'

#For the sort commands called by lapback.
export TMPDIR=$bulkdir

fi