Imported Upstream version 3.1.0
[debian/amanda] / changer-src / chg-rait.sh
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 prefix="@prefix@"
29 exec_prefix="@exec_prefix@"
30 sbindir="@sbindir@"
31 amlibexecdir="@amlibexecdir@"
32 . "${amlibexecdir}/amanda-sh-lib.sh"
33
34 # add sbin and ucb dirs
35 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
36 export PATH
37
38 #
39 # debugging...
40 #
41 if [ -d "@AMANDA_DBGDIR@" ]; then
42         DBGFILE=@AMANDA_DBGDIR@/rait-changer.debug
43         KIDDEBUG=@AMANDA_DBGDIR@/changer.debug
44         WORK=@AMANDA_DBGDIR@/chgwork$$
45 else
46         DBGFILE=/dev/null
47         KIDDEBUG=/dev/null
48         WORK=/tmp/chgwork$$
49 fi
50
51 exec 2>$DBGFILE
52 echo `_ "arguments: "` $0 $* >&2
53 set -x
54
55 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
56 if test "$USE_VERSION_SUFFIXES" = "yes"; then
57         SUF="-@VERSION@";
58 else
59         SUF=
60 fi
61 getconf=$sbindir/amgetconf$SUF
62
63
64 changerfile=`$getconf changerfile`
65 . $changerfile
66
67 #
68 # get config items that other changers use to put in our
69 # fake amanda.conf files.
70 #
71 org=`$getconf ORG`
72 mailto=`$getconf mailto`
73
74 #
75 # make a working directory (with amanda.conf) for each changer, and start the
76 # changer script in background for each one
77 #
78
79 i=1
80 while [ $i -le $nchangers ]
81 do
82    eval tpchanger=\$tpchanger_$i
83    eval changerdev=\$changerdev_$i
84    eval changerfile=\$changerfile_$i
85    eval tapedev=\$tapedev_$i
86
87    mkdir -p $WORK/$i
88    (
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
113     i=`expr $i + 1`
114 done
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-reset|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