#!/bin/bash

cd /tmp

# make the dir /tmp/tbup

if [ -e tbup ]; then
 echo "There already is a directory /tmp/tbup !!"
 echo " This means that"
 echo "  1) another tbackup or trestore command is running, if this is the"
 echo "     case you should wait till it has terminated, or"
 echo "  2) a tbackup or trestore command terminated abnormally, in that case"
 echo "     you can answer yes to the following question."

#This is a kludge to prevent trouble when run as an at job.  We have
#not processed the arguments at this point, so we don't know if we are
#in batch mode yet.  This prevents tbackup waiting forever in the question.
 if [ $batchmode = y ]; then
  echo "Can't resolve this problem in batch mode."
  echo "Aborting..."
  exit 1
 fi
 
 if ! question "Delete old /tmp/tbup and continue"; then exit; fi
 
 rm -r /tmp/tbup
fi

mkdir tbup
#prevent other users from reading named pipes etc.
chmod 700 tbup

