Imported Upstream version 2.5.1
[debian/amanda] / changer-src / chg-zd-mtx.sh.in
index 6cf5b18bbdbc87eb6ae4afb4a2ecae7d9667997c..db25d10ae4a0b6196bd23c8fc08176595ae708a8 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh 
+#!@SHELL@ 
 #
 # Exit Status:
 # 0 Alles Ok
 # in amanda.conf.  For example, if amanda.conf has:
 #
 #      changerfile="/etc/amanda/Dailyset1/CHANGER"
+#    or changerfile="/etc/amanda/Dailyset1/CHANGER.conf"
 #
 # the variables must be in "/etc/amanda/Dailyset1/CHANGER.conf".
+# The ".conf" is appended only if it's not there".
 #
 # If "changerfile" is a relative path, it is relative to the directory
 # that contains amanda.conf.  That also happens to be the directory Amanda
@@ -447,39 +449,82 @@ get_loaded_info() {
        get_mtx_status
 
        set x `sed -n '
-/^Data Transfer Element:Empty/                         {
+/^Data Transfer Element:Empty/                          {
     s/.*/-1/p
     q
 }
-/^Data Transfer Element '$driveslot':Empty/            {
+/^Data Transfer Element '$driveslot':Empty/             {
     s/.*/-1/p
     q
 }
-/^Data Transfer Element:Full.*:VolumeTag/              {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^    ]*\)/\1 \2/p
+/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^     ]*\)/               {
+    s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^     ]*\)/\1 \2/p
     q
 }
-/^Data Transfer Element '$driveslot':Full.*:VolumeTag/ {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^    ]*\)/\1 \2/p
+/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^     ]*\)/  {
+    s/.*(Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^     ]*\)/\1 \2/p
     q
 }
-/^Data Transfer Element:Full/                          {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded)\(.*\)/\1/p
+/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded):VolumeTag *= *\([^     ]*\)/        {
+    s/.*:VolumeTag *= *\([^     ]*\)/-2 \1/p
     q
 }
-/^Data Transfer Element '$driveslot':Full/             {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded)\(.*\)/\1/p
+/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded)/                           {
+    s/.*(Storage Element \([0-9][0-9]*\) Loaded).*/\1/p
+    q
+}
+/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded)/              {
+    s/.*Storage Element \([0-9][0-9]*\) Loaded.*/\1/p
+    q
+}
+/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded)/    {
+    s/.*/-2/p
     q
 }
 ' < $mtx_status 2>&1`
        shift                                   # get rid of the "x"
        loadedslot=$1
        loadedbarcode=$2
-
        if [ -z "$loadedslot" ]; then
                Exit 2 "<none>" "could not determine current slot, are you sure your drive slot is $driveslot"
                return $?                       # in case we are internal
        fi
+
+       #Use the current slot if it's empty and we don't know which slot is loaded'
+       if [ $loadedslot -eq -2 ]; then
+               set x `sed -n '
+{
+    /^.*Storage Element '$currentslot':Empty/ {
+       s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p
+        q
+    }
+    /^.*Storage Element '$currentslot':Full/ {
+       s/.*Storage Element \([0-9][0-9]*\):Full/-2/p
+        q
+    }
+}
+' < $mtx_status 2>& 1`
+               shift                           # get rid of the "x"
+               loadedslotx=$1
+               if [ ! -z $loadedslotx ]; then
+                       loadedslot=$loadedslotx
+               fi
+       fi
+
+       #Use the first empty slot if we don't know which slot is loaded'
+       if [ $loadedslot -eq -2 ]; then
+               set x `sed -n '
+{
+    /^.*Storage Element \([0-9][0-9]*\):Empty/ {
+       s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p
+        q
+    }
+}
+' < $mtx_status 2>& 1`
+               shift                           # get rid of the "x"
+               loadedslot=$1
+       fi
+
        if IsNumeric "$loadedslot" ; then
                :
        else
@@ -506,14 +551,25 @@ get_slot_list() {
        fi
        get_mtx_status
        slot_list=`sed -n '
-/^Data Transfer Element:Full/                          {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded)\(.*\)/\1/p
+/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded)/ {
+    s/.*(Storage Element \([0-9][0-9]*\) Loaded).*/\1/p
+}
+/^Data Transfer Element '$driveslot':Full (Storage Element \([0-9][0-9]*\) Loaded)/ {
+    s/.*Storage Element \([0-9][0-9]*\) Loaded.*/\1/p
 }
-/^Data Transfer Element '$driveslot':Full/             {
-    s/.*(Storage Element \([0-9][0-9]*\) Loaded)\(.*\)/\1/p
+/^Data Transfer Element '$driveslot':Full (Unknown Storage Element Loaded)/ {
+    : loop
+    n
+    /^.*Storage Element \([0-9][0-9]*\):Full/ {
+        s/.*Storage Element \([0-9][0-9]*\):Full.*/\1/p
+        b loop
+    }
+    /^.*Storage Element \([0-9][0-9]*\):Empty/ {
+       s/.*Storage Element \([0-9][0-9]*\):Empty/\1/p
+    }
 }
-/^[    ]*Storage Element \([0-9][0-9]*\):Full/         {
-    s/.*Storage Element \([0-9][0-9]*\):.*/\1/p
+/^.*Storage Element \([0-9][0-9]*\):Full/ {
+    s/.*Storage Element \([0-9][0-9]*\):Full.*/\1/p
 }
 ' < $mtx_status 2>&1 | grep -v "^${cleanslot}\$" | sort -n`
        slot_list=`echo $slot_list`             # remove the newlines
@@ -576,20 +632,20 @@ else
        SUF=
 fi
 
-DBGFILE=`amgetconf$SUF dbopen.$argv0 2>/dev/null | grep -v BUGGY`
+DBGFILE=`amgetconf$SUF dbopen.$argv0 2>/dev/null`
 if [ -z "$DBGFILE" ]
 then
        DBGFILE=/dev/null                       # will try this again below
 fi
 
-changerfile=`amgetconf$SUF changerfile 2>/dev/null | grep -v BUGGY`
+changerfile=`amgetconf$SUF changerfile 2>/dev/null`
 if [ -z "$changerfile" ]; then
        Exit 2 \
             "<none>" \
             "changerfile must be specified in amanda.conf"
 fi
 
-tape=`amgetconf$SUF tapedev 2>/dev/null | grep -v BUGGY`
+tape=`amgetconf$SUF tapedev 2>/dev/null`
 if [ -z "$tape" ]; then
        Exit 2 \
             "<none>" \
@@ -599,7 +655,7 @@ elif [ $tape = "/dev/null" -o `expr "$tape" : 'null:'` -eq 5 ]; then
             "<none>" \
             "tapedev ($tape) may not be the null device"
 fi
-TAPE=`amgetconf$SUF changerdev 2>/dev/null | grep -v BUGGY`
+TAPE=`amgetconf$SUF changerdev 2>/dev/null`
 if [ -z "$TAPE" ]; then
        Exit 2 \
             "<none>" \
@@ -613,7 +669,14 @@ export TAPE                                        # for mtx command
 
 #### Set up the various config files.
 
-configfile=$changerfile.conf
+conf_match=`expr "$changerfile" : .\*\.conf\$`
+if [ $conf_match -ge 6 ]; then
+       configfile=$changerfile
+       changerfile=`echo $changerfile | sed 's/.conf$//g'`
+else
+       configfile=$changerfile.conf
+fi
+
 cleanfile=$changerfile-clean
 accessfile=$changerfile-access
 slotfile=$changerfile-slot
@@ -946,6 +1009,10 @@ loadslot() {
                Exit 0 "$loadedslot" "$tape"
                return $?                       # in case we are internal
        fi
+       if [ $loadedslot -eq -2 ]; then
+               Exit 0 "$loadedslot" "$tape"
+               return $?                       # in case we are internal
+        fi
 
        # If we are loading the cleaning tape, bump the cleaning count
        # and reset the access count.  Otherwise, bump the access count
@@ -1081,9 +1148,7 @@ info() {
        if [ $currentslot -lt $firstslot -o $currentslot -gt $lastslot ]; then
                currentslot=$firstslot          # what "current" will get
        fi
-       set x $slot_list
-       shift                                   # get rid of the "x"
-       numslots=$#
+       numslots=`expr $lastslot - $firstslot + 1`
        Exit 0 "$currentslot" "$numslots 1 $reader"
        return $?                               # in case we are internal
 }