/usr/lib/amanda/chg-multi is in amanda-server 1:3.3.9-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | #!/bin/sh
#
# Amanda, The Advanced Maryland Automatic Network Disk Archiver
# Copyright (c) 1991-1999 University of Maryland at College Park
# Copyright (c) 2007-2013 Zmanda, Inc. All Rights Reserved.
# All Rights Reserved.
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of U.M. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. U.M. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Author: James da Silva, Systems Design and Analysis Group
# Computer Science Department
# University of Maryland at College Park
#
#
# chg-multi.sh - generic tape changer script
#
# source utility functions and values from configure
prefix=/usr
exec_prefix=${prefix}
amlibexecdir=/usr/lib/amanda
. ${amlibexecdir}/chg-lib.sh
pname="chg-multi"
if [ -d "/var/log/amanda" ]; then
logfile=/var/log/amanda/changer.debug
else
logfile=/dev/null
fi
echo `_ "arguments ->"` "$@" >> $logfile
ourconf=`amgetconf changerfile`
if ! error=try_find_mt; then
echo <none> $error
exit 2
fi
EXPR=expr
# EXPR=/usr/local/bin/expr # in case you need a more powerful expr...
# read in some config parameters
if [ ! -f "$ourconf" ]; then
answer=`_ '<none> %s: %s does not exist' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
firstslot=`awk '$1 == "firstslot" {print $2}' $ourconf 2>/dev/null`
if [ -z "$firstslot" ]; then
answer=`_ '<none> %s: firstslot not specified in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
lastslot=`awk '$1 == "lastslot" {print $2}' $ourconf 2>/dev/null`
if [ -z "$lastslot" ]; then
answer=`_ '<none> %s: lastslot not specified in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
nslots=`$EXPR $lastslot - $firstslot + 1`
gravity=`awk '$1 == "gravity" {print $2}' $ourconf 2>/dev/null`
if [ -z "$gravity" ]; then
answer=`_ '<none> %s: gravity not specified in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
needeject=`awk '$1 == "needeject" {print $2}' $ourconf 2>/dev/null`
if [ -z "$needeject" ]; then
answer=`_ '<none> %s: needeject not specified in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
multieject=`awk '$1 == "multieject" {print $2}' $ourconf 2>/dev/null`
if [ -z "$multieject" ]; then
echo `_ 'Note: setting multieject to a default of zero'` >> $logfile
multieject=0
fi
ejectdelay=`awk '$1 == "ejectdelay" {print $2}' $ourconf 2>/dev/null`
if [ -z "$ejectdelay" ]; then
echo `_ 'Note: setting ejectdelay to a default of zero'` >> $logfile
ejectdelay=0
fi
posteject=`awk '$1 == "posteject" {print $2}' $ourconf 2>/dev/null`
if [ -z "$posteject" ]; then
echo `_ 'Note: setting posteject to a default of "true"'` >> $logfile
posteject=true
fi
ourstate=`awk '$1 == "statefile" {print $2}' $ourconf 2>/dev/null`
if [ -z "$ourstate" ]; then
answer=`_ '<none> %s: statefile not specified in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
if [ -f "$ourstate" -a ! -r "$ourstate" ]; then
answer=`_ "<none> %s: Can't read the statefile %s" "$pname" "$ourstate"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
if [ -f "$ourstate" -a ! -w "$ourstate" ]; then
answer=`_ "<none> %s: Can't write the statefile %s" "$pname" "$ourstate"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
dirstate=`dirname $ourstate`
if [ ! -e "$dirstate" ]; then
answer=`_ "<none> %s: Directory %s doesn't exist" "$pname" "$dirstate"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
if [ ! -d "$dirstate" ]; then
answer=`_ '<none> %s: %s must be a directory' "$pname" "$dirstate"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
if [ ! -w "$dirstate" ]; then
answer=`_ "<none> %s: Can't write to %s directory" "$pname" "$dirstate"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
# needeject and multieject are incompatible
if [ $needeject -eq 1 ] && [ $multieject -eq 1 ] ; then
answer=`_ '<none> %s: needeject and multieject cannot be both enabled in %s' "$pname" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
# read in state: only curslot and curloaded at the present time
curslot=`awk '$1 == "curslot" {print $2}' $ourstate 2>/dev/null`
if [ -z "$curslot" ]; then
curslot=$firstslot
fi
curloaded=`awk '$1 == "curloaded" {print $2}' $ourstate 2>/dev/null`
if [ -z "$curloaded" ]; then
curloaded=0
fi
# process the command-line
# control vars to avoid code duplication: not all shells have functions!
usage=0
checkgravity=0
ejectslot=0
loadslot=0
slotempty=0
ejectonly=0
if [ $# -ge 1 ]; then command=$1; else command="-usage"; fi
case "$command" in
-info) # return basic information about changer
backwards=`$EXPR 1 - $gravity`
answer="$curslot $nslots $backwards"
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 0
;;
-reset) # reset changer. Actually, we only reset changer state. We
# trust that the operator has reloaded a stack and reset the
# hardware. In most cases, we do not want to actually do
# anything: if the operator has done something with the
# hardware, we have no way to know what the actual current
# slot is. If the hardware state has not changed, and what is
# really wanted is to load the first slot, use "slot first"
# instead
checkgravity=0
loadslot=1
newslot=$firstslot
curslot=$firstslot
# XXX put changer-specific reset here, if applicable
;;
-eject) # eject tape if loaded. Note that if multieject is set, this
# only can make sense if the position is last and gravity 1
checkgravity=0
loadslot=0
newslot=$curslot
ejectslot=1
ejectonly=1
if [ $multieject -eq 1 ] && \
([ $gravity -eq 0 ] || [ $curslot -ne $lastslot ]) ; then
# Can't do this: if we eject, the stacker is going to
# load the next tape, and our state will be botched
answer=`_ '%s %s: Cannot use -eject with multieject/nogravity/notlastslot' "$curslot" "$pname"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
fi
if [ $curloaded -eq 0 ]; then
answer=`_ '%s %s: slot already empty' "$curslot" "$pname"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
fi
;;
-slot) # change to slot
checkgravity=1
loadslot=1
slotparm=$2
case "$slotparm" in
[0-9]*)
newslot=$slotparm
if [ $newslot -gt $lastslot ] || \
[ $newslot -lt $firstslot ] ; then
answer=`_ '%s %s: no slot %s: legal range is %s ... %s' "$newslot" "$pname" "$newslot" "$firstslot" "$lastslot"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
fi
;;
current)
newslot=$curslot
;;
first)
newslot=$firstslot
;;
last)
newslot=$lastslot
;;
next|advance)
newslot=`$EXPR $curslot + 1`
if [ $newslot -gt $lastslot ]; then
newslot=$firstslot
fi
if [ $slotparm = advance ]; then
loadslot=0
fi
;;
prev)
newslot=`$EXPR $curslot - 1`
if [ $newslot -lt $firstslot ]; then
newslot=$lastslot
fi
;;
*)
answer=`_ '<none> %s: bad slot name "%s"' "$pname" "$slotparm"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
;;
esac
;;
*)
usage=1
;;
esac
if [ $usage -eq 1 ]; then
answer=`_ '<none> usage: %s {-reset | -slot [<slot-number>|current|next|prev|advance] | -info | -eject}' "$pname"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
# check for legal move
if [ $checkgravity -eq 1 ] && [ $gravity -ne 0 ] ; then
if [ $newslot -lt $curslot ] || [ "$slotparm" = "prev" ] ; then
answer=`_ '%s %s: cannot go backwards in gravity stacker' "$newslot" "$pname"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
fi
fi
# Do the 'mt offline' style of stacker control if applicable
if [ $multieject -eq 1 ] && [ $loadslot -eq 1 ] && [ $newslot -ne $curslot ]
then
# XXX put changer-specific load command here, if applicable
curloaded=0 # unless something goes wrong
slotempty=0
while [ $curslot -ne $newslot ]; do
device=`awk '$1 == "slot" && $2 == '$curslot' {print $3}' $ourconf 2>/dev/null`
if [ "$device" = "" ]; then
answer=`_ '%s %s: slot %s device not specified in %s' "$curslot" "$pname" "$curslot" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
echo `_ ' -> offline'` "$device" >> $logfile
if ! try_eject_device $device; then
answer=`_ '%s %s: %s: unable to change to slot %s' "$newslot" "$pname" "$device" "$curslot"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
[ $ejectdelay -gt 0 ] && sleep $ejectdelay
echo `_ ' -> running'` $posteject $device >> $logfile
$posteject $device >> $logfile 2>&1
status=$?
if [ $status -ne 0 ]; then
answer=`_ '%s %s: %s %s failed: %s' "$newslot" "$pname" "$posteject" "$device" "$status"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
curslot=`$EXPR $curslot + 1`
if [ $curslot -gt $lastslot ] ; then
curslot=$firstslot
fi
done
fi
if [ $ejectonly -eq 1 ] \
|| ([ $needeject -eq 1 ] \
&& [ $loadslot -eq 1 ] \
&& [ $curloaded -eq 1 ] \
&& [ $newslot -ne $curslot ])
then
# XXX put changer-specific load command here, if applicable
curloaded=0 # unless something goes wrong
slotempty=0
# try to unload the current device
device=`awk '$1 == "slot" && $2 == '$curslot' {print $3}' $ourconf 2>/dev/null`
if [ "$device" = "" ]; then
answer=`_ '%s %s: slot %s device not specified in %s' "$curslot" "$pname" "$curslot" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
echo `_ ' -> offline'` $device >> $logfile
try_eject_device $device
if [ $? -ne 0 ]; then
#
# XXX if the changer-specific eject command can distinguish
# betweeen "slot empty" and more serious errors, return 1
# for the first case, 2 for the second case. Generically,
# we just presume an error signifies an empty slot.
#
slotempty=1
else
[ $ejectonly -eq 0 ] && [ $ejectdelay -gt 0 ] && sleep $ejectdelay
echo `_ ' -> running '` $posteject $device >> $logfile
$posteject $device >> $logfile 2>&1
status=$?
if [ $status -ne 0 ]; then
answer=`_ '%s %s: %s %s failed: %s' "$newslot" "$pname" "$posteject" "$device" "$status"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
fi
fi
if [ $loadslot -eq 1 ]; then # load the tape from the slot
# XXX put changer-specific load command here, if applicable
curloaded=1 # unless something goes wrong
slotempty=0
curslot=$newslot
# try to rewind the device
device=`awk '$1 == "slot" && $2 == '$curslot' {print $3}' $ourconf 2>/dev/null`
if [ "$device" = "" ]; then
answer=`_ '%s %s: slot %s device not specified in %s' "$curslot" "$pname" "$curslot" "$ourconf"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 2
fi
amdevcheck_status $device
if [ $? -ne 0 ]; then
#
# XXX if the changer-specific load command can distinguish
# betweeen "slot empty" and more serious errors, return 1
# for the first case, 2 for the second case. Generically,
# we just presume an error signifies an empty slot.
#
slotempty=1
curloaded=0
fi
fi
# update state
echo `_ '# multi-changer state cache: DO NOT EDIT!'` > $ourstate
echo curslot $newslot >> $ourstate
echo curloaded $curloaded >> $ourstate
# return slot info
if [ $slotempty -eq 1 ]; then
answer=`_ '%s %s: slot is empty: %s' "$newslot" "$pname" "$amdevcheck_message"`
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 1
fi
if [ "$command" = -slot -a "$slotparm" = advance ]; then
device=/dev/null
fi
answer="$newslot $device"
echo `_ 'Exit ->'` $answer >> $logfile
echo $answer
exit 0
|