1 --- amanda-2.6.0/changer-src/chg-zd-mtx.sh.orig 2008-01-18 01:31:16.000000000 +0100
2 +++ amanda-2.6.0/changer-src/chg-zd-mtx.sh 2008-05-07 13:00:14.000000000 +0200
7 - if [ $internal_call -gt 0 ]; then
8 + if [ "$internal_call" -gt 0 ]; then
14 Log $call_type "($code) -> $exit_slot $@"
15 echo "$exit_slot" "$@"
16 - if [ $call_type = Return ]; then
17 + if [ "$call_type" = "Return" ]; then
20 amgetconf dbclose.$argv0:$DBGFILE > /dev/null 2>&1
22 "$@" > $stdout 2> $stderr
24 Log `_ 'Exit code: %s' "$exitcode"`
29 cat $stdout >> $DBGFILE
35 cat $stderr >> $DBGFILE
39 test -n "$DEBUG" && set -x
40 - if [ $mtx_status_valid -ne 0 ]; then
41 + if [ "$mtx_status_valid" -ne 0 ]; then
45 Run $MTX status > $mtx_status 2>&1
47 - if [ $status -eq 0 ]; then
48 + if [ "$status" -eq 0 ]; then
55 #Use the current slot if it's empty and we don't know which slot is loaded'
56 - if [ $loadedslot -eq -2 ]; then
57 + if [ "$loadedslot" -eq -2 ]; then
60 /^.*Storage Element '$currentslot':Empty/ {
62 ' < $mtx_status 2>& 1`
63 shift # get rid of the "x"
65 - if [ ! -z $loadedslotx ]; then
66 + if [ ! -z "$loadedslotx" ]; then
67 loadedslot=$loadedslotx
71 #Use the first empty slot if we don't know which slot is loaded'
72 - if [ $loadedslot -eq -2 ]; then
73 + if [ "$loadedslot" -eq -2 ]; then
76 /^.*Storage Element \([0-9][0-9]*\):Empty/ {
79 ' < $mtx_status 2>&1 | grep -v "^${cleanslot}\$" | sort -n`
80 slot_list=`echo $slot_list` # remove the newlines
81 - if [ $firstslot -lt 0 -o $lastslot -lt 0 ]; then
82 + if [ "$firstslot" -lt 0 -o "$lastslot" -lt 0 ]; then
84 for slot in $slot_list; do
85 - if [ $firstslot -lt 0 ]; then
86 + if [ "$firstslot" -lt 0 ]; then
87 Log `_ 'SLOTLIST -> firstslot set to %s' "$slot"`
90 - if [ $lastslot -lt 0 ]; then
91 + if [ "$lastslot" -lt 0 ]; then
95 - if [ $lastslot -lt 0 -a $last -ge 0 ]; then
96 + if [ "$lastslot" -lt 0 -a "$last" -ge 0 ]; then
97 Log `_ 'SLOTLIST -> lastslot set to %s' "$last"`
100 - if [ $firstslot -lt 0 ]; then
101 + if [ "$firstslot" -lt 0 ]; then
104 `_ 'cannot determine first slot'`
105 return $? # in case we are internal
106 - elif [ $lastslot -lt 0 ]; then
107 + elif [ "$lastslot" -lt 0 ]; then
110 `_ 'cannot determine last slot'`
114 for slot in $slot_list; do
115 - if [ $slot -ge $firstslot -a $slot -le $lastslot ]; then
116 + if [ "$slot" -ge "$firstslot" -a "$slot" -le "$lastslot" ]; then
117 amanda_slot_list="$amanda_slot_list $slot"
123 "tapedev $rawtape is not a tape device."
124 -elif [ $tape = "/dev/null" -o `expr "$tape" : 'null:'` -eq 5 ]; then
125 +elif [ "$tape" = "/dev/null" -o "`expr "$tape" : 'null:'`" -eq 5 ]; then
128 "tapedev ($tape) may not be the null device"
132 "changerdev may not be empty"
133 -elif [ $TAPE = "/dev/null" ]; then
134 +elif [ "$TAPE" = "/dev/null" ]; then
137 "changerdev ($TAPE) may not be the null device"
138 @@ -676,19 +676,19 @@
139 #### Set up the various config files.
141 conf_match=`expr "$changerfile" : .\*\.conf\$`
142 -if [ $conf_match -ge 6 ]; then
143 +if [ "$conf_match" -ge 6 ]; then
144 configfile=$changerfile
145 changerfile=`echo $changerfile | sed 's/.conf$//g'`
147 configfile=$changerfile.conf
150 -if [ ! -e $configfile ]; then
151 +if [ ! -e "$configfile" ]; then
154 "configuration file \"$configfile\" doesn't exist"
156 -if [ ! -f $configfile ]; then
157 +if [ ! -f "$configfile" ]; then
160 "configuration file \"$configfile\" is not a file"
161 @@ -698,10 +698,10 @@
162 accessfile=$changerfile-access
163 slotfile=$changerfile-slot
164 labelfile=$changerfile-barcodes
165 -[ ! -s $cleanfile ] && echo 0 > $cleanfile
166 -[ ! -s $accessfile ] && echo 0 > $accessfile
167 -[ ! -s $slotfile ] && echo -1 > $slotfile
168 -[ ! -f $labelfile ] && > $labelfile
169 +[ ! -s "$cleanfile" ] && echo 0 > $cleanfile
170 +[ ! -s "$accessfile" ] && echo 0 > $accessfile
171 +[ ! -s "$slotfile" ] && echo -1 > $slotfile
172 +[ ! -f "$labelfile" ] && > $labelfile
173 cleancount=`cat $cleanfile`
174 accesscount=`cat $accessfile`
178 # Get DBGFILE set if it is not already.
180 -if [ $DBGFILE = /dev/null ]; then
181 +if [ "$DBGFILE" = /dev/null ]; then
182 if [ -d "$DBGDIR" ]; then
183 DBGFILE=$DBGDIR/changer.debug.drive$driveslot
187 Log `_ "Config info:"`
188 for var in $varlist; do
189 - if [ $var = "OFFLINE_BEFORE_UNLOAD" ]; then
190 + if [ "$var" = "OFFLINE_BEFORE_UNLOAD" ]; then
192 - elif [ $var = "AUTOCLEAN" ]; then
193 + elif [ "$var" = "AUTOCLEAN" ]; then
197 @@ -850,12 +850,12 @@
199 # Run the rest of the config file sanity checks.
201 -if [ $firstslot -gt $lastslot ]; then
202 +if [ "$firstslot" -gt "$lastslot" ]; then
205 `_ 'firstslot (%s) greater than lastslot (%s) in %s' "$firstslot" "$lastslot" "$configfile"`
207 -if [ $autoclean -ne 0 -a $cleanslot -lt 0 ]; then
208 +if [ "$autoclean" -ne 0 -a "$cleanslot" -lt 0 ]; then
211 `_ 'autoclean set but cleanslot not valid (%s)' "$cleanslot"`
212 @@ -865,10 +865,10 @@
214 currentslot=`cat $slotfile`
215 if IsNumeric "$currentslot" ; then
216 - if [ $currentslot -lt $firstslot ]; then
217 + if [ "$currentslot" -lt "$firstslot" ]; then
218 Log `_ 'SETUP -> current slot %s less than %s ... resetting to %s' "$currentslot" "$firstslot" "$firstslot"`
219 currentslot=$firstslot
220 - elif [ $currentslot -gt $lastslot ]; then
221 + elif [ "$currentslot" -gt "$lastslot" ]; then
222 Log `_ 'SETUP -> current slot %s greater than %s ... resetting to %s' "$currentslot" "$lastslot" "$lastslot"`
223 currentslot=$lastslot
225 @@ -881,19 +881,19 @@
226 first_slot_in_list=-1
227 next_slot_after_current=-1
228 for slot in $slot_list; do
229 - if [ $first_slot_in_list -lt 0 ]; then
230 + if [ "$first_slot_in_list" -lt 0 ]; then
231 first_slot_in_list=$slot # in case $firstslot is missing
233 - if [ $slot -eq $currentslot ]; then
234 + if [ "$slot" -eq "$currentslot" ]; then
237 - elif [ $slot -gt $currentslot ]; then
238 + elif [ "$slot" -gt "$currentslot" ]; then
239 next_slot_after_current=$slot # $currentslot is missing
243 -if [ $found_current -eq 0 ]; then
244 - if [ $next_slot_after_current -lt 0 ]; then
245 +if [ "$found_current" -eq 0 ]; then
246 + if [ "$next_slot_after_current" -lt 0 ]; then
247 new_currentslot=$first_slot_in_list
249 new_currentslot=$next_slot_after_current
251 test -n "$DEBUG" && set -x
252 Log `_ 'EJECT -> ejecting tape from %s' "$tape"`
254 - if [ $loadedslot -gt 0 ]; then
255 + if [ "$loadedslot" -gt 0 ]; then
256 Log `_ 'EJECT -> moving tape from drive %s to storage slot %s' "$driveslot" "$loadedslot"`
257 - if [ $offline_before_unload -ne 0 ]; then
258 + if [ "$offline_before_unload" -ne 0 ]; then
259 Run try_eject_device $tape
264 Log `_ ' -> status %s, result "%s"' "$status" "$result"`
266 - if [ $status -ne 0 ]; then
267 + if [ "$status" -ne 0 ]; then
271 @@ -1001,7 +1001,7 @@
274 while [ $# -gt 0 ]; do
275 - if [ $1 -eq $find_slot ]; then
276 + if [ "$1" -eq "$find_slot" ]; then
280 @@ -1030,15 +1030,15 @@
281 # If the desired slot is already loaded, we are done. Only update
282 # current slot if this is not the cleaning slot.
284 - if [ $loadslot = $loadedslot ]; then
285 - if [ $loadslot -ne $cleanslot ]; then
286 + if [ "$loadslot" = "$loadedslot" ]; then
287 + if [ "$loadslot" -ne "$cleanslot" ]; then
289 echo $loadslot > $slotfile
291 Exit 0 "$loadedslot" "$rawtape"
292 return $? # in case we are internal
294 - if [ $loadedslot -eq -2 ]; then
295 + if [ "$loadedslot" -eq -2 ]; then
296 Exit 0 "$loadedslot" "$rawtape"
297 return $? # in case we are internal
299 @@ -1046,20 +1046,20 @@
300 # If we are loading the cleaning tape, bump the cleaning count
301 # and reset the access count. Otherwise, bump the access count
302 # and see if it is time to do a cleaning.
303 - if [ $loadslot = $cleanslot ]; then
304 + if [ "$loadslot" = "$cleanslot" ]; then
305 rm -f $cleanfile $accessfile
306 expr $cleancount + 1 > $cleanfile
310 expr $accesscount + 1 > $accessfile
311 - if [ $autoclean -ne 0 -a $accesscount -gt $autocleancount ]
312 + if [ "$autoclean" -ne 0 -a "$accesscount" -gt "$autocleancount" ]
314 internal_call=`expr $internal_call + 1`
315 loadslot clean > /dev/null 2>&1
317 internal_call=`expr $internal_call - 1`
318 - if [ $status -ne 0 ]; then
319 + if [ "$status" -ne 0 ]; then
320 Exit $status "$loadslot" "$exit_answer"
321 return $? # in case we are internal
323 @@ -1079,14 +1079,14 @@
324 eject > /dev/null 2>&1
326 internal_call=`expr $internal_call - 1`
327 - if [ $status -gt 1 ]; then
328 + if [ "$status" -gt 1 ]; then
329 Exit $status "$exit_slot" "$exit_answer"
330 return $? # in case we are internal
333 # If we were doing an "advance", we are done.
334 - if [ $whichslot = advance ]; then
335 - if [ $loadslot -ne $cleanslot ]; then
336 + if [ "$whichslot" = "advance" ]; then
337 + if [ "$loadslot" -ne "$cleanslot" ]; then
339 echo $loadslot > $slotfile
341 @@ -1100,7 +1100,7 @@
343 Log `_ ' -> status %s, result "%s"' "$status" "$result"`
345 - if [ $status -ne 0 ]; then
346 + if [ "$status" -ne 0 ]; then
347 Exit 2 "$loadslot" "$result"
348 return $? # in case we are internal
350 @@ -1110,7 +1110,7 @@
351 # for "long enough" (as determined empirically by the user),
352 # then return success.
354 - if [ $loadslot -eq $cleanslot ]; then
355 + if [ "$loadslot" -eq "$cleanslot" ]; then
356 Run sleep $cleancycle
357 Exit 0 "$loadslot" "$rawtape"
358 return $? # in case we are internal
359 @@ -1122,7 +1122,7 @@
362 sleep $initial_poll_delay
363 - while [ $waittime -lt $max_drive_wait ]; do
364 + while [ "$waittime" -lt "$max_drive_wait" ]; do
365 amdevcheck_status $tape
366 if [ $? -eq 0 ]; then
368 @@ -1131,12 +1131,12 @@
369 sleep $poll_drive_ready
370 waittime=`expr $waittime + $poll_drive_ready`
372 - if [ $ready -eq 0 ]; then
373 + if [ "$ready" -eq 0 ]; then
374 Exit 2 "$loadslot" `_ 'Drive not ready after %s seconds, rewind said "%s"' "$max_drive_wait" "$result"`
375 return $? # in case we are internal
378 - if [ $loadslot -ne $cleanslot ]; then
379 + if [ "$loadslot" -ne "$cleanslot" ]; then
381 echo $loadslot > $slotfile
383 @@ -1167,11 +1167,11 @@
384 # can search based on barcodes.
387 - if [ $havereader -eq 1 ]; then
388 + if [ "$havereader" -eq 1 ]; then
392 - if [ $currentslot -lt $firstslot -o $currentslot -gt $lastslot ]; then
393 + if [ "$currentslot" -lt "$firstslot" -o "$currentslot" -gt "$lastslot" ]; then
394 currentslot=$firstslot # what "current" will get
396 numslots=`expr $lastslot - $firstslot + 1`
397 @@ -1202,7 +1202,7 @@
398 `_ 'Line %s malformed in %s: %s %s %s' "$line" "$labelfile" "$lbl" "$bc" "$junk"`
399 return $? # in case we are internal
401 - if [ $lbl = "$lbl_search" -o $bc = "$bc_search" ]; then
402 + if [ "$lbl" = "$lbl_search" -o "$bc" = "$bc_search" ]; then
403 if [ $labelfile_entry_found -ne 0 ]; then
404 Log `_ 'ERROR -> Duplicate entries: %s line %s' "$labelfile" "$line"`
405 LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`
406 @@ -1230,12 +1230,12 @@
407 return $? # in case we are internal
410 - if [ $havereader -eq 0 ]; then
411 + if [ "$havereader" -eq 0 ]; then
412 Exit 2 `_ '<none>'` `_ 'Not configured with barcode reader'`
413 return $? # in case we are internal
416 - if [ $loadedslot -lt 0 ]; then
417 + if [ "$loadedslot" -lt 0 ]; then
418 Exit 1 `_ '<none>'` `_ 'No tape currently loaded'`
419 return $? # in case we are internal
421 @@ -1245,7 +1245,7 @@
423 Log `_ 'LABEL -> Adding label "%s" with barcode "%s" for slot %s into %s' "$tapelabel" "$loadedbarcode" "$loadedslot" "$labelfile"`
424 read_labelfile "$tapelabel" "$loadedbarcode" < $labelfile
425 - if [ $labelfile_entry_found -ne 0 ]; then
426 + if [ "$labelfile_entry_found" -ne 0 ]; then
428 if [ "$labelfile_barcode" != "$loadedbarcode" ]; then
430 @@ -1289,13 +1289,13 @@
431 return $? # in case we are internal
434 - if [ $havereader -eq 0 ]; then
435 + if [ "$havereader" -eq 0 ]; then
436 Exit 2 `_ '<none>'` `_ 'Not configured with barcode reader'`
437 return $? # in case we are internal
439 Log `_ 'SEARCH -> Hunting for label "%s"' "$tapelabel"`
440 read_labelfile "$tapelabel" "" < $labelfile
441 - if [ $labelfile_entry_found -eq 0 ]; then
442 + if [ "$labelfile_entry_found" -eq 0 ]; then
443 LogAppend `_ ' -> !!! label "%s" not found in %s !!!' "$tapelabel" "$labelfile"`
444 LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`