Imported Upstream version 3.1.0
[debian/amanda] / changer-src / chg-null.sh
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 amlibexecdir="@amlibexecdir@"
14 . "${amlibexecdir}/amanda-sh-lib.sh"
15
16 debugdir=@AMANDA_DBGDIR@
17
18 # add sbin and ucb dirs
19 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
20 export PATH
21
22 if [ -d "$debugdir" ]
23 then
24         logfile=$debugdir/changer.debug
25 else
26         logfile=/dev/null
27 fi
28 exec 2> $logfile
29 set -x
30
31 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
32 if test "$USE_VERSION_SUFFIXES" = "yes"; then
33         SUF="-@VERSION@"
34 else
35         SUF=
36 fi
37
38 myname=$0
39
40 EGREP='@EGREP@'
41
42 firstslot=1
43 totalslots=200
44
45 changerfile=`amgetconf$SUF changerfile`
46
47 tapedev="null:/dev/xxx$$"
48
49 cleanfile=$changerfile-clean
50 accessfile=$changerfile-access
51 slotfile=$changerfile-slot
52 [ ! -f $cleanfile ] && echo 0 > $cleanfile
53 [ ! -f $accessfile ] && echo 0 > $accessfile
54 [ ! -f $slotfile ] && echo $firstslot > $slotfile
55 cleancount=`cat $cleanfile`
56 accesscount=`cat $accessfile`
57 slot=`cat $slotfile`
58
59 rc=0
60
61 case x$1 in
62
63 x-slot)
64
65     #
66     # handle special slots...
67     #
68     case "$2" in
69     current)    newslot=$slot           ; load=true;;
70     next)       newslot=`expr $slot + 1`; load=true;;
71     advance)    newslot=`expr $slot + 1`; load=false;;
72     prev)       newslot=`expr $slot - 1`; load=true;;
73     first)      newslot=0               ; load=true;;
74     last)       newslot=-1              ; load=true;;
75     *)          newslot=$2              ; load=true;;
76     esac
77
78     if [ 0 -gt $newslot ]
79     then
80         newslot=`expr $totalslots - 1`
81     fi
82
83     if [ $totalslots -le  $newslot ]
84     then
85         newslot=0
86     fi
87     echo $newslot > $changerfile-slot
88     slot=$newslot
89     echo $slot $tapedev
90     ;;
91
92 x-info)
93     echo $slot $totalslots 1
94     ;;
95
96 x-eject)
97     echo $slot $tapedev
98     ;;
99 esac
100
101 exit $rc