X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=changer-src%2Fchg-lib.sh.in;h=a53c48a8cfff139732818a8be0e8b8d2ccbe148c;hb=f8da3d96bb7fe9d1e74087295c5c39f53a3623ef;hp=0e383e67b8358e7d50227e703d2b0af68bfaac91;hpb=e442edb4d5816c4ad107ad9e71164f845eba70ad;p=debian%2Famanda diff --git a/changer-src/chg-lib.sh.in b/changer-src/chg-lib.sh.in index 0e383e6..a53c48a 100644 --- a/changer-src/chg-lib.sh.in +++ b/changer-src/chg-lib.sh.in @@ -17,51 +17,23 @@ MTF=@MT_FILE_FLAG@ # No user-level customization should be required beyond this point. ################################################################################ -#### -# Set up paths, including PATH for finding amanda executables - -PATH="$PATH:@sbindir@:@libexecdir@" prefix="@prefix@" exec_prefix="@exec_prefix@" sbindir="@sbindir@" libexecdir="@libexecdir@" - -#### -# Gettext - -#+ -# Function to: -# Simplify gettext usage by allowing printf format -# strings for translators, use _() identifier for -# xgettext extraction similar to "C" usage and -# collapsing "printf `gettext fmt` ...", which is -# used everywhere, into one function. -#- -_() { - fmt=`gettext -d amanda "$1"` - shift - printf "$fmt" $* -} +amlibexecdir="@amlibexecdir@" +. "${amlibexecdir}/amanda-sh-lib.sh" #### # 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 @@ -103,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 @@ -140,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" @@ -150,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