Imported Upstream version 2.5.1
[debian/amanda] / changer-src / chg-rait.sh.in
1 #!@SHELL@
2
3 # chg-rait
4 #
5 # This assumes we have rait-striped drives in several
6 # other amanda changer configs.
7 #
8 # so we have a changerfile that lists other changers and
9 # changer files.
10 #   nchangers=3
11 #   tpchanger_1="chg-mtx"
12 #   changerdev_1="/dev/mtx1"
13 #   changerfile_1="/some/file1"
14 #   tapedev_1="/some/dev"
15 #   tpchanger_2="chg-mtx"
16 #   changerdev_2="/dev/mtx2"
17 #   changerfile_2="/some/file2"
18 #   tapedev_2="/some/dev"
19 #   tpchanger_3="chg-mtx"
20 #   changerdev_3="/dev/mtx3"
21 #   changerfile_3="/some/file3"
22 #   tapedev_3="/some/dev"
23 #
24 # the tapedev_n entries are only needed if the changer script in question
25 # uses tapedev.
26 #
27
28 #
29 # debugging...
30 #
31 if [ -d "@AMANDA_DBGDIR@" ]; then
32         DBGFILE=@AMANDA_DBGDIR@/rait-changer.debug
33         KIDDEBUG=@AMANDA_DBGDIR@/changer.debug
34         WORK=@AMANDA_DBGDIR@/chgwork$$
35 else
36         DBGFILE=/dev/null
37         KIDDEBUG=/dev/null
38         WORK=/tmp/chgwork$$
39 fi
40
41 exec 2>$DBGFILE
42 echo "args: $0 $*" >&2
43 set -x 
44
45 #
46 # the usual config fun
47 #
48 prefix=@prefix@
49 exec_prefix=@exec_prefix@
50 sbindir=@sbindir@
51 libexecdir=@libexecdir@
52
53 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
54 if test "$USE_VERSION_SUFFIXES" = "yes"; then
55         SUF="-@VERSION@";
56 else
57         SUF=
58 fi
59 getconf=$sbindir/amgetconf$SUF
60
61
62 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
63 export PATH 
64
65 changerfile=`$getconf changerfile`
66 . $changerfile
67
68 #
69 # get config items that other changers use to put in our
70 # fake amanda.conf files.
71 #
72 org=`$getconf ORG`
73 mailto=`$getconf mailto`
74
75 #
76 # make a working directory (with amanda.conf) for each changer, and start the
77 # changer script in background for each one
78 #
79
80 i=1
81 while [ $i -le $nchangers ]
82 do
83    eval tpchanger=\$tpchanger_$i
84    eval changerdev=\$changerdev_$i
85    eval changerfile=\$changerfile_$i
86    eval tapedev=\$tapedev_$i
87
88    mkdir -p $WORK/$i
89    cd $WORK/$i
90
91    cat >> amanda.conf <<EOF
92 org             "$ORG"
93 mailto          "$mailto"
94 tpchanger       "$tpchanger"
95 changerdev      "$changerdev"
96 changerfile     "$changerfile"
97 tapedev         "$tapedev"
98
99 define tapetype EXABYTE {
100     comment "default tapetype"
101     length 4200 mbytes
102     filemark 48 kbytes
103     speed 474 kbytes                    
104 }
105 EOF
106
107     (
108         $tpchanger "$@"
109         echo "$?"> exitcode 
110     )  > stdout 2>stderr &
111
112    i=`expr $i + 1`
113 done
114
115 wait
116
117 #
118 # once they've all finished, collect up the results
119 #
120
121 myexit=0
122 myslot=-1
123 mymax=65536
124 myflag=1
125 mydev=""
126 mysep="{"
127
128 case x$1 in
129 x-slot|x-reseti|x-eject|x-search|x-label)
130
131     #
132     # read slot number and device from each
133     # slot numbers must match(?!), and is our resulting slot number
134     # resulting device is {dev1,dev2,...} from each one
135     #
136     i=1
137     while [ $i -le $nchangers ]
138     do
139         read exitcode < $WORK/$i/exitcode
140         read n dev < $WORK/$i/stdout
141         echo -------------- >&2
142         cat $WORK/$i/stderr >&2
143         cat $KIDDEBUG >&2
144         echo -------------- >&2
145
146         if [ "$exitcode" != 0 ]
147         then
148             myexit=$exitcode
149         fi
150         if [ $myslot = -1 ]
151         then
152             myslot=$n
153         fi
154         if [ $n != $myslot ]
155         then
156              # synch error!
157             myexit=1
158             echo "stackers are out of synch, issue a reset" >&2
159         fi
160         mydev="$mydev$mysep$dev"
161         mysep=","
162
163         i=`expr $i + 1`
164     done
165     mydev="rait:$mydev}"
166     echo $myslot $mydev
167     ;;
168 x-info)
169     #
170     # read info from each
171     # slot numbers must match(?!), and is our resulting slot number
172     # minimum max slots is our resulting max slots
173     # if any can't go backwards, the aggregate can't either
174     #
175     i=1
176     while [ $i -le $nchangers ]
177     do
178         read exitcode < $WORK/$i/exitcode
179         read n max flag < $WORK/$i/stdout
180         echo -------------- >&2
181         cat $WORK/$i/stderr >&2
182         cat $KIDDEBUG >&2
183         echo -------------- >&2
184
185         if [ "$exitcode" != 0 ]
186         then
187              myexit=$exitcode
188         fi
189         if [ $myslot = -1 ]
190         then
191             myslot=$n
192         fi
193         if [ $n != $myslot ]
194         then
195              # synch error!
196             myexit=1
197             echo "stackers are out of synch, issue a -reset" >&2
198         fi
199         if [ $max -lt $mymax ]
200         then
201             mymax=$max
202         fi
203         if [ $flag = 0 ]
204         then
205             myflag=0
206         fi
207         i=`expr $i + 1`
208     done
209     echo $myslot $mymax $myflag
210
211 esac
212
213 #
214 # clean up work directories
215 #
216 rm -rf $WORK
217
218 exit $myexit