]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/scripts/disk-changer.in
Add comments and cleanup
[bacula/bacula] / bacula / scripts / disk-changer.in
index f9c800cc0ebb7709b4e41462b571f1abc2407500..1d5dc74154fc9c748c78eda5e0002d656bfb5806 100644 (file)
@@ -136,8 +136,8 @@ get_dir() {
    bn=`basename $device`
    dir=`echo "$device" | sed -e s%/$bn%%g`
    if [ ! -d $dir ]; then
-      echo "ERROR: Autochanger directory \"$dir\" does not exist.\n"
-      echo "      You must create it.\n"
+      echo "ERROR: Autochanger directory \"$dir\" does not exist."
+      echo "      You must create it."
       exit 1
    fi
 }
@@ -171,12 +171,12 @@ case $2 in
        check_parm_count $# 2
        ;;
     transfer)
-        check_parm_count $# 4
+       check_parm_count $# 4
        if [ $slot -gt $maxslot ]; then
           echo "Slot ($slot) out of range (1-$maxslot)"
           exit 1
        fi
-        ;;
+       ;;
     *)
        check_parm_count $# 5
        if [ $drive -gt $maxdrive ]; then
@@ -275,35 +275,37 @@ case $cmd in
       debug "Doing disk -f $ctl -- to list volumes"
       get_dir 
       if [ ! -f $dir/barcodes ]; then
-          exit 0
+         exit 0
       fi
 
       # we print drive content seen by autochanger
       # and we also remove loaded media from the barcode list
-      for i in $dir/loaded*
-      do
-          d=${i##$dir/loaded}
-          s=$(cat $i)
-          v=$(awk -F: "/^$s:/"' { print $2 }' $dir/barcodes)
-          echo "D:$d:F:$s:$v"
-          echo "^$s:" >> $TMPFILE
+      i=0
+      while [ $i -le $maxdrive ]; do
+        if [ -f $dir/loaded${i} ]; then
+            ld=`cat $dir/loaded${i}`
+            v=`awk -F: "/^$ld:/"' { print $2 }' $dir/barcodes`
+            echo "D:$i:F:$ld:$v"
+            echo "^$ld:" >> $TMPFILE
+        fi
+        i=`expr $i + 1`
       done
 
       # Empty slots are not in barcodes file
       # When we detect a gap, we print missing rows as empty
       # At the end, we fill the gap between the last entry and maxslot
-      grep -v -f $TMPFILE $dir/barcodes | \
+      grep -v -f $TMPFILE $dir/barcodes | sort -n | \
       perl -ne 'BEGIN { $cur=1 } 
        if (/(\d+):(.+)?/) {
-         if ($cur == $1) { 
-           print "S:$1:F:$2\n" 
-         } else { 
-           while ($cur < $1) {
-              print "S:$cur:E\n";
-              $cur++;
-           }
-         }
-         $cur++;
+        if ($cur == $1) { 
+          print "S:$1:F:$2\n" 
+        } else { 
+          while ($cur < $1) {
+             print "S:$cur:E\n";
+             $cur++;
+          }
+        }
+        $cur++;
        } 
        END { while ($cur < '"$maxslot"') { print "S:$cur:E\n"; $cur++; } } '
 
@@ -327,8 +329,8 @@ case $cmd in
       mv $dir/slot${slot} $dir/slot{$slotdest}
 
       if [ -f $dir/barcodes ]; then
-         sed "s/^$slot:/$slotdest:/" >  $TMPFILE
-         sort -n $TMPFILE > $dir/barcodes
+        sed "s/^$slot:/$slotdest:/" >  $TMPFILE
+        sort -n $TMPFILE > $dir/barcodes
       fi
       exit 0
       ;;