client="client"
 fi
 
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
+$bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
 @output tmp/dir.out
 status dir
 @output tmp/fd.out
 
 scripts/cleanup
 
 if test x@autochanger@ != x/dev/null; then
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive1@ 1`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive1@ 1`
    echo "Slot $slot in drive 1"
    if test x$slot != x0 ; then
       echo "unload slot $slot in drive 1"
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive1@ 1
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive1@ 1
    fi
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive@ 0`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive@ 0`
    echo "Slot $slot in drive 0"
    if test x$slot != x0 ; then
       echo "unload slot $slot in drive 0"
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ 0
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive@ 0
    fi
 
 
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive1@ 1`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive1@ 1`
    if test x$slot != x2; then
       echo "load slot 2 in drive 1"
-      bin/@changer_script@ @autochanger@ load 2 @tape_drive1@ 1
+      $scripts/@changer_script@ @autochanger@ load 2 @tape_drive1@ 1
    fi
    echo "WEOF drive 1"
    init_drive @tape_drive1@
 
    echo "unload slot 2 in drive 1"
-   bin/@changer_script@ @autochanger@ unload 2 @tape_drive1@ 1
+   $scripts/@changer_script@ @autochanger@ unload 2 @tape_drive1@ 1
 
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive@ 0`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive@ 0`
    echo "Slot $slot in drive 0"
    if test x$slot != x1; then
       echo "load slot 1 in drive 0"
-      bin/@changer_script@ @autochanger@ load 1 @tape_drive@ 0
+      $scripts/@changer_script@ @autochanger@ load 1 @tape_drive@ 0
    fi
    echo "WEOF drive 0"
    init_drive @tape_drive@
 
    echo "unload slot 1 from drive 0"
-   bin/@changer_script@ @autochanger@ unload 1 @tape_drive@ 0
+   $scripts/@changer_script@ @autochanger@ unload 1 @tape_drive@ 0
 fi
 
 scripts/cleanup
 
 if test x@autochanger@ != x/dev/null; then
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive@ $DRIVE1`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive@ $DRIVE1`
    case $slot in
    0)
-      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
       ;;
    $SLOT1)
       ;;
    default)
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
-      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
       ;;
   esac
 fi
 
    echo "s%  mail =%# mail = %g" >${outf}
    echo "s%  operator =%# operator =%g" >>${outf}
    cp bin/bacula-dir.conf tmp/1
-   sed -f ${outf} tmp/1 >bin/bacula-dir.conf
+   sed -f ${outf} tmp/1 > bin/bacula-dir.conf
    echo " "
    echo " "
    echo " === Starting $TestName at `date +%R:%S` ==="
-   echo " === Starting $TestName at `date +%R:%S` ===" >>working/log
+   echo " === Starting $TestName at `date +%R:%S` ===" >> working/log
    echo " "
    export zstat
 }
      ./bacula-ctl-fd start
      ./bacula-ctl-dir start
      cd ..
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf
      return $?
    else
      cd bin
      ./bacula start 2>&1 >/dev/null
      cd ..
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
      return $?
    fi
 }
 run_bconsole()
 {
    if test "$debug" -eq 1 ; then
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf
    else
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
    fi
 }
 
 run_btape()
 {
    if test "$debug" -eq 1 ; then
-     cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
+     cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
    else
-     cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
+     cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 >tmp/log1.out 2>&1
    fi
 }
 
 run_bscan()
 {
    if test "$debug" -eq 1 ; then
-      bin/bscan $* | tee tmp/log.out
+      $bin/bscan $* | tee tmp/log.out
    else
-      bin/bscan $* 2>&1 >/dev/null
+      $bin/bscan $* 2>&1 >/dev/null
    fi
 }
 
 # Source the configuration variables
 . ${cwd}/config
 
+working=${working:-"$cwd/working"}
+bin=${bin:-"$cwd/bin"}
+scripts=${scripts:-"$bin"}
+
+export bin
+export working
+export scripts
+
 db_name=${db_name:-"regress"}
 db_user=${db_user:-"regress"}
 db_password=${db_password:-""}
 
