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 getconf=$sbindir/amgetconf
48 # make sure we can find JUKE later
52 if [ -f /usr/local/etc/setups.sh ]
54 . /usr/local/etc/setups.sh
58 # add sbin, ucb, and the JUKE_DIR to PATH
59 PATH="$PATH:$JUKE_DIR/bin:/usr/sbin:/sbin:/usr/ucb"
64 # figure out which drives are in which jukebox
71 if juke list -j $juke drive $d | grep 'drive [0-9]' >&2
73 eval "drives_in_$juke=\"\$drives_in_$juke $d\""
79 unload_drive_n_clean() {
82 # $1 is whether to clean it
87 # if the drive is ONLINE, mt unload it
89 if amdevcheck_status $tapedev; then
90 try_eject_device $tapedev
94 # unload any tapes present, maybe load/unload a cleaning cartridge
98 eval "jdlist=\"\$drives_in_$juke\""
101 juke unload -j $juke drive $drive >&2 || true
102 if juke list -j $juke drive $drive | grep '(empty)' >&2
106 echo `_ '%s %s unable to empty preceding tape from drive %s' "$slot" "$tapedev" "$drive"`
112 juke load -j $juke drive $drive clean
114 juke unload -j $juke drive $drive
122 # load slots. If it's a stripe, load several...
126 eval "jdlist=\"\$drives_in_$juke\""
127 jndrives=`echo $jdlist | wc -w`
131 rslot=`expr $newslot '*' $jndrives + $count`
132 juke load -j $changerdev drive $drive slot $rslot >&2
133 if juke list -j $changerdev drive $drive | grep '(empty)' >&2
135 echo `_ '$slot $tapedev unable to load tape into drive' "$slot" "$tapedev"`
138 count=`expr $count + 1`
143 # wait for drive(s) to come online
146 until amdevcheck_status $tapedev; do
147 count=`expr $count + 1`
150 echo `_ '%s %s never came online: %s' "$slot" "$tapedev" "$amdevcheck_message"`
158 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$"
161 # get config variables
163 changerfile=`$getconf changerfile`
164 tapedev=`$getconf tapedev`
165 changerdev=`$getconf changerdev`
166 dlist=`csh -c "echo $tapedev" | sed -e 's/rait://g' -e 's/tape://g'`
167 ndrives=`echo $dlist | wc -w`
168 jlist=`csh -c "echo $changerdev"`
169 njukes=`echo $jlist | wc -w`
170 totalslots=`for juke in $jlist ; do juke list -j $juke; done |
175 if [ $ndrives -gt 1 ]
178 # if it's a 3 tape stripe and we have 30 actual slots
179 # we only have 10 virtual slots...
181 totalslots=`expr $totalslots / $ndrives`
187 # get current slot if we have one
189 if [ -f "$changerfile" ]
191 slot="`cat $changerfile`"
194 echo $slot > $changerfile
198 # We treat -reset just like -slot 0
200 if [ x$1 = 'x-reset' ]
211 # handle special slots...
214 current) newslot=$slot ; load=true;;
215 next) newslot=`expr $slot + 1`; load=true;;
216 advance) newslot=`expr $slot + 1`; load=false;;
217 prev) newslot=`expr $slot - 1`; load=true;;
218 first) newslot=0 ; load=true;;
219 last) newslot=-1 ; load=true;;
220 *) newslot=$2 ; load=true;;
223 if [ $newslot = "clean" ]
225 unload_drive_n_clean true
227 if [ 0 -gt $newslot ]
229 newslot=`expr $totalslots - 1`
232 if [ $totalslots -le $newslot ]
237 echo $newslot > $changerfile
242 unload_drive_n_clean false
251 echo $slot $totalslots 1
256 unload_drive_n_clean false