# Make the bulk directory, and a symlink to it in /tmp/tbup
# Check if there is enough space to hold a file of $psize bytes.
# (i.e. hold one part)


# 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 ! question "Delete old $bulkdir and continue"; then 
    echo "aborting..."
    cd /tmp
    rm -r /tmp/tbup
    exit 1
 fi

rm -r $bulkdir
fi

if [ ! -d `dirname $bulkdir` ]; then
 echo "Can't create $bulkdir, there is no directory `dirname $bulkdir`."
 exit 1
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'