--- /dev/null
+#!/bin/sh
+
+. scripts/functions
+
+SCR=$cwd/bin/bacula-ctl
+sed "s:BACDIRBIN=$cwd/bin:BACDIRBIN=$bin:" $SCR-dir > tmp/1
+mv tmp/1 $SCR-dir
+sed "s:BACSDBIN=$cwd/bin:BACSDBIN=$bin:" $SCR-sd > tmp/1
+mv tmp/1 $SCR-sd
+sed "s:BACFDBIN=$cwd/bin:BACFDBIN=$bin:" $SCR-fd > tmp/1
+mv tmp/1 $SCR-fd
+chmod -x $cwd/bin/bacula-fd $cwd/bin/bacula-sd $cwd/bin/bacula-dir $cwd/bin/bconsole    
+chmod +x $SCR-*
+
 
 # optimize so we don't unnecessarily unload and load slots
 #
 if test x@autochanger@ != x/dev/null; then
-   slot=`bin/@changer_script@ @autochanger@ loaded 0 @tape_drive@ $DRIVE1`
+   slot=`$scripts/@changer_script@ @autochanger@ loaded 0 @tape_drive@ $DRIVE1`
    case $slot in
    0)
-      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
       init_drive @tape_drive@
       slot=$SLOT1
       ;;
       slot=$SLOT2
       ;;
    *)
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
-      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
       init_drive @tape_drive@
       slot=$SLOT1
       ;;
 # init the other slot
   case $slot in
    $SLOT1)
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
-      bin/@changer_script@ @autochanger@ load $SLOT2 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT2 @tape_drive@ $DRIVE1
       init_drive @tape_drive@
       ;;
    $SLOT2)
-      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
-      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+      $scripts/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
       init_drive @tape_drive@
       ;;
    esac
 
    echo " "
    exit 1
 fi
+# we build and setup binaries to the $cwd/bin directory not $bin
 rm -rf build bin
 # Copy new source
 echo "Copying source from ${BACULA_SOURCE}"
 cd src/win32
 make clean
 cd ../..
-make
+make -j4
 check_exit_code
 make install
 check_exit_code
 
 
 mkdir -p ${cwd}/tmp/bacula-restores
 if test "$debug" -eq 1 ; then
-  bin/bextract -v -b working/restore.bsr -c bin/bacula-sd.conf ${cwd}/tmp ${cwd}/tmp/bacula-restores                
+  $bin/bextract -v -b working/restore.bsr -c bin/bacula-sd.conf ${cwd}/tmp ${cwd}/tmp/bacula-restores                
 else
-  bin/bextract -b working/restore.bsr -c bin/bacula-sd.conf ${cwd}/tmp ${cwd}/tmp/bacula-restores 2>&1 >/dev/null
+  $bin/bextract -b working/restore.bsr -c bin/bacula-sd.conf ${cwd}/tmp ${cwd}/tmp/bacula-restores 2>&1 >/dev/null
 fi
 rstat=$?
 grep "^  Termination: *Backup OK" ${cwd}/tmp/log1.out 2>&1 >/dev/null
 
 END_OF_DATA
 
 echo "Starting Bacula tape writing"
-#bin/btape -c bin/bacula-sd.conf /dev/nst0 <<END_OF_DATA
+#$bin/btape -c bin/bacula-sd.conf /dev/nst0 <<END_OF_DATA
 #rewind
 #label
 #Test001
 
 echo "Begin attempt to read tape that crashes the system"
 echo "volume=TestVolume001" >tmp/bscan.bsr
-strace -o strace.new bin/bscan -d200 -w working -u regress -n regress -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4
+strace -o strace.new $bin/bscan -d200 -w working -u regress -n regress -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4
 exit
 cat <<END_OF_DATA >tmp/bconcmds
 @$out /dev/null
 
 fi
 
 if test "$debug" -eq 1 ; then
-  bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4                
+  $bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4                
 else
-  bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4 2>&1 >/dev/null
+  $bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf DDS-4 2>&1 >/dev/null
 fi
 
 cat <<END_OF_DATA >tmp/bconcmds
 
 fi
 
 if test "$debug" -eq 1 ; then
-  bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp                   
+  $bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp                   
 else
-  bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp 2>&1 >tmp/log3.out
+  $bin/bscan -w working -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp 2>&1 >tmp/log3.out
 fi
 
 cat <<END_OF_DATA >tmp/bconcmds
 
 change_jobname $JobName
 start_test
 
-bin/btape -c bin/bacula-sd.conf DDS-4 <<END_OF_DATA 2>&1 >${cwd}/tmp/log1.out
+$bin/btape -c bin/bacula-sd.conf DDS-4 <<END_OF_DATA >${cwd}/tmp/log1.out 2>&1
 fill
 s
 
 END_OF_DATA
 
 
