X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fchg-lib.sh.in;h=a53c48a8cfff139732818a8be0e8b8d2ccbe148c;hb=4f0b86f7a23848c16cfe82fae81e639917fcff27;hp=791154c70243ce2cb8ea3b4d8ff9d09a73c18c77;hpb=d92f70685083588e2a7ce6bc312a735f6937b5a6;p=debian%2Famanda diff --git a/changer-src/chg-lib.sh.in b/changer-src/chg-lib.sh.in index 791154c..a53c48a 100644 --- a/changer-src/chg-lib.sh.in +++ b/changer-src/chg-lib.sh.in @@ -28,21 +28,12 @@ amlibexecdir="@amlibexecdir@" # Eponymous functions to access various amanda apps # TODO: move to amanda-sh-lib.sh -if test "@USE_VERSION_SUFFIXES@" = "yes"; then - amgetconf() { - "${sbindir}/amgetconf-@VERSION@" "${@}" - } - amdevcheck() { - "${sbindir}/amdevcheck-@VERSION@" "${@}" - } -else - amgetconf() { - "${sbindir}/amgetconf" "${@}" - } - amdevcheck() { - "${sbindir}/amdevcheck" "${@}" - } -fi +amgetconf() { + "${sbindir}/amgetconf" "${@}" +} +amdevcheck() { + "${sbindir}/amdevcheck" "${@}" +} # This function tries to find a useable mt binary. If a fully-qualified path # was provided at configure time or via a config file, we check that it @@ -84,32 +75,36 @@ try_find_mt() { # This function strips the tape: from the front of device names. # Capture its output with ``. tape_device_filename() { - # Easy (?) to express this in Perl. - perl -e '$ARGV[0] =~ /^(?:([^:]+):)?(.*)$/; - print $2 if ($1 || "tape") eq "tape"' "$1" + if echo "$1"|grep '^tape:' >/dev/null; then + echo "$1" | sed 's/^tape://' + else + if echo "$1"|grep '^/' >/dev/null; then + echo "$1" + fi + fi } -# Runs amdevcheck to find out if a particular device is usable. Finds the -# config name based on pwd, so run it from the config directory. The sole -# argument should be the device name to check. Note that amdevcheck can FP -# on device status, since some devices can't differentiate between device -# problems and an unlabeled volume. +# Invoke amdevcheck to determine whether the device is ready for use. +# +# @return 0 if a tape is loaded or error +# @return 1 if a tape is tape offline or busy +# +# @side-effect: $amdevcheck_message is the contents of all MESSAGE lines from +# amdevcheck, suitable for use in higher-level error messages amdevcheck_status() { amdevcheck_message= - local amdevcheck_config_dir=`pwd` - local amdevcheck_config_name=`basename $amdevcheck_config_dir` - local amdevcheck_output=`amdevcheck $amdevcheck_config_name $@` + local amdevcheck_output=`amdevcheck . $@` local amdevcheck_status=$? test "$amdevcheck_status" -ne 0 && return 0 # extract any messages - amdevcheck_message=`echo "$amdevcheck_output" | sed '/^MESSAGE /{s/^MESSAGE //;p;}; d'` + amdevcheck_message=`echo "$amdevcheck_output" | sed -n -e '/^MESSAGE /{' -e 's/^MESSAGE //' -e 'p' -e 'q' -e '}'` # Return 1 if it's possible that the device is offline or busy; if the device cannot # distinguish this state from an error condition, then our caller will just have to # time out - if echo "$amdevcheck_output" | $EGREP "VOLUME_MISSING" > /dev/null; then + if echo "$amdevcheck_output" | $EGREP "VOLUME_MISSING|DEVICE_BUSY" > /dev/null; then return 1 else return 0 @@ -121,7 +116,7 @@ amdevcheck_status() { # be extended at some later time. try_eject_device() { - if echo "$1" | grep -e '^tape:' > /dev/null; then + if echo "$1" | grep '^tape:' > /dev/null; then try_eject_device_tape="`echo \"$1\" | cut -b6-`" elif echo "$1" | grep -v : > /dev/null; then try_eject_device_tape="$1" @@ -131,7 +126,7 @@ try_eject_device() { if test -n "$try_eject_device_tape"; then if try_find_mt; then - $MT $MTF "$try_eject_device_tape" eject + $MT $MTF "$try_eject_device_tape" offline fi else # Technically we failed to eject the device, but we presume that's