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@";
40 if (-x "$sbindir/ammt") {
45 $MTF="@MT_FILE_FLAG@";
47 print "<none> $pname: mt program not found\n";
51 $tapeDevice=`$sbindir/amgetconf tapedev`;
52 die "tapedev not found in amanda.conf"
53 if !$tapeDevice or $tapeDevice eq "" or
54 $tapeDevice =~ m/no such parameter/;
58 if (!sysopen(RTH, $tapeDevice, 2)) {
59 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
62 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
63 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
67 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
71 if (!sysopen(RTH, $tapeDevice, 2)) {
72 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
75 if (sysread(RTH, $status, 136) != 136) {
76 print "$currentTape $pname: error in reading rth status.\n";
80 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
84 @statusBits=unpack("c*",$status);
86 if( ($statusBits[18] == 0x1) || ($statusBits[18]== 0x9)) {
87 return ($statusBits[27]-1);
96 if (!sysopen(RTH, $tapeDevice, 2)) {
97 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
100 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
101 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
105 print "$currentTape $pname: error in closing `$tapeDevice' for getting tpae status: $!\n";
109 if (!sysopen(RTH, $tapeDevice, 2)) {
110 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
113 if (sysread(RTH, $status, 136) != 136) {
114 print "$currentTape $pname: error in reading rth status for tape $currentTape.\n";
118 print "$currentTape $pname: error in closing `$tapeDevice' for getting tape status: $!\n";
122 @statusBits=unpack("c*",$status);
125 for($i=42;$i<187;$i+=16) {
126 if($statusBits[$i] == 0x9) {
127 $slots[$curTape] = 1;
130 $slots[$curTape] = 0;
141 $command = sprintf "GeT%d", $tape;
142 if (!sysopen(RTH, $tapeDevice, 2)) {
143 print "$currentTape $pname: error in opening `$tapeDevice' for loading tape: $!\n";
146 if (syswrite(RTH, $command, 4) != 4) {
147 print "$currentTape $pname: error in loading tape by writing `$command' to `$tapeDevice': $!\n";
151 print "$currentTape $pname: error in closing `$tapeDevice' when trying to load tape: $!\n";
159 $command = sprintf "PuT%d", $tape;
160 if (!sysopen(RTH, $tapeDevice, 2)) {
161 print "$currentTape $pname: error in opening `$tapeDevice' for unloading tape: $!\n";
164 if (syswrite(RTH, $command, 4) != 4) {
165 print "$currentTape $pname: error in unloading tape by writing `$command' to `$tapeDevice': $!\n";
169 print "$currentTape $pname: error in closing `$tapeDevice' when trying to unload tape: $!\n";
177 @slots=getTapeStatus();
179 if($currentTape == $tape) {
183 if($slots[$tape-1] == 0) {
184 print "<none> $pname: no tape in slot requested\n";
188 print $tape," $pname: requested a tape > 6\n";
192 print $tape," $pname: requested a tape < 1\n";
201 if($tape==$currentTape) {
207 if($currentTape==0) {
213 rthUnload($currentTape);
220 $result = &GetOptions("slot=s", "info", "reset", "eject");
222 system($MT, 'rewind');
227 $currentTape=getCurrentTape();
230 if($opt_slot =~ /first/) {
232 print $currentTape, " ", $tapeDevice, "\n";
234 if($opt_slot =~ /last/) {
236 print $currentTape, " ", $tapeDevice, "\n";
238 if($opt_slot =~ /current/) {
239 changeTape($currentTape);
240 print $currentTape, " ", $tapeDevice, "\n";
242 if($opt_slot =~ /next/) {
243 $tape=$currentTape+1;
248 print $currentTape, " ", $tapeDevice,"\n";
250 if($opt_slot =~ /prev/) {
251 $tape=$currentTape-1;
256 print $currentTape, " ", $tapeDevice,"\n";
258 if($opt_slot =~ /\d/) {
259 changeTape($opt_slot);
260 print $currentTape, " ", $tapeDevice,"\n";
262 if($opt_slot =~ /advance/) {
263 $tape=$currentTape+1;
268 rthUnload($currentTape);
270 print $currentTape, " ", "/dev/null","\n";
278 print $currentTape, " 6 1\n";
285 print $currentTape, " ",$tapeDevice,"\n";
291 rthUnload($currentTape);
292 print "0 ",$tapeDevice,"\n";
296 print "0 $pname: drive was not loaded\n";
301 print "$pname: No command was received. Exiting.\n";