1 ################################################################################
2 # You may want to customize these values
3 ################################################################################
5 # These are the defaults discovered by configure when Amanda was installed.
6 # They can be overridden here, or by by 'mt_binary' and 'mtx_binary',
7 # respectively, in the changerfile (currently only for chg-zd-mtx.sh and
13 # This is the flag used to specify a device filename to 'mt', usually '-f'
16 ################################################################################
17 # No user-level customization should be required beyond this point.
18 ################################################################################
21 exec_prefix="@exec_prefix@"
23 libexecdir="@libexecdir@"
24 amlibexecdir="@amlibexecdir@"
25 . "${amlibexecdir}/amanda-sh-lib.sh"
28 # Eponymous functions to access various amanda apps
29 # TODO: move to amanda-sh-lib.sh
32 "${sbindir}/amgetconf" "${@}"
35 "${sbindir}/amdevcheck" "${@}"
38 # This function tries to find a useable mt binary. If a fully-qualified path
39 # was provided at configure time or via a config file, we check that it
40 # exists and is executable. If an incomplete path was specified (e.g., "mt"),
41 # we ask the shell to search the path. Returns 0 on success, 1 on failure.
45 if test -n $mt_found; then
53 if "`echo $MT | dd bs=1 count=1`" = "/"; then
54 if ! test -f "${MT}"; then
55 echo `_ "mt binary at '%s' not found" "$MTX"`
58 if ! test -x "${MT}"; then
59 echo `_ "mt binary at '%s' is not executable" "$MTX"`
63 # try running it to see if the shell can find it
64 "$MT" >/dev/null 2>/dev/null
65 if test $? -eq 127 -o $? -eq 126; then
66 echo `_ "Could not run mt binary at '%s'" "$MTX"`
75 # This function strips the tape: from the front of device names.
76 # Capture its output with ``.
77 tape_device_filename() {
78 if echo "$1"|grep '^tape:' >/dev/null; then
79 echo "$1" | sed 's/^tape://'
81 if echo "$1"|grep '^/' >/dev/null; then
87 # Invoke amdevcheck to determine whether the device is ready for use.
89 # @return 0 if a tape is loaded or error
90 # @return 1 if a tape is tape offline or busy
92 # @side-effect: $amdevcheck_message is the contents of all MESSAGE lines from
93 # amdevcheck, suitable for use in higher-level error messages
96 local amdevcheck_output=`amdevcheck . $@`
97 local amdevcheck_status=$?
99 test "$amdevcheck_status" -ne 0 && return 0
101 # extract any messages
102 amdevcheck_message=`echo "$amdevcheck_output" | sed -n -e '/^MESSAGE /{' -e 's/^MESSAGE //' -e 'p' -e 'q' -e '}'`
104 # Return 1 if it's possible that the device is offline or busy; if the device cannot
105 # distinguish this state from an error condition, then our caller will just have to
107 if echo "$amdevcheck_output" | $EGREP "VOLUME_MISSING|DEVICE_BUSY" > /dev/null; then
114 # This attempts to eject a device using whatever system tools are available.
115 # At the moment, that means mt for tapes, and nothing otherwise, but might
116 # be extended at some later time.
119 if echo "$1" | grep '^tape:' > /dev/null; then
120 try_eject_device_tape="`echo \"$1\" | cut -b6-`"
121 elif echo "$1" | grep -v : > /dev/null; then
122 try_eject_device_tape="$1"
124 try_eject_device_tape=
127 if test -n "$try_eject_device_tape"; then
129 $MT $MTF "$try_eject_device_tape" offline
132 # Technically we failed to eject the device, but we presume that's
133 # because it doesn't require ejection.