#general initialisations.

export version="V0.8"

# add /auxbin to path if it exists.
if [ -e /auxbin ]; then
 export PATH=/auxbin:$PATH
fi

# running as root?
if [ $UID != 0 ]; then 
 echo "$0 should be run by root!!"
 exit 1
fi

export userwd=`pwd`

#routines for getting parameters
source paramrouts

# make temp dirs.
source makedirs

unset logpars_done
unset only_params

cd /tmp/tbup

unset no_dirnames

export rmbulkdir='echo -n'
export resetfloppy='echo -n'

#provide a clean abort.
trap 'trap "" 2; echo; echo -n "Aborting..."; cd /tmp; trap "" 15; kill 0; wait; rm -rf /tmp/tbup; eval $rmbulkdir; eval $resetfloppy; echo; exit' 2

# get parameters

#reset params file.
cat /dev/null >allpars

#get configuration parameters.
if [ -f /etc/tbackup/Config ]; then
 source /etc/tbackup/Config
else
 echo Error: configuration script /etc/tbackup/Config not found.
 echo aborting....
 cd /tmp
 rm -r /tmp/tbup
 exit 1
fi


#read defaults
source $bupbin/t$ttytitle.dea
if [ -f /etc/tbackup/t$ttytitle.dea ]; then
 source /etc/tbackup/t$ttytitle.dea
fi


#execute arguments, these may control the further execution
#by setting dea_,pre_, and checkpre_  parameters.

while [ "$*" != "" ]; do
 com="$1"
#strip off leading - if present.
 case $1 in -* ) 
  com=`echo $com | gawk '{ print substr($0,2) }'`
 esac
 shift
 if [ -f /etc/tbackup/$com\.arg ]; then
  source /etc/tbackup/$com\.arg
 else
  if [ -f $bupbin/$com\.arg ]; then
   source $bupbin/$com\.arg
  else
   echo Error: script $com\.arg not found in /etc/tbackup!
   echo aborting....
   cd /tmp
   rm -r /tmp/tbup
   exit 1
  fi
 fi
done


#running on virtual console? (if n, make an xterm for progress display).
if [ $progressxwindow = n ]; then
#override: log on a virtual console, even if running X.
 export virtcons=y
else
 export virtcons=n
 case "`tty`" in
  /dev/tty[0-9]* | /dev/console  )
     export virtcons=y
 esac
fi

