]> git.sur5r.net Git - bacula/bacula/blobdiff - regress/scripts/prepare-two-tapes.in
Tweak
[bacula/bacula] / regress / scripts / prepare-two-tapes.in
index 37b3e9d990d20516e0f2aaef75bccf65da2c2806..1093895ab7e08ba5b77187f71de793765c160d64 100755 (executable)
@@ -1,56 +1,56 @@
 #!/bin/sh
 #
-# Create two blank tapes
+# Cleanup left over files -- both before and after test run
 #
+# Write an EOF on tape in slot $SLOT1  and  on tape in $SLOT2
 
-# mt status output
-# SunOS     No Additional Sense
-# FreeBSD   Current Driver State: at rest.
-# Linux     ONLINE
-#  Note Debian has messed up their mt. When no tape is in the
-#    drive it waits 2 minutes. When a tape is in the drive, it
-#    prints user unfriendly output.
-#
+. scripts/functions
+
+scripts/cleanup
 
-OS=`uname`
-case ${OS} in
-  SunOS)
-    ready="No Additional Sense"
-    ;;
-  FreeBSD)
-    ready="Current Driver State: at rest."
-    ;;
-  Linux)
-    if test -e /etc/debian_version ; then
-       ready="drive status"
-    else
-       ready="ONLINE"
-    fi
-  ;;
-esac
 
-wait_for_drive() {
-  i=0 
-  while [ $i -le 300 ]; do  # Wait max 300 seconds
-    if mt -f $1 status 2>&1 | grep "${ready}" >/dev/null 2>&1; then
-      break
-    fi
-#   debug "Device $1 - not ready, retrying..."
-    sleep 1
-    i=`expr $i + 1`
-  done
-}
+# with disk-changer, we have to initialize slots
+init_slot @tape_drive@ $SLOT1
+init_slot @tape_drive@ $SLOT2
 
 #
-# mt -f @tape_drive@ offline
-@changer_path@ -f @autochanger@ unload
-@changer_path@ -f @autochanger@ load 1
-wait_for_drive @tape_drive@
-mt -f @tape_drive@ rewind
-mt -f @tape_drive@ weof
-@changer_path@ -f @autochanger@ unload
-@changer_path@ -f @autochanger@ load 2
-wait_for_drive @tape_drive@
-mt -f @tape_drive@ rewind
-mt -f @tape_drive@ weof
-#@changer_path@ -f @autochanger@ unload
+# init first of two slots
+# 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`
+   case $slot in
+   0)
+      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      slot=$SLOT1
+      ;;
+   $SLOT1)
+      slot=$SLOT1
+      ;;
+   $SLOT2)
+      slot=$SLOT2
+      ;;
+   *)
+      bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      slot=$SLOT1
+      ;;
+  esac
+  init_drive @tape_drive@
+  bin/@changer_script@ @autochanger@ unload $slot @tape_drive@ $DRIVE1
+
+
+# init the other slot
+  case $slot in
+   $SLOT1)
+      bin/@changer_script@ @autochanger@ load $SLOT2 @tape_drive@ $DRIVE1
+      ;;
+   $SLOT2)
+      bin/@changer_script@ @autochanger@ load $SLOT1 @tape_drive@ $DRIVE1
+      ;;
+   *)
+      echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $slot"
+      exit 1
+   esac
+   init_drive @tape_drive@
+fi