3 # Catch for sh/csh on systems without #! ability.
4 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
5 & eval 'exec @PERL@ -S $0 $argv:q'
9 # A tape changer script for the Robotic Tape Handling system OEM'd
10 # by Andataco (RTH-406) for use with Amanda, the Advanced Maryland
11 # Network Disk Archiver.
13 # Author: Erik Frederick 1/10/97
14 # edf@tyrell.mc.duke.edu
16 # This changer script controls the HP c1553 tape drive via a
17 # Peripheral Vision Inc. SCSI control subsystem that interprets
18 # commands sent on the SCSI bus. It may work with other tape drives
19 # containing the PVI board.
21 # Permission to freely use and distribute is granted.
28 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
29 $ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
31 $pname = "rth-changer";
34 $prefix=$prefix; # avoid warnings about possible typo
35 $exec_prefix="@exec_prefix@";
36 $exec_prefix=$exec_prefix; # ditto
38 $amlibexecdir="@amlibexecdir@";
39 if ("@USE_VERSION_SUFFIXES@" eq "yes") {
45 if (-x "$sbindir/ammt$SUF") {
46 $MT="$sbindir/ammt$SUF";
50 $MTF="@MT_FILE_FLAG@";
52 print "<none> $pname: mt program not found\n";
56 $tapeDevice=`$sbindir/amgetconf$SUF tapedev`;
57 die "tapedev not found in amanda.conf"
58 if !$tapeDevice or $tapeDevice eq "" or
59 $tapeDevice =~ m/no such parameter/;
63 if (!sysopen(RTH, $tapeDevice, 2)) {
64 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
67 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
68 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
72 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
76 if (!sysopen(RTH, $tapeDevice, 2)) {
77 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
80 if (sysread(RTH, $status, 136) != 136) {
81 print "$currentTape $pname: error in reading rth status.\n";
85 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
89 @statusBits=unpack("c*",$status);
91 if( ($statusBits[18] == 0x1) || ($statusBits[18]== 0x9)) {
92 return ($statusBits[27]-1);
101 if (!sysopen(RTH, $tapeDevice, 2)) {
102 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
105 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
106 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
110 print "$currentTape $pname: error in closing `$tapeDevice' for getting tpae status: $!\n";
114 if (!sysopen(RTH, $tapeDevice, 2)) {
115 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
118 if (sysread(RTH, $status, 136) != 136) {
119 print "$currentTape $pname: error in reading rth status for tape $currentTape.\n";
123 print "$currentTape $pname: error in closing `$tapeDevice' for getting tape status: $!\n";
127 @statusBits=unpack("c*",$status);
130 for($i=42;$i<187;$i+=16) {
131 if($statusBits[$i] == 0x9) {
132 $slots[$curTape] = 1;
135 $slots[$curTape] = 0;
146 $command = sprintf "GeT%d", $tape;
147 if (!sysopen(RTH, $tapeDevice, 2)) {
148 print "$currentTape $pname: error in opening `$tapeDevice' for loading tape: $!\n";
151 if (syswrite(RTH, $command, 4) != 4) {
152 print "$currentTape $pname: error in loading tape by writing `$command' to `$tapeDevice': $!\n";
156 print "$currentTape $pname: error in closing `$tapeDevice' when trying to load tape: $!\n";
164 $command = sprintf "PuT%d", $tape;
165 if (!sysopen(RTH, $tapeDevice, 2)) {
166 print "$currentTape $pname: error in opening `$tapeDevice' for unloading tape: $!\n";
169 if (syswrite(RTH, $command, 4) != 4) {
170 print "$currentTape $pname: error in unloading tape by writing `$command' to `$tapeDevice': $!\n";
174 print "$currentTape $pname: error in closing `$tapeDevice' when trying to unload tape: $!\n";
182 @slots=getTapeStatus();
184 if($currentTape == $tape) {
188 if($slots[$tape-1] == 0) {
189 print "<none> $pname: no tape in slot requested\n";
193 print $tape," $pname: requested a tape > 6\n";
197 print $tape," $pname: requested a tape < 1\n";
206 if($tape==$currentTape) {
212 if($currentTape==0) {
218 rthUnload($currentTape);
225 $result = &GetOptions("slot=s", "info", "reset", "eject");
227 system($MT, 'rewind');
232 $currentTape=getCurrentTape();
235 if($opt_slot =~ /first/) {
237 print $currentTape, " ", $tapeDevice, "\n";
239 if($opt_slot =~ /last/) {
241 print $currentTape, " ", $tapeDevice, "\n";
243 if($opt_slot =~ /current/) {
244 changeTape($currentTape);
245 print $currentTape, " ", $tapeDevice, "\n";
247 if($opt_slot =~ /next/) {
248 $tape=$currentTape+1;
253 print $currentTape, " ", $tapeDevice,"\n";
255 if($opt_slot =~ /prev/) {
256 $tape=$currentTape-1;
261 print $currentTape, " ", $tapeDevice,"\n";
263 if($opt_slot =~ /\d/) {
264 changeTape($opt_slot);
265 print $currentTape, " ", $tapeDevice,"\n";
267 if($opt_slot =~ /advance/) {
268 $tape=$currentTape+1;
273 rthUnload($currentTape);
275 print $currentTape, " ", "/dev/null","\n";
283 print $currentTape, " 6 1\n";
290 print $currentTape, " ",$tapeDevice,"\n";
296 rthUnload($currentTape);
297 print "0 ",$tapeDevice,"\n";
301 print "0 $pname: drive was not loaded\n";
306 print "$pname: No command was received. Exiting.\n";