5 # This assumes we have possibly rait-striped drives in several
6 # jukeboxes, controlled by the Fermilab "juke" package
8 # So we could have 3 drives in 3 jukeboxes:
9 # changerscript="chg-juke"
10 # changerfile=/some/file
11 # tapedev="rait:/dev/nst{1,2,3}"
12 # changerdev="myjuke{0,1,2}"
13 # Or, if the jukebox has multiple drives:
14 # changerscript="chg-juke"
15 # changerfile=/some/file
16 # tapedev="rait:/dev/nst{1,2,3}"
18 # We need therefore to generate lists with csh to expand the tapedev
19 # and changerdev, and deal with the possibility that there are several
20 # jukeboxes and several drives in each jukebox involved.
23 exec_prefix="@exec_prefix@"
25 amlibexecdir="@amlibexecdir@"
26 . "${amlibexecdir}/amanda-sh-lib.sh"
32 if [ -d "@AMANDA_DBGDIR@" ]; then
33 DBGFILE=@AMANDA_DBGDIR@/changer.debug
38 echo `_ 'args:'` $0 $* >&2
42 # the usual config fun
45 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
46 if test "$USE_VERSION_SUFFIXES" = "yes"; then
51 getconf=$sbindir/amgetconf$SUF
54 # make sure we can find JUKE later
58 if [ -f /usr/local/etc/setups.sh ]
60 . /usr/local/etc/setups.sh
64 # add sbin, ucb, and the JUKE_DIR to PATH
65 PATH="$PATH:$JUKE_DIR/bin:/usr/sbin:/sbin:/usr/ucb"
70 # figure out which drives are in which jukebox
77 if juke list -j $juke drive $d | grep 'drive [0-9]' >&2
79 eval "drives_in_$juke=\"\$drives_in_$juke $d\""
85 unload_drive_n_clean() {
88 # $1 is whether to clean it
93 # if the drive is ONLINE, mt unload it
95 if amdevcheck_status $tapedev; then
96 try_eject_device $tapedev
100 # unload any tapes present, maybe load/unload a cleaning cartridge
104 eval "jdlist=\"\$drives_in_$juke\""
107 juke unload -j $juke drive $drive >&2 || true
108 if juke list -j $juke drive $drive | grep '(empty)' >&2
112 echo `_ '%s %s unable to empty preceding tape from drive %s' "$slot" "$tapedev" "$drive"`
118 juke load -j $juke drive $drive clean
120 juke unload -j $juke drive $drive
128 # load slots. If it's a stripe, load several...
132 eval "jdlist=\"\$drives_in_$juke\""
133 jndrives=`echo $jdlist | wc -w`
137 rslot=`expr $newslot '*' $jndrives + $count`
138 juke load -j $changerdev drive $drive slot $rslot >&2
139 if juke list -j $changerdev drive $drive | grep '(empty)' >&2
141 echo `_ '$slot $tapedev unable to load tape into drive' "$slot" "$tapedev"`
144 count=`expr $count + 1`
149 # wait for drive(s) to come online
152 until amdevcheck_status $tapedev; do
153 count=`expr $count + 1`
156 echo `_ '%s %s never came online: %s' "$slot" "$tapedev" "$amdevcheck_message"`
164 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$"
167 # get config variables
169 changerfile=`$getconf changerfile`
170 tapedev=`$getconf tapedev`
171 changerdev=`$getconf changerdev`
172 dlist=`csh -c "echo $tapedev" | sed -e 's/rait://g' -e 's/tape://g'`
173 ndrives=`echo $dlist | wc -w`
174 jlist=`csh -c "echo $changerdev"`
175 njukes=`echo $jlist | wc -w`
176 totalslots=`for juke in $jlist ; do juke list -j $juke; done |
181 if [ $ndrives -gt 1 ]
184 # if it's a 3 tape stripe and we have 30 actual slots
185 # we only have 10 virtual slots...
187 totalslots=`expr $totalslots / $ndrives`
193 # get current slot if we have one
195 if [ -f "$changerfile" ]
197 slot="`cat $changerfile`"
200 echo $slot > $changerfile
204 # We treat -reset just like -slot 0
206 if [ x$1 = 'x-reset' ]
217 # handle special slots...
220 current) newslot=$slot ; load=true;;
221 next) newslot=`expr $slot + 1`; load=true;;
222 advance) newslot=`expr $slot + 1`; load=false;;
223 prev) newslot=`expr $slot - 1`; load=true;;
224 first) newslot=0 ; load=true;;
225 last) newslot=-1 ; load=true;;
226 *) newslot=$2 ; load=true;;
229 if [ $newslot = "clean" ]
231 unload_drive_n_clean true
233 if [ 0 -gt $newslot ]
235 newslot=`expr $totalslots - 1`
238 if [ $totalslots -le $newslot ]
243 echo $newslot > $changerfile
248 unload_drive_n_clean false
257 echo $slot $totalslots 1
262 unload_drive_n_clean false