Imported Upstream version 2.5.1
[debian/amanda] / changer-src / chg-null.sh.in
1 #!@SHELL@ 
2 #
3 # Exit Status:
4 # 0 Alles Ok
5 # 1 Illegal Request
6 # 2 Fatal Error
7 #
8
9 # try to hit all the possibilities here
10 prefix=@prefix@
11 exec_prefix=@exec_prefix@
12 sbindir=@sbindir@
13 libexecdir=@libexecdir@
14 debugdir=@AMANDA_DEBUGDIR@
15
16 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
17 export PATH
18
19 if [ -d "$debugdir" ]
20 then
21         logfile=$debugdir/changer.debug
22 else
23         logfile=/dev/null
24 fi
25 exec 2> $logfile
26 set -x
27
28 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
29 if test "$USE_VERSION_SUFFIXES" = "yes"; then
30         SUF="-@VERSION@"
31 else
32         SUF=
33 fi
34
35 myname=$0
36
37 EGREP='@EGREP@'
38
39 firstslot=1
40 totalslots=200
41
42 changerfile=`amgetconf$SUF changerfile`
43
44 tapedev="null:/dev/xxx$$"
45
46 cleanfile=$changerfile-clean
47 accessfile=$changerfile-access
48 slotfile=$changerfile-slot
49 [ ! -f $cleanfile ] && echo 0 > $cleanfile
50 [ ! -f $accessfile ] && echo 0 > $accessfile
51 [ ! -f $slotfile ] && echo $firstslot > $slotfile
52 cleancount=`cat $cleanfile`
53 accesscount=`cat $accessfile`
54 slot=`cat $slotfile`
55
56 rc=0
57
58 case x$1 in
59
60 x-slot) 
61
62     #
63     # handle special slots...
64     #
65     case "$2" in
66     current)    newslot=$slot           ; load=true;;
67     next)       newslot=`expr $slot + 1`; load=true;;
68     advance)    newslot=`expr $slot + 1`; load=false;;
69     prev)       newslot=`expr $slot - 1`; load=true;;
70     first)      newslot=0               ; load=true;;
71     last)       newslot=-1              ; load=true;;
72     *)          newslot=$2              ; load=true;;
73     esac
74
75     if [ 0 -gt $newslot ]
76     then
77         newslot=`expr $totalslots - 1`
78     fi
79
80     if [ $totalslots -le  $newslot ]
81     then
82         newslot=0
83     fi
84     echo $newslot > $changerfile-slot
85     slot=$newslot
86     echo $slot $tapedev
87     ;;
88
89 x-info)
90     echo $slot $totalslots 1
91     ;;
92
93 x-eject)
94     echo $slot $tapedev
95     ;;
96 esac
97
98 exit $rc