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.
25 if [ -d "@AMANDA_DBGDIR@" ]; then
26 DBGFILE=@AMANDA_DBGDIR@/changer.debug
31 echo "args: $0 $*" >&2
35 # the usual config fun
38 exec_prefix=@exec_prefix@
40 libexecdir=@libexecdir@
43 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
44 if test "$USE_VERSION_SUFFIXES" = "yes"; then
49 getconf=$sbindir/amgetconf$SUF
52 # make sure we can find JUKE later
56 if [ -f /usr/local/etc/setups.sh ]
58 . /usr/local/etc/setups.sh
62 PATH=$sbindir:$libexecdir:$JUKE_DIR/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
67 # figure out which drives are in which jukebox
74 if juke list -j $juke drive $d | grep 'drive [0-9]' >&2
76 eval "drives_in_$juke=\"\$drives_in_$juke $d\""
82 unload_drive_n_clean() {
85 # $1 is whether to clean it
90 # if the drive is ONLINE, mt unload it
92 if $MT -t $tapedev status | egrep "$ONLINEREGEX" >&2
94 $MT -t $tapedev offline >&2 || true
98 # unload any tapes present, maybe load/unload a cleaning cartridge
102 eval "jdlist=\"\$drives_in_$juke\""
105 juke unload -j $juke drive $drive >&2 || true
106 if juke list -j $juke drive $drive | grep '(empty)' >&2
110 echo "$slot $tapedev unable to empty preceding tape from drive $drive"
116 juke load -j $juke drive $drive clean
118 juke unload -j $juke drive $drive
126 # load slots. If it's a stripe, load several...
130 eval "jdlist=\"\$drives_in_$juke\""
131 jndrives=`echo $jdlist | wc -w`
135 rslot=`expr $newslot '*' $jndrives + $count`
136 juke load -j $changerdev drive $drive slot $rslot >&2
137 if juke list -j $changerdev drive $drive | grep '(empty)' >&2
139 echo "$slot $tapedev unable to load tape into drive"
142 count=`expr $count + 1`
147 # wait for drive(s) to come online
150 until $MT -t $tapedev status | egrep "$ONLINEREGEX" >&2
152 count=`expr $count + 1`
155 echo "$slot $tapedev never came online"
163 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$"
166 # get config variables
168 changerfile=`$getconf changerfile`
169 tapedev=`$getconf tapedev`
170 changerdev=`$getconf changerdev`
171 dlist=`csh -c "echo $tapedev" | sed -e 's/rait://g' -e 's/tape://g'`
172 ndrives=`echo $dlist | wc -w`
173 jlist=`csh -c "echo $changerdev"`
174 njukes=`echo $jlist | wc -w`
175 totalslots=`for juke in $jlist ; do juke list -j $juke; done |
180 if [ $ndrives -gt 1 ]
183 # if it's a 3 tape stripe and we have 30 actual slots
184 # we only have 10 virtual slots...
186 totalslots=`expr $totalslots / $ndrives`
192 # get current slot if we have one
194 if [ -f "$changerfile" ]
196 slot="`cat $changerfile`"
199 echo $slot > $changerfile
203 # We treat -reset just like -slot 0
205 if [ x$1 = 'x-reset' ]
216 # handle special slots...
219 current) newslot=$slot ; load=true;;
220 next) newslot=`expr $slot + 1`; load=true;;
221 advance) newslot=`expr $slot + 1`; load=false;;
222 prev) newslot=`expr $slot - 1`; load=true;;
223 first) newslot=0 ; load=true;;
224 last) newslot=-1 ; load=true;;
225 *) newslot=$2 ; load=true;;
228 if [ $newslot = "clean" ]
230 unload_drive_n_clean true
232 if [ 0 -gt $newslot ]
234 newslot=`expr $totalslots - 1`
237 if [ $totalslots -le $newslot ]
242 echo $newslot > $changerfile
247 unload_drive_n_clean false
256 echo $slot $totalslots 1
261 unload_drive_n_clean false