9 # try to hit all the possibilities here
11 exec_prefix=@exec_prefix@
13 libexecdir=@libexecdir@
15 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin
18 if [ -d "@AMANDA_DBGDIR@" ]; then
19 logfile=@AMANDA_DBGDIR@/changer.debug
24 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
25 if test "$USE_VERSION_SUFFIXES" = "yes"; then
33 tape=`amgetconf$SUF tapedev`
34 TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command
35 if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then
36 echo "Both tapedev and changerdev must be specified in config file";
42 if [ -x $sbindir/ammt$SUF ]; then
45 elif [ -x "@MT@" ]; then
49 answer="<none> $myname: mt program not found"
51 echo "Exit -> $answer" >> $logfile
55 echo MT "->" $MT $MTF >> $logfile
57 if [ -x $sbindir/amdd$SUF ]; then
59 elif [ -x "@DD@" ]; then
62 answer="<none> $myname: dd program not found"
64 echo "Exit -> $answer" >> $logfile
68 echo DD "->" $DD >> $logfile
75 changerfile=`amgetconf$SUF changerfile`
77 cleanfile=$changerfile-clean
78 accessfile=$changerfile-access
79 [ ! -f $cleanfile ] && echo 0 > $cleanfile
80 [ ! -f $accessfile ] && echo 0 > $accessfile
81 cleancount=`cat $cleanfile`
82 accesscount=`cat $accessfile`
87 sed -n 's/Drive: No tape Loaded/-1/p;s/Drive: tape \(.\) loaded/\1/p'`
89 if [ -z "$used" ]; then
97 if [ $used -gt 0 ];then
101 echo "Exit -> $answer" >> $logfile
105 answer="<none> $myname: Drive was not loaded"
107 echo "Exit -> $answer" >> $logfile
115 if [ $used -gt 0 ];then
122 echo "Exit -> $answer" >> $logfile
128 echo "Exit -> $answer" >> $logfile
137 echo " -> loaded $used" >> $logfile
141 if [ $used -lt 0 ];then
147 echo "Exit -> $answer" >> $logfile
152 load=`expr $used + 1`
153 [ $load -gt $lastslot ] && load=$firstslot
156 load=`expr $used - 1`
157 [ $load -lt $firstslot ] && load=$lastslot
165 [$firstslot-$lastslot])
172 answer="<none> $myname: illegal request: \"$whichslot\""
174 echo "Exit -> $answer" >> $logfile
180 if [ $load = $used ]; then
183 echo "Exit -> $answer" >> $logfile
188 if [ $load = $cleanslot ]; then
189 expr $cleancount + 1 > $cleanfile
192 expr $accesscount + 1 > $accessfile
193 if [ $accesscount -gt 9 ]; then
194 $myname -slot clean >/dev/null
198 # Slot 6 might contain an ordinary tape rather than a cleaning
199 # tape. A cleaning tape auto-ejects; an ordinary tape does not.
200 # We therefore have to read the status again to check what
205 if [ $used -gt 0 ];then
206 echo " -> unload $used" >> $logfile
209 echo " -> status $status" >> $logfile
210 echo " -> res $res" >> $logfile
211 if [ $status -ne 0 ];then
212 answer="<none> $myname: $res"
214 echo "Exit -> $answer" >> $logfile
219 if [ $whichslot = advance ];then
220 answer="$load /dev/null"
222 echo "Exit -> $answer" >> $logfile
226 echo " -> load $load" >> $logfile
229 echo " -> status $status" >> $logfile
230 echo " -> res $res" >> $logfile
231 if [ $status -eq 0 ];then
232 echo " -> rew $load" >> $logfile
233 $MT $MTF $tape rewind
234 $DD if=$tape bs=32k count=1 >> $logfile 2>&1
241 echo "Exit -> $answer" >> $logfile
248 echo " -> info $used" >> $logfile
249 if [ $used -lt 0 ];then
252 answer="$used $lastslot 1"
254 echo "Exit -> $answer" >> $logfile
259 echo Args "->" "$@" >> $logfile
260 while [ $# -ge 1 ];do
279 answer="<none> $myname: Unknown option $1"
281 echo "Exit -> $answer" >> $logfile