10 exec_prefix=@exec_prefix@
11 amlibexecdir=@amlibexecdir@
12 . ${amlibexecdir}/chg-lib.sh
15 # Changer config file (changerfile)
17 # resend_mail=900 # 15 minutes
18 # timeout_mail=604800 # 7 days
19 # request="tty" # Use the tty to ask the user to change tape.
20 # # Can't be use by cron
21 # request="email" # Send an email to ask the user to change tape.
22 # request="tty_email" # Use the tty if it exist or send an email.
23 # #Default is "tty_email"
24 # mtx_binary="/path/to/mtx" # path of 'mtx'; default is value discovered by
30 if [ -d "@AMANDA_DBGDIR@" ]; then
31 logfile=@AMANDA_DBGDIR@/changer.debug
40 if ! error=`try_find_mt`; then
46 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
47 REPORTTO=`amgetconf mailto`
48 tape=`amgetconf tapedev`
50 if [ -z "$tape" ]; then
51 echo `_ '<none> tapedev not specified in amanda.conf.'`
59 resend_mail=900 # 15 minutes
60 timeout_mail=604800 # 7 days
62 changerfile=`amgetconf changerfile`
64 conf_match=`expr "$changerfile" : .\*\.conf\$`
65 if [ $conf_match -ge 6 ]; then
66 configfile=$changerfile
67 changerfile=`echo $changerfile | sed 's/.conf$//g'`
69 configfile=$changerfile.conf
72 cleanfile=$changerfile-clean
73 accessfile=$changerfile-access
74 slotfile=$changerfile-slot
75 [ ! -f $cleanfile ] && echo 0 > $cleanfile
76 [ ! -f $accessfile ] && echo 0 > $accessfile
77 [ ! -f $slotfile ] && echo $firstslot > $slotfile
78 cleancount=`cat $cleanfile`
79 accesscount=`cat $accessfile`
82 # define these functions early so that they can be overridden in changerfile.conf
86 echo -n `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
87 read ANSWER < /dev/tty
89 echo -n `_ 'no /dev/tty to ask to change tape'`
95 # If $changerfile exists, source it into this script. One reason is to
96 # override the request() function above which gets called to request
97 # that a tape be mounted. Here is an alternate versions of request()
98 # that does things more asynchronous:
101 # Send E-mail about the mount request and wait for the drive
102 # to go ready by checking the status once a minute. Repeat
103 # the E-mail once an hour in case it gets lost.
105 gtimeout=$timeout_mail
107 if [ $gtimeout -le 0 ]; then
108 echo -n `_ 'timeout waiting for tape online'`
111 if [ $timeout -le 0 ]; then
112 msg=`_ 'insert Amanda tape into slot %s (%s)' "$1" "$tape"`
113 subject=`_ '%s AMANDA TAPE MOUNT REQUEST FOR SLOT %s' "$ORG" "$1"`
114 echo "$msg" | $MAILER -s "$subject" $REPORTTO
117 echo `_ ' -> status %s' "$tape"` >> $logfile
118 if amdevcheck_status $tape; then
122 timeout=`expr $timeout - 60`
123 gtimeout=`expr $gtimeout - 60`
127 request_tty_email() {
129 echo -n `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
130 read ANSWER < /dev/tty
137 if [ X"$request" = X"tty" ]; then
139 else if [ X"$request" = X"email" ]; then
142 request_tty_email "$1"
147 # source the changer configuration file (see description, top of file)
148 if [ -f $configfile ]; then
152 # adjust MTX, if necessary
153 test -n "${mtx_binary}" && MTX="${mtx_binary}"
155 # check that MAILER is defined
156 if test -z "$MAILER"; then
157 if test x"$request" = x"email" || test x"$request" = x"tty-email"; then
158 answer=`_ "<none> %s: Can't send email because MAILER is not defined" "$myname"`
159 echo `_ 'Exit ->'` $answer >> $logfile
168 echo `_ ' -> status %s' "$tape"` >> $logfile
169 if amdevcheck_status $tape; then
170 echo `_ ' -> offline %s' "$tape"` >> $logfile
171 try_eject_device $tape
175 answer=`_ '<none> %s: Drive was not loaded' "$myname"`
178 echo `_ 'Exit ->'` $answer >> $logfile
186 echo `_ ' -> status %s' "$tape"` >> $logfile
187 if amdevcheck_status $tape; then
192 echo `_ 'Exit ->'` $answer >> $logfile
200 echo `_ ' -> status %s' "$tape"` >> $logfile
201 # amdevcheck returns zero if the tape exists.
202 amdevcheck_status $tape;
209 [ $load -eq 0 ] && load=$firstslot
210 [ $load -gt $lastslot ] && load=$firstslot
211 [ $load -lt $firstslot ] && load=$lastslot
214 load=`expr $slot + 1`
215 [ $load -gt $lastslot ] && load=$firstslot
218 load=`expr $slot - 1`
219 [ $load -lt $firstslot ] && load=$lastslot
228 if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
229 answer=`_ '<none> %s: slot must be %s .. %s' "$myname" "firstslot" "$lastslot"`
230 echo `_ 'Exit ->'` $answer >> $logfile
237 answer=`_ '<none> %s: illegal slot: %s' "$myname" "$1"`
238 echo `_ 'Exit ->'` $answer >> $logfile
244 if [ $tape_status -eq 0 -a $load = $slot ];then
247 echo `_ 'Exit ->'` $answer >> $logfile
252 expr $accesscount + 1 > $accessfile
254 if [ $tape_status -eq 0 ]; then
255 echo `_ " -> offline %s" "$tape"` >> $logfile
256 try_eject_device $tape
259 if [ $whichslot = advance ]; then
262 echo `_ ' -> load %s' "$load"` >> $logfile
265 echo `_ ' -> status %s' "$tape"` >> $logfile
266 if amdevcheck_status $tape; then
271 echo $load > $slotfile
273 echo `_ 'Exit ->'` $answer >> $logfile
281 echo `_ ' -> status %s' "$tape"` >> $logfile
282 if amdevcheck_status $tape; then
283 answer="$slot $lastslot 1"
285 answer="0 $lastslot 1"
287 echo `_ 'Exit ->'` $answer >> $logfile
296 echo `gettext "args ->"` "$@" >> $logfile
297 while [ $# -ge 1 ];do
316 fmt`gettext "<none> %s: Unknown option %s\n"`
317 printf $fmt $myname $1