X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fchg-zd-mtx.sh.in;h=a36e9010e8415f008c030323d2a01e31d3c53bdc;hb=d3b2175e084f88c8736ad7073eacbf4670147aec;hp=281112cd5449f16dc734ce8768b214c31f0c9b35;hpb=34197d9f46a5f4e944378cbb65fca32ee0eec7b9;p=debian%2Famanda diff --git a/changer-src/chg-zd-mtx.sh.in b/changer-src/chg-zd-mtx.sh.in index 281112c..a36e901 100644 --- a/changer-src/chg-zd-mtx.sh.in +++ b/changer-src/chg-zd-mtx.sh.in @@ -205,6 +205,7 @@ # # initial_poll_delay=NN #### initial delay after load before polling for # #### readiness +# #### #### @@ -305,17 +306,10 @@ # env DEBUG=yes .../chg-zd-mtx ... ################################################################################ -################################################################################ -# You may need to customize these things -################################################################################ - -MT=@MT@ -MTF=@MT_FILE_FLAG@ -MTX=@MTX@ - -################################################################################ -# No user-level customization should be required beyond this point. -################################################################################ +# source utility functions and values from configure +exec_prefix=@exec_prefix@ +libexecdir=@libexecdir@ +. ${libexecdir}/chg-lib.sh test -n "$DEBUG" && set -x TMPDIR="@AMANDA_TMPDIR@" @@ -376,7 +370,7 @@ Exit() { exit_slot=$1 shift exit_answer="$@" - Log $call_type "($code)" "->" "$exit_slot" "$@" + Log $call_type "($code) -> $exit_slot $@" echo "$exit_slot" "$@" if [ $call_type = Return ]; then return $code @@ -390,11 +384,11 @@ Exit() { ### Run() { - Log Running: "$@" + Log `_ 'Running: %s' "$@"` rm -f $stdout $stderr "$@" > $stdout 2> $stderr exitcode=$? - Log Exit code: $exitcode + Log `_ 'Exit code: %s' "$exitcode"` if [ -s $stdout ] then LogAppend Stdout: @@ -487,7 +481,9 @@ get_loaded_info() { loadedslot=$1 loadedbarcode=$2 if [ -z "$loadedslot" ]; then - Exit 2 "" "could not determine current slot, are you sure your drive slot is $driveslot" + Exit 2 \ + `_ ''` \ + "could not determine current slot, are you sure your drive slot is $driveslot" return $? # in case we are internal fi @@ -542,12 +538,12 @@ get_loaded_info() { : else Exit 2 \ - "" \ + `_ ''` \ "currently loaded slot ($loadedslot) not numeric" return $? # in case we are internal fi - Log "STATUS -> currently loaded slot = $loadedslot" - LogAppend " -> currently loaded barcode = \"$loadedbarcode\"" + Log `_ 'STATUS -> currently loaded slot = %s' "$loadedslot"` + LogAppend `_ ' -> currently loaded barcode = "%s"' "$loadedbarcode"` } ### @@ -593,7 +589,7 @@ get_slot_list() { last=$lastslot for slot in $slot_list; do if [ $firstslot -lt 0 ]; then - Log "SLOTLIST -> firstslot set to $slot" + Log `_ 'SLOTLIST -> firstslot set to %s' "$slot"` firstslot=$slot fi if [ $lastslot -lt 0 ]; then @@ -601,18 +597,18 @@ get_slot_list() { fi done if [ $lastslot -lt 0 -a $last -ge 0 ]; then - Log "SLOTLIST -> lastslot set to $last" + Log `_ 'SLOTLIST -> lastslot set to %s' "$last"` lastslot=$last fi if [ $firstslot -lt 0 ]; then Exit 2 \ - "" \ - "cannot determine first slot" + `_ ''` \ + `_ 'cannot determine first slot'` return $? # in case we are internal elif [ $lastslot -lt 0 ]; then Exit 2 \ - "" \ - "cannot determine last slot" + `_ ''` \ + `_ 'cannot determine last slot'` return $? # in case we are internal fi fi @@ -624,7 +620,7 @@ get_slot_list() { done if [ -z "$amanda_slot_list" ]; then Exit 2 \ - "" \ + `_ ''` \ "no slots available" return $? # in case we are internal fi @@ -657,28 +653,28 @@ fi changerfile=`amgetconf$SUF changerfile 2>/dev/null` if [ -z "$changerfile" ]; then Exit 2 \ - "" \ + `_ ''` \ "changerfile must be specified in amanda.conf" fi tape=`amgetconf$SUF tapedev 2>/dev/null` if [ -z "$tape" ]; then Exit 2 \ - "" \ + `_ ''` \ "tapedev may not be empty" elif [ $tape = "/dev/null" -o `expr "$tape" : 'null:'` -eq 5 ]; then Exit 2 \ - "" \ + `_ ''` \ "tapedev ($tape) may not be the null device" fi TAPE=`amgetconf$SUF changerdev 2>/dev/null` if [ -z "$TAPE" ]; then Exit 2 \ - "" \ + `_ ''` \ "changerdev may not be empty" elif [ $TAPE = "/dev/null" ]; then Exit 2 \ - "" \ + `_ ''` \ "changerdev ($TAPE) may not be the null device" fi export TAPE # for mtx command @@ -696,6 +692,17 @@ else configfile=$changerfile.conf fi +if [ ! -e $configfile ]; then + Exit 2 \ + `_ ''` \ + "configuration file \"$configfile\" doesn't exist" +fi +if [ ! -f $configfile ]; then + Exit 2 \ + `_ ''` \ + "configuration file \"$configfile\" is not a file" +fi + cleanfile=$changerfile-clean accessfile=$changerfile-access slotfile=$changerfile-slot @@ -760,12 +767,12 @@ if [ $DBGFILE = /dev/null ]; then else DBGFILE=/dev/null fi - Log === Start "`date`" === + Log `_ '=== Start %s ===' "\`date\`"` fi if [ -z "$driveslot" ]; then Exit 2 \ - "" \ - "cannot determine drive slot from $tape" + `_ ''` \ + `_ 'cannot determine drive slot from %s' "$tape"` fi stdout=$TMPDIR/$myname.1.$$ @@ -773,11 +780,11 @@ stderr=$TMPDIR/$myname.2.$$ mtx_status=$TMPDIR/$myname.status.$$ trap "rm -f $stdout $stderr $mtx_status" 0 # exit cleanup -Log "Using config file $configfile" +Log `_ 'Using config file %s' "$configfile"` # Log the argument list. -Log "Arg info:" +Log `_ "Arg info:"` LogAppend "\$# = $#" i=0 LogAppend "\$$i = \"$argv0\"" @@ -810,7 +817,7 @@ max_drive_wait=${max_drive_wait:-'120'} # default: two minutes get_slot_list -Log "Config info:" +Log `_ "Config info:"` for var in $varlist; do if [ $var = "OFFLINE_BEFORE_UNLOAD" ]; then continue # old name @@ -820,15 +827,15 @@ for var in $varlist; do eval val=\"'$'$var\" if [ -z "$val" ]; then Exit 2 \ - "" \ - "$var missing in $configfile" + `_ ''` \ + `_ '%s missing in %s' "$var" "$configfile"` fi if IsNumeric "$val" ; then : else Exit 2 \ - "" \ - "$var ($val) not numeric in $configfile" + `_ ''` \ + `_ '%s (%s) not numeric in %s' "$var" "$val" "$configfile"` fi LogAppend $var = \"$val\" done @@ -837,14 +844,13 @@ done if [ $firstslot -gt $lastslot ]; then Exit 2 \ - "" \ - "firstslot ($firstslot) greater than" \ - "lastslot ($lastslot) in $configfile" + `_ ''` \ + `_ 'firstslot (%s) greater than lastslot (%s) in %s' "$firstslot" "$lastslot" "$configfile"` fi if [ $autoclean -ne 0 -a $cleanslot -lt 0 ]; then Exit 2 \ - "" \ - "autoclean set but cleanslot not valid ($cleanslot)" + `_ ''` \ + `_ 'autoclean set but cleanslot not valid (%s)' "$cleanslot"` fi # Set up the current slot @@ -852,19 +858,14 @@ fi currentslot=`cat $slotfile` if IsNumeric "$currentslot" ; then if [ $currentslot -lt $firstslot ]; then - Log "SETUP -> current slot $currentslot" \ - "less than $firstslot ..." \ - "resetting to $firstslot" + Log `_ 'SETUP -> current slot %s less than %s ... resetting to %s' "$currentslot" "$firstslot" "$firstslot"` currentslot=$firstslot elif [ $currentslot -gt $lastslot ]; then - Log "SETUP -> current slot $currentslot" \ - "greater than $lastslot ..." \ - "resetting to $lastslot" + Log `_ 'SETUP -> current slot %s greater than %s ... resetting to %s' "$currentslot" "$lastslot" "$lastslot"` currentslot=$lastslot fi else - Log "SETUP -> contents of $slotfile ($currentslot) invalid," \ - "setting current slot to first slot ($firstslot)" + Log `_ 'SETUP -> contents of %s (%s) invalid, setting current slot to first slot (%s)' "$slotfile" "$currentslot" "$firstslot"` currentslot=$firstslot fi @@ -889,8 +890,7 @@ if [ $found_current -eq 0 ]; then else new_currentslot=$next_slot_after_current fi - Log "WARNING -> current slot $currentslot not available," \ - "setting current slot to next slot ($new_currentslot)" + Log `_ 'WARNING -> current slot %s not available, setting current slot to next slot (%s)' "$currentslot" "$new_currentslot"` currentslot=$new_currentslot fi @@ -902,18 +902,17 @@ fi eject() { test -n "$DEBUG" && set -x - Log "EJECT -> ejecting tape from $tape" + Log `_ 'EJECT -> ejecting tape from %s' "$tape"` get_loaded_info if [ $loadedslot -gt 0 ]; then - Log "EJECT -> moving tape from drive $driveslot" \ - "to storage slot $loadedslot" + Log `_ 'EJECT -> moving tape from drive %s to storage slot %s' "$driveslot" "$loadedslot"` if [ $offline_before_unload -ne 0 ]; then Run $MT $MTF $tape offline > /dev/null 2>&1 fi sleep $unloadpause result=`Run $MTX unload $loadedslot $driveslot 2>&1` status=$? - Log " -> status $status, result \"$result\"" + Log `_ ' -> status %s, result "%s"' "$status" "$result"` mtx_status_valid=0 if [ $status -ne 0 ]; then answer="$result" @@ -923,7 +922,7 @@ eject() { code=0 fi else - answer="Drive was not loaded" + answer=`_ 'Drive was not loaded'` code=1 fi Exit $code "$loadedslot" "$answer" @@ -936,13 +935,12 @@ eject() { reset() { test -n "$DEBUG" && set -x - Log "RESET -> loading tape from slot $firstslot" \ - "to drive $driveslot ($tape)" + Log `_ 'RESET -> loading tape from slot %s to drive %s (%s)' "$firstslot" "$driveslot" "$tape"` # Call loadslot without doing it as an internal and let it finish # things up. loadslot $firstslot # NOTREACHED - Exit 2 "" "reset: should not get here" + Exit 2 `_ ''` `_ 'reset: should not get here'` return $? # in case we are internal } @@ -955,11 +953,11 @@ reset() { loadslot() { test -n "$DEBUG" && set -x if [ $# -lt 1 ]; then - Exit 2 "" "Missing -slot argument" + Exit 2 `_ ''` `_ 'Missing -slot argument'` return $? # in case we are internal fi whichslot=$1 - Log "LOADSLOT -> load drive $driveslot ($tape) from slot $whichslot" + Log `_ 'LOADSLOT -> load drive %s (%s) from slot %s' "$driveslot" "$tape" "$whichslot"` numeric=`echo $whichslot | sed 's/[^0-9]//g'` case $whichslot in @@ -979,7 +977,7 @@ loadslot() { find_slot=$cleanslot ;; *) - Exit 2 "" "Illegal slot: \"$whichslot\"" + Exit 2 `_ ''` `_ 'Illegal slot: "%s"' "$whichslot"` return $? # in case we are internal ;; esac @@ -1003,9 +1001,8 @@ loadslot() { done if [ $# -le 0 ]; then Exit 2 \ - "" \ - "Cannot find slot $find_slot" \ - "in slot list ($slot_list)" + `_ ''` \ + `_ 'Cannot find slot %s in slot list (%s)' "$find_slot " "$slot_list"` return $? # in case we are internal fi @@ -1090,11 +1087,10 @@ loadslot() { fi # Load the tape, finally! - Log "LOADSLOT -> loading tape from slot $loadslot" \ - "to drive $driveslot ($tape)" + Log `_ "LOADSLOT -> loading tape from slot %s to drive %s (%s)" "$loadslot" "$driveslot" "$tape"` result=`Run $MTX load $loadslot $driveslot 2>&1` status=$? - Log " -> status $status, result \"$result\"" + Log `_ ' -> status %s, result "%s"' "$status" "$result"` mtx_status_valid=0 if [ $status -ne 0 ]; then Exit 2 "$loadslot" "$result" @@ -1128,9 +1124,7 @@ loadslot() { waittime=`expr $waittime + $poll_drive_ready` done if [ $ready -eq 0 ]; then - Exit 2 "$loadslot" "Drive not ready after" \ - "$max_drive_wait seconds," \ - "rewind said \"$result\"" + Exit 2 "$loadslot" `_ 'Drive not ready after %s seconds, rewind said "%s"' "$max_drive_wait" "$result"` return $? # in case we are internal fi @@ -1151,13 +1145,13 @@ info() { test -n "$DEBUG" && set -x get_loaded_info get_slot_list - Log "INFO -> first slot: $firstslot" - LogAppend " -> current slot: $currentslot" - LogAppend " -> loaded slot: $loadedslot" - LogAppend " -> last slot: $lastslot" - LogAppend " -> slot list: $slot_list" - LogAppend " -> can go backwards: 1" - LogAppend " -> havereader: $havereader" + Log `_ 'INFO -> first slot: %s' "$firstslot"` + LogAppend `_ ' -> current slot: %s' "$currentslot"` + LogAppend `_ ' -> loaded slot: %s' "$loadedslot"` + LogAppend `_ ' -> last slot: %s' "$lastslot"` + LogAppend `_ ' -> slot list: %s' "$slot_list"` + LogAppend `_ ' -> can go backwards: 1'` + LogAppend `_ ' -> havereader: %s' "$havereader"` ### # Check if a barcode reader is configured or not. If so, it @@ -1193,24 +1187,20 @@ read_labelfile() { while read lbl bc junk; do line=`expr $line + 1` if [ -z "$lbl" -o -z "$bc" -o -n "$junk" ]; then - Log "ERROR -> Line $line malformed: $lbl $bc $junk" - LogAppend " -> Remove $labelfile" \ - "and run" \ - "\"$sbindir/amtape $config update\"" + Log `_ 'ERROR -> Line %s malformed: %s %s %s' "$line" "$lbl" "$bc" "$junk"` + LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"` Exit 2 \ - "" \ - "Line $line malformed in $labelfile: $lbl $bc $junk" + `_ ''` \ + `_ 'Line %s malformed in %s: %s %s %s' "$line" "$labelfile" "$lbl" "$bc" "$junk"` return $? # in case we are internal fi if [ $lbl = "$lbl_search" -o $bc = "$bc_search" ]; then if [ $labelfile_entry_found -ne 0 ]; then - Log "ERROR -> Duplicate entries: $labelfile line $line" - LogAppend " -> Remove $labelfile" \ - "and run" \ - "\"$sbindir/amtape $config update\"" + Log `_ 'ERROR -> Duplicate entries: %s line %s' "$labelfile" "$line"` + LogAppend `_ ' -> Remove $labelfile and run "$sbindir/amtape $config update"' "$labelfile" "$sbindir/amtape" "$config"` Exit 2 \ - "" \ - "Duplicate entries: $labelfile line $line" + `_ ''` \ + `_ 'Duplicate entries: %s line %s' "$labelfile" "$line"` return $? # in case we are internal fi labelfile_entry_found=1 @@ -1228,23 +1218,20 @@ read_labelfile() { addlabel() { test -n "$DEBUG" && set -x if [ $# -lt 1 ]; then - Exit 2 "" "Missing -label argument" + Exit 2 `_ ''` `_ 'Missing -label argument'` return $? # in case we are internal fi tapelabel=$1 if [ $havereader -eq 0 ]; then - Exit 2 "" "Not configured with barcode reader" + Exit 2 `_ ''` `_ 'Not configured with barcode reader'` return $? # in case we are internal fi get_loaded_info if [ $loadedslot -lt 0 ]; then - Exit 1 "" "No tape currently loaded" + Exit 1 `_ ''` `_ 'No tape currently loaded'` return $? # in case we are internal fi - Log "LABEL -> Adding label \"$tapelabel\"" \ - "with barcode \"$loadedbarcode\"" \ - "for slot $loadedslot" \ - "into $labelfile" + Log `_ 'LABEL -> Adding label "%s" with barcode "%s" for slot %s into %s' "$tapelabel" "$loadedbarcode" "$loadedslot" "$labelfile"` read_labelfile "$tapelabel" "$loadedbarcode" < $labelfile if [ $labelfile_entry_found -ne 0 ]; then lf_val= @@ -1262,25 +1249,17 @@ addlabel() { new_val=$tapelabel fi if [ -n "$lf_val" ]; then - LogAppend "ERROR -> !!! Label database corrupted !!!" - LogAppend " -> \"$old_val\" conflicts with" \ - "new $val_type \"$new_val\"" \ - "for $lf_type \"$lf_val\"" - LogAppend " -> Remove $labelfile" \ - "and run" \ - "\"$sbindir/amtape $config update\"" + LogAppend `_ 'ERROR -> !!! Label database corrupted !!!'` + LogAppend `_ ' -> "%s" conflicts with new %s "%s" for %s "%s"' "$old_val" "$val_type" "$new_val" "$lf_type" "$lf_val"` Exit 2 \ - "" \ - "$tapelabel: \"$old_val\" conflicts with" \ - "new $val_type \"$new_val\"" \ - "for $lf_type \"$lf_val\"" + `_ ''` \ + `_ '%s: "%s" conflicts with new %s "%s" for %s "%s"' "$tapelabel" "$old_val" "$val_type" "$new_val" "$lf_type" "$lf_val"` return $? # in case we are internal fi - LogAppend " -> already synced" + LogAppend `_ " -> already synced"` else echo "$tapelabel $loadedbarcode" >> $labelfile - LogAppend " -> appended $labelfile entry:" \ - "$tapelabel $loadedbarcode" + LogAppend `_ ' -> appended %s entry: %s %s' "$labelfile" "$tapelabel" "$loadedbarcode"` fi Exit 0 "$loadedslot" "$tape" return $? # in case we are internal @@ -1294,28 +1273,25 @@ addlabel() { searchtape() { test -n "$DEBUG" && set -x if [ $# -lt 1 ]; then - Exit 2 "" "Missing -search argument" + Exit 2 `_ ''` `_ 'Missing -search argument'` return $? # in case we are internal fi tapelabel=$1 if [ $havereader -eq 0 ]; then - Exit 2 "" "Not configured with barcode reader" + Exit 2 `_ ''` `_ 'Not configured with barcode reader'` return $? # in case we are internal fi - Log "SEARCH -> Hunting for label \"$tapelabel\"" + Log `_ 'SEARCH -> Hunting for label "%s"' "$tapelabel"` read_labelfile "$tapelabel" "" < $labelfile if [ $labelfile_entry_found -eq 0 ]; then - LogAppend " -> !!! label \"$tapelabel\" not found" \ - "in $labelfile !!!" - LogAppend " -> Remove $labelfile" \ - "and run" \ - "\"$sbindir/amtape $config update\"" + LogAppend `_ ' -> !!! label "%s" not found in %s !!!' "$tapelabel" "$labelfile"` + LogAppend `_ ' -> Remove $labelfile and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"` Exit 2 \ - "" \ - "$tapelabel: label \"$tapelabel\" not found in $labelfile" + `_ ''` \ + `_ '%s: label "%s" not found in %s' "$tapelabel" "$tapelabel" "$labelfile"` return $? # in case we are internal fi - LogAppend " -> barcode is \"$labelfile_barcode\"" + LogAppend `_ ' -> barcode is "%s"' "$labelfile_barcode"` get_mtx_status foundslot=`sed -n ' /VolumeTag *= *'$labelfile_barcode' *$/ { @@ -1323,24 +1299,20 @@ searchtape() { q } ' < $mtx_status` - LogAppend " -> foundslot is $foundslot" + LogAppend `_ ' -> foundslot is %s' "$foundslot"` if [ -z "$foundslot" ]; then - LogAppend "ERROR -> !!! Could not find slot" \ - "for barcode \"$labelfile_barcode\"!!!" - LogAppend " -> Remove $labelfile" \ - "and run" \ - "\"$sbindir/amtape $config update\"" + LogAppend `_ 'ERROR -> !!! Could not find slot for barcode "%s"!!!' "$labelfile_barcode"` + LogAppend `_ ' -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"` Exit 2 \ - "" \ - "barcode \"$labelfile_barcode\"" \ - "not found in mtx status output" + `_ ''` \ + `_ 'barcode "%s" not found in mtx status output' "$labelfile_barcode"` return $? # in case we are internal fi # Call loadslot without doing it as an internal and let it finish # things up. loadslot $foundslot # NOTREACHED - Exit 2 "" "searchtape: should not get here" + Exit 2 `_ ''` `_ 'searchtape: should not get here'` return $? # in case we are internal } @@ -1349,7 +1321,7 @@ searchtape() { ### if [ $# -lt 1 ]; then - Exit 2 "" "Usage: $myname -command args" + Exit 2 `_ ''` `_ 'Usage: %s -command args' "$myname"` fi cmd=$1 shift @@ -1376,8 +1348,8 @@ case "$cmd" in loadslot clean ;; *) - Exit 2 "" "unknown option: $cmd" + Exit 2 `_ ''` `_ 'unknown option: %s' "$cmd"` ;; esac -Exit 2 "" "$myname: should not get here" +Exit 2 `_ ''` `_ '%s: should not get here' "$myname"`