1 diff -ur amanda-2.6.1p1/changer-src/chg-zd-mtx.sh amanda-2.6.1p1-sh/changer-src/chg-zd-mtx.sh
2 --- amanda-2.6.1p1/changer-src/chg-zd-mtx.sh 2008-12-16 21:46:41.000000000 +0100
3 +++ amanda-2.6.1p1-sh/changer-src/chg-zd-mtx.sh 2009-07-03 21:00:25.379617588 +0200
8 - if [ $internal_call -gt 0 ]; then
9 + if [ "$internal_call" -gt 0 ]; then
15 Log $call_type "($code) -> $exit_slot $@"
16 echo "$exit_slot" "$@"
17 - if [ $call_type = Return ]; then
18 + if [ "$call_type" = "Return" ]; then
21 amgetconf dbclose.$myname:$DBGFILE > /dev/null 2>&1
23 "$@" > $stdout 2> $stderr
25 Log `_ 'Exit code: %s' "$exitcode"`
30 cat $stdout >> $DBGFILE
36 cat $stderr >> $DBGFILE
40 test -n "$DEBUG" && set -x
41 - if [ $mtx_status_valid -ne 0 ]; then
42 + if [ "$mtx_status_valid" -ne 0 ]; then
46 Run $MTX status > $mtx_status 2>&1
48 - if [ $status -eq 0 ]; then
49 + if [ "$status" -eq 0 ]; then
56 #Use the current slot if it's empty and we don't know which slot is loaded'
57 - if [ $loadedslot -eq -2 ]; then
58 + if [ "$loadedslot" -eq -2 ]; then
61 /^.*Storage Element '$currentslot':Empty/ {
63 ' < $mtx_status 2>& 1`
64 shift # get rid of the "x"
66 - if [ ! -z $loadedslotx ]; then
67 + if [ ! -z "$loadedslotx" ]; then
68 loadedslot=$loadedslotx
72 #Use the first empty slot if we don't know which slot is loaded'
73 - if [ $loadedslot -eq -2 ]; then
74 + if [ "$loadedslot" -eq -2 ]; then
77 /^.*Storage Element \([0-9][0-9]*\):Empty/ {
80 ' < $mtx_status 2>&1 | grep -v "^${cleanslot}\$" | sort -n`
81 slot_list=`echo $slot_list` # remove the newlines
82 - if [ $firstslot -lt 0 -o $lastslot -lt 0 ]; then
83 + if [ "$firstslot" -lt 0 -o "$lastslot" -lt 0 ]; then
85 for slot in $slot_list; do
86 - if [ $firstslot -lt 0 ]; then
87 + if [ "$firstslot" -lt 0 ]; then
88 Log `_ 'SLOTLIST -> firstslot set to %s' "$slot"`
91 - if [ $lastslot -lt 0 ]; then
92 + if [ "$lastslot" -lt 0 ]; then
96 - if [ $lastslot -lt 0 -a $last -ge 0 ]; then
97 + if [ "$lastslot" -lt 0 -a "$last" -ge 0 ]; then
98 Log `_ 'SLOTLIST -> lastslot set to %s' "$last"`
101 - if [ $firstslot -lt 0 ]; then
102 + if [ "$firstslot" -lt 0 ]; then
105 `_ 'cannot determine first slot'`
106 return $? # in case we are internal
107 - elif [ $lastslot -lt 0 ]; then
108 + elif [ "$lastslot" -lt 0 ]; then
111 `_ 'cannot determine last slot'`
115 for slot in $slot_list; do
116 - if [ $slot -ge $firstslot -a $slot -le $lastslot ]; then
117 + if [ "$slot" -ge "$firstslot" -a "$slot" -le "$lastslot" ]; then
118 amanda_slot_list="$amanda_slot_list $slot"
122 `_ 'Line %s malformed in %s: %s %s %s' "$line" "$labelfile" "$lbl" "$bc" "$junk"`
123 return $? # in case we are internal
125 - if [ $lbl = "$lbl_search" -o $bc = "$bc_search" ]; then
126 + if [ "$lbl" = "$lbl_search" -o "$bc" = "$bc_search" ]; then
127 if [ $labelfile_entry_found -ne 0 ]; then
128 Log `_ 'ERROR -> Duplicate entries: %s line %s' "$labelfile" "$line"`
129 LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`
133 "tapedev $rawtape is not a tape device."
134 -elif [ $tape = "/dev/null" -o `expr "$tape" : 'null:'` -eq 5 ]; then
135 +elif [ "$tape" = "/dev/null" -o "`expr "$tape" : 'null:'`" -eq 5 ]; then
138 "tapedev ($tape) may not be the null device"
142 "changerdev may not be empty"
143 -elif [ $TAPE = "/dev/null" ]; then
144 +elif [ "$TAPE" = "/dev/null" ]; then
147 "changerdev ($TAPE) may not be the null device"
148 @@ -884,19 +884,19 @@
149 #### Set up the various config files.
151 conf_match=`expr "$changerfile" : .\*\.conf\$`
152 -if [ $conf_match -ge 6 ]; then
153 +if [ "$conf_match" -ge 6 ]; then
154 configfile=$changerfile
155 changerfile=`echo $changerfile | sed 's/.conf$//g'`
157 configfile=$changerfile.conf
160 -if [ ! -e $configfile ]; then
161 +if [ ! -e "$configfile" ]; then
164 "configuration file \"$configfile\" doesn't exist"
166 -if [ ! -f $configfile ]; then
167 +if [ ! -f "$configfile" ]; then
170 "configuration file \"$configfile\" is not a file"
171 @@ -907,10 +907,10 @@
172 slotfile=$changerfile-slot
173 labelfile=$changerfile-barcodes
175 -[ ! -s $cleanfile ] && echo 0 > $cleanfile
176 -[ ! -s $accessfile ] && echo 0 > $accessfile
177 -[ ! -s $slotfile ] && echo -1 > $slotfile
178 -[ ! -f $labelfile ] && > $labelfile
179 +[ ! -s "$cleanfile" ] && echo 0 > $cleanfile
180 +[ ! -s "$accessfile" ] && echo 0 > $accessfile
181 +[ ! -s "$slotfile" ] && echo -1 > $slotfile
182 +[ ! -f "$labelfile" ] && > $labelfile
183 cleancount=`cat $cleanfile`
184 accesscount=`cat $accessfile`
188 # Get DBGFILE set if it is not already.
190 -if [ $DBGFILE = /dev/null ]; then
191 +if [ "$DBGFILE" = /dev/null ]; then
192 if [ -d "$DBGDIR" ]; then
193 DBGFILE=$DBGDIR/changer.debug.drive$driveslot
195 @@ -1037,9 +1037,9 @@
197 Log `_ "Config info:"`
198 for var in $varlist; do
199 - if [ $var = "OFFLINE_BEFORE_UNLOAD" ]; then
200 + if [ "$var" = "OFFLINE_BEFORE_UNLOAD" ]; then
202 - elif [ $var = "AUTOCLEAN" ]; then
203 + elif [ "$var" = "AUTOCLEAN" ]; then
205 elif [ $var = "slotinfofile" ]; then
206 continue # not numeric
207 @@ -1062,12 +1062,12 @@
209 # Run the rest of the config file sanity checks.
211 -if [ $firstslot -gt $lastslot ]; then
212 +if [ "$firstslot" -gt "$lastslot" ]; then
215 `_ 'firstslot (%s) greater than lastslot (%s) in %s' "$firstslot" "$lastslot" "$configfile"`
217 -if [ $autoclean -ne 0 -a $cleanslot -lt 0 ]; then
218 +if [ "$autoclean" -ne 0 -a "$cleanslot" -lt 0 ]; then
221 `_ 'autoclean set but cleanslot not valid (%s)' "$cleanslot"`
222 @@ -1077,10 +1077,10 @@
224 currentslot=`cat $slotfile`
225 if IsNumeric "$currentslot" ; then
226 - if [ $currentslot -lt $firstslot ]; then
227 + if [ "$currentslot" -lt "$firstslot" ]; then
228 Log `_ 'SETUP -> current slot %s less than %s ... resetting to %s' "$currentslot" "$firstslot" "$firstslot"`
229 currentslot=$firstslot
230 - elif [ $currentslot -gt $lastslot ]; then
231 + elif [ "$currentslot" -gt "$lastslot" ]; then
232 Log `_ 'SETUP -> current slot %s greater than %s ... resetting to %s' "$currentslot" "$lastslot" "$lastslot"`
233 currentslot=$lastslot
235 @@ -1093,19 +1093,19 @@
236 first_slot_in_list=-1
237 next_slot_after_current=-1
238 for slot in $slot_list; do
239 - if [ $first_slot_in_list -lt 0 ]; then
240 + if [ "$first_slot_in_list" -lt 0 ]; then
241 first_slot_in_list=$slot # in case $firstslot is missing
243 - if [ $slot -eq $currentslot ]; then
244 + if [ "$slot" -eq "$currentslot" ]; then
247 - elif [ $slot -gt $currentslot ]; then
248 + elif [ "$slot" -gt "$currentslot" ]; then
249 next_slot_after_current=$slot # $currentslot is missing
253 -if [ $found_current -eq 0 ]; then
254 - if [ $next_slot_after_current -lt 0 ]; then
255 +if [ "$found_current" -eq 0 ]; then
256 + if [ "$next_slot_after_current" -lt 0 ]; then
257 new_currentslot=$first_slot_in_list
259 new_currentslot=$next_slot_after_current
260 @@ -1124,9 +1124,9 @@
261 test -n "$DEBUG" && set -x
262 Log `_ 'EJECT -> ejecting tape from %s' "$tape"`
264 - if [ $loadedslot -gt 0 ]; then
265 + if [ "$loadedslot" -gt 0 ]; then
266 Log `_ 'EJECT -> moving tape from drive %s to storage slot %s' "$driveslot" "$loadedslot"`
267 - if [ $offline_before_unload -ne 0 ]; then
268 + if [ "$offline_before_unload" -ne 0 ]; then
269 Run try_eject_device $tape
272 @@ -1134,7 +1134,7 @@
274 Log `_ ' -> status %s, result "%s"' "$status" "$result"`
276 - if [ $status -ne 0 ]; then
277 + if [ "$status" -ne 0 ]; then
281 @@ -1213,7 +1213,7 @@
284 while [ $# -gt 0 ]; do
285 - if [ $1 -eq $find_slot ]; then
286 + if [ "$1" -eq "$find_slot" ]; then
290 @@ -1242,15 +1242,15 @@
291 # If the desired slot is already loaded, we are done. Only update
292 # current slot if this is not the cleaning slot.
294 - if [ $loadslot = $loadedslot ]; then
295 - if [ $loadslot -ne $cleanslot ]; then
296 + if [ "$loadslot" = "$loadedslot" ]; then
297 + if [ "$loadslot" -ne "$cleanslot" ]; then
299 echo $loadslot > $slotfile
301 Exit 0 "$loadedslot" "$rawtape"
302 return $? # in case we are internal
304 - if [ $loadedslot -eq -2 ]; then
305 + if [ "$loadedslot" -eq -2 ]; then
306 Exit 0 "$loadedslot" "$rawtape"
307 return $? # in case we are internal
309 @@ -1258,20 +1258,20 @@
310 # If we are loading the cleaning tape, bump the cleaning count
311 # and reset the access count. Otherwise, bump the access count
312 # and see if it is time to do a cleaning.
313 - if [ $loadslot = $cleanslot ]; then
314 + if [ "$loadslot" = "$cleanslot" ]; then
315 rm -f $cleanfile $accessfile
316 expr $cleancount + 1 > $cleanfile
320 expr $accesscount + 1 > $accessfile
321 - if [ $autoclean -ne 0 -a $accesscount -gt $autocleancount ]
322 + if [ "$autoclean" -ne 0 -a "$accesscount" -gt "$autocleancount" ]
324 internal_call=`expr $internal_call + 1`
325 loadslot clean > /dev/null 2>&1
327 internal_call=`expr $internal_call - 1`
328 - if [ $status -ne 0 ]; then
329 + if [ "$status" -ne 0 ]; then
330 Exit $status "$loadslot" "$exit_answer"
331 return $? # in case we are internal
333 @@ -1291,14 +1291,14 @@
334 eject > /dev/null 2>&1
336 internal_call=`expr $internal_call - 1`
337 - if [ $status -gt 1 ]; then
338 + if [ "$status" -gt 1 ]; then
339 Exit $status "$exit_slot" "$exit_answer"
340 return $? # in case we are internal
343 # If we were doing an "advance", we are done.
344 - if [ $whichslot = advance ]; then
345 - if [ $loadslot -ne $cleanslot ]; then
346 + if [ "$whichslot" = "advance" ]; then
347 + if [ "$loadslot" -ne "$cleanslot" ]; then
349 echo $loadslot > $slotfile
351 @@ -1312,7 +1312,7 @@
353 Log `_ ' -> status %s, result "%s"' "$status" "$result"`
355 - if [ $status -ne 0 ]; then
356 + if [ "$status" -ne 0 ]; then
357 Exit 2 "$loadslot" "$result"
358 return $? # in case we are internal
360 @@ -1322,7 +1322,7 @@
361 # for "long enough" (as determined empirically by the user),
362 # then return success.
364 - if [ $loadslot -eq $cleanslot ]; then
365 + if [ "$loadslot" -eq "$cleanslot" ]; then
366 Run sleep $cleancycle
367 Exit 0 "$loadslot" "$rawtape"
368 return $? # in case we are internal
369 @@ -1334,7 +1334,7 @@
372 sleep $initial_poll_delay
373 - while [ $waittime -lt $max_drive_wait ]; do
374 + while [ "$waittime" -lt "$max_drive_wait" ]; do
375 amdevcheck_status $tape
376 if [ $? -eq 0 ]; then
378 @@ -1343,12 +1343,12 @@
379 sleep $poll_drive_ready
380 waittime=`expr $waittime + $poll_drive_ready`
382 - if [ $ready -eq 0 ]; then
383 + if [ "$ready" -eq 0 ]; then
384 Exit 2 "$loadslot" `_ 'Drive not ready after %s seconds: %s' "$max_drive_wait" "$amdevcheck_message"`
385 return $? # in case we are internal
388 - if [ $loadslot -ne $cleanslot ]; then
389 + if [ "$loadslot" -ne "$cleanslot" ]; then
391 echo $loadslot > $slotfile
393 @@ -1379,11 +1379,11 @@
394 # can search based on barcodes.
397 - if [ $havereader -eq 1 ]; then
398 + if [ "$havereader" -eq 1 ]; then
402 - if [ $currentslot -lt $firstslot -o $currentslot -gt $lastslot ]; then
403 + if [ "$currentslot" -lt "$firstslot" -o "$currentslot" -gt "$lastslot" ]; then
404 currentslot=$firstslot # what "current" will get
406 numslots=`expr $lastslot - $firstslot + 1`
407 @@ -1404,12 +1404,12 @@
411 - if [ $loadedslot -lt 0 ]; then
412 + if [ "$loadedslot" -lt 0 ]; then
413 Exit 1 `_ '<none>'` `_ 'No tape currently loaded'`
414 return $? # in case we are internal
416 record_label_in_slot "$tapelabel" "$loadedslot"
417 - if [ $havereader -eq 0 ]; then
418 + if [ "$havereader" -eq 0 ]; then
419 Exit 0 "$loadedslot" "$rawtape" # that's all we needed
420 return $? # in case we are internal
422 @@ -1419,7 +1419,7 @@
424 Log `_ 'LABEL -> Adding label "%s" with barcode "%s" for slot %s into %s' "$tapelabel" "$loadedbarcode" "$loadedslot" "$labelfile"`
425 read_labelfile "$tapelabel" "$loadedbarcode" < $labelfile
426 - if [ $labelfile_entry_found -ne 0 ]; then
427 + if [ "$labelfile_entry_found" -ne 0 ]; then
429 if [ "$labelfile_barcode" != "$loadedbarcode" ]; then
431 @@ -1465,13 +1465,13 @@
432 return $? # in case we are internal
435 - if [ $havereader -eq 0 ]; then
436 + if [ "$havereader" -eq 0 ]; then
437 Exit 2 `_ '<none>'` `_ 'Not configured with barcode reader'`
438 return $? # in case we are internal
440 Log `_ 'SEARCH -> Hunting for label "%s"' "$tapelabel"`
441 read_labelfile "$tapelabel" "" < $labelfile
442 - if [ $labelfile_entry_found -eq 0 ]; then
443 + if [ "$labelfile_entry_found" -eq 0 ]; then
444 LogAppend `_ ' -> !!! label "%s" not found in %s !!!' "$tapelabel" "$labelfile"`
445 LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`