X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=changer-src%2Fchg-lib.sh.in;h=7ed4e5a98a8b6cfacb4116ae8efa8482a67af44e;hb=94a044f90357edefa6f4ae9f0b1d5885b0e34aee;hp=2df29bf0d1ab7b833f7ddfdd16da6395ade04166;hpb=d3b2175e084f88c8736ad7073eacbf4670147aec;p=debian%2Famanda diff --git a/changer-src/chg-lib.sh.in b/changer-src/chg-lib.sh.in index 2df29bf..7ed4e5a 100644 --- a/changer-src/chg-lib.sh.in +++ b/changer-src/chg-lib.sh.in @@ -17,53 +17,116 @@ 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@" "${@}" } - ammt() { - "${sbindir}/ammt-@VERSION@" "${@}" - } - amdd() { - "${sbindir}/amdd-@VERSION@" "${@}" + amdevcheck() { + "${sbindir}/amdevcheck-@VERSION@" "${@}" } else amgetconf() { "${sbindir}/amgetconf" "${@}" } - amdd() { - "${sbindir}/amdd" "${@}" - } - amdd() { - "${sbindir}/amdd" "${@}" + amdevcheck() { + "${sbindir}/amdevcheck" "${@}" } fi + +# 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 +# exists and is executable. If an incomplete path was specified (e.g., "mt"), +# we ask the shell to search the path. Returns 0 on success, 1 on failure. + +try_find_mt() { + # Only do this once. + if test -n $mt_found; then + return 0 + fi + + if test -z $MT; then + MT=mt + fi + + if "`echo $MT | dd bs=1 count=1`" = "/"; then + if ! test -f "${MT}"; then + echo `_ "mt binary at '%s' not found" "$MTX"` + return 1 + fi + if ! test -x "${MT}"; then + echo `_ "mt binary at '%s' is not executable" "$MTX"` + return 1 + fi + else + # try running it to see if the shell can find it + "$MT" >/dev/null 2>/dev/null + if test $? -eq 127 -o $? -eq 126; then + echo `_ "Could not run mt binary at '%s'" "$MTX"` + return 1 + fi + fi + + mt_found=yes + return 0 +} + +# 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" +} + +# 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. +amdevcheck_status() { + amdevcheck_config_dir=`pwd` + amdevcheck_config_name=`basename $amdevcheck_config_dir` + amdevcheck_output=`amdevcheck $amdevcheck_config_name $@` + + if test $? -eq 0 || \ + echo $amdevcheck_output | grep UNLABELED > /dev/null; then + return 0 + else + return 1 + fi +} + +# This attempts to eject a device using whatever system tools are available. +# At the moment, that means mt for tapes, and nothing otherwise, but might +# be extended at some later time. + +try_eject_device() { + if echo "$1" | grep -e '^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" + else + try_eject_device_tape= + fi + + if test -n "$try_eject_device_tape"; then + if try_find_mt; then + $MT $MTF "$try_eject_device_tape" eject + fi + else + # Technically we failed to eject the device, but we presume that's + # because it doesn't require ejection. + return 0 + fi +}