-grep "^The last block on the tape matches\. Test succeeded\." ${cwd}/tmp/log1.out 2>&1 >/dev/null
+grep "^The last block on the tape matches\. Test succeeded\." ${cwd}/tmp/log1.out >/dev/null 2>&1
 if [ $? != 0 ] ; then
    echo " "
    echo " "
 
 END_OF_DATA
 
 
-bin/bacula start
-cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf > /dev/null
+run_baculabin/bacula start
 stop_bacula
 
-export dstat=0
-export bstat=0
-export rstat=0
+dstat=0
+bstat=0
+rstat=0
 
 end_test
 
 
 run_bacula
 touch ${cwd}/tmp/log1.out
-client=$(grep client= bin/bacula-dir.conf)
+client=`grep client= bin/bacula-dir.conf`
 check_for_zombie_jobs storage=File $client
 stop_bacula
 
 dstat=0
 bstat=0
 rstat=0
-export dstat
-export bstat
-export rstat
-
 
 end_test
 
 messages
 quit
 END_OF_DATA
-if test "$debug" -eq 1 ; then
-  bin/bacula start
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
-else
-  bin/bacula start 2>&1 >/dev/null
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
-fi
+
+run_bacula
 
 scripts/check_for_zombie_jobs storage=DDS-4
 echo "Backup 1 done"
 messages
 quit
 END_OF_DATA
-if test "$debug" -eq 1 ; then
-  bin/bacula start
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
-else
-  bin/bacula start 2>&1 >/dev/null
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
-fi
+
+run_bacula
 
 scripts/check_for_zombie_jobs storage=DDS-4
 echo "Backup 2 done"
 messages
 quit
 END_OF_DATA
-if test "$debug" -eq 1 ; then
-  bin/bacula start
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
-else
-  bin/bacula start 2>&1 >/dev/null
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
-fi
+run_bacula
 
 scripts/check_for_zombie_jobs storage=DDS-4
 echo "Backup 3 done"
 messages
 quit
 END_OF_DATA
-if test "$debug" -eq 1 ; then
-  bin/bacula start
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
-else
-  bin/bacula start 2>&1 >/dev/null
-  cat ${cwd}/tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
-fi
+run_bacula
 
 scripts/check_for_zombie_jobs storage=DDS-4
 echo "Backup 4 done"
 
 . scripts/functions
 
 
-stop_bacula
-cd bin
-./drop_bacula_tables >/dev/null 2>&1
-./make_bacula_tables >/dev/null 2>&1
-./grant_bacula_privileges 2>&1 >/dev/null
-cd ..
-
+scripts/cleanup
 scripts/copy-2disk-confs
 scripts/prepare-two-disks
 
 
 #
 cwd=`pwd`
 . scripts/functions
-bin/bacula stop 2>&1 >/dev/null
-cd bin
-./drop_bacula_tables >/dev/null 2>&1
-./make_bacula_tables >/dev/null 2>&1
-./grant_bacula_privileges 2>&1 >/dev/null
-cd ..
-
+scripts/cleanup
 scripts/cleanup-tape
 scripts/copy-tape-confs
 echo "/lib" >${cwd}/tmp/file-list
 echo " === Starting lib-tape-root test ==="
 echo " "
 echo " "
-bin/bacula start 2>&1 >/dev/null
+
 bin/bconsole -c bin/bconsole.conf <<END_OF_DATA
 @output /dev/null
 messages
 @output
 quit
 END_OF_DATA
-bin/bacula stop 2>&1 >/dev/null
+run_bacula
+stop_bacula
 cd /
 ${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original
 cd ${cwd}/tmp/bacula-restores
 
 check_two_logs
 
 scripts/check_for_zombie_jobs storage=DDS-4
-bin/bacula stop 2>&1 >/dev/null
+stop_bacula
 for i in `cat ${cwd}/tmp/restore2-list`; do
    diff $i ${cwd}/tmp/bacula-restores$i
    if [ $? != 0 ] ; then
 
 echo " "
 echo " "
 
-bin/bacula start 2>&1 >/dev/null
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA
+cat <<END_OF_DATA > ${cwd}/tmp/bconcmds
 @output /dev/null
 messages
 @output tmp/log1.out
 @output
 quit
 END_OF_DATA
-bin/bacula stop 2>&1 >/dev/null
+run_bacula
+stop_bacula
+
 cd /
 ${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original
 cd ${cwd}/tmp/bacula-restores