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
29 if [ -d "@AMANDA_DBGDIR@" ]; then
30 logfile=@AMANDA_DBGDIR@/changer.debug
39 if ! error=`try_find_mt`; then
44 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
45 REPORTTO=`amgetconf mailto`
46 MAILER=`amgetconf mailer`
47 tape=`amgetconf tapedev`
49 if [ -z "$tape" ]; then
50 echo `_ '<none> tapedev not specified in amanda.conf.'`
58 resend_mail=900 # 15 minutes
59 timeout_mail=604800 # 7 days
60 abort_file="chg-manual.abort"
63 changerfile=`amgetconf changerfile`
65 conf_match=`expr "$changerfile" : .\*\.conf\$`
66 if [ $conf_match -ge 6 ]; then
67 configfile=$changerfile
68 changerfile=`echo $changerfile | sed 's/.conf$//g'`
70 configfile=$changerfile.conf
73 cleanfile=$changerfile-clean
74 accessfile=$changerfile-access
75 slotfile=$changerfile-slot
76 [ ! -f $cleanfile ] && echo 0 > $cleanfile
77 [ ! -f $accessfile ] && echo 0 > $accessfile
78 [ ! -f $slotfile ] && echo $firstslot > $slotfile
79 cleancount=`cat $cleanfile`
80 accesscount=`cat $accessfile`
83 # define these functions early so that they can be overridden in changerfile.conf
87 echo "$amdevcheck_message" >> /dev/tty
88 # message parsed by ZMC:
89 echo `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
90 echo `_ ' or type "NONE" to abort'` > /dev/tty
91 read ANSWER < /dev/tty
92 if [ X"$ANSWER" = X"NONE" ]; then
93 echo `_ 'Aborting by user request'` > /dev/tty
94 answer=`_ '<none> Aborting by user request'`
95 echo `_ 'Exit ->'` $answer >> $logfile
100 answer=`_ '<none> no /dev/tty to ask to change tape'`
101 echo `_ 'Exit ->'` $answer >> $logfile
108 # If $changerfile exists, source it into this script. One reason is to
109 # override the request() function above which gets called to request
110 # that a tape be mounted. Here is an alternate versions of request()
111 # that does things more asynchronous:
114 # Send E-mail about the mount request and wait for the drive
115 # to go ready by checking the status once a minute. Repeat
116 # the E-mail once an hour in case it gets lost.
118 gtimeout=$timeout_mail
119 rm -f $abort_filename
121 if [ $gtimeout -le 0 ]; then
122 answer=`_ '%s %s: timeout waiting for tape online' "$load" "$myname"`
123 echo `_ 'Exit ->'` $answer >> $logfile
127 if [ -f $abort_filename ]; then
128 rm -f $abort_filename
129 answer=`_ '<none> Aborting by user request'`
130 echo `_ 'Exit ->'` $answer >> $logfile
134 if [ $timeout -le 0 ]; then
135 msg=`_ '%s\nInsert Amanda tape into slot %s (%s)\nor \`touch %s\` to abort.' "$amdevcheck_message" "$1" "$tape" "$abort_filename"`
136 subject=`_ '%s AMANDA TAPE MOUNT REQUEST FOR SLOT %s' "$ORG" "$1"`
137 echo "$msg" | $MAILER -s "$subject" $REPORTTO
140 echo `_ ' -> status %s' "$tape"` >> $logfile
141 if amdevcheck_status $tape; then
145 timeout=`expr $timeout - 60`
146 gtimeout=`expr $gtimeout - 60`
150 request_tty_email() {
159 if [ X"$request" = X"tty" ]; then
161 else if [ X"$request" = X"email" ]; then
164 request_tty_email "$1"
169 # source the changer configuration file (see description, top of file)
170 if [ -f $configfile ]; then
174 # adjust MTX, if necessary
175 test -n "${mtx_binary}" && MTX="${mtx_binary}"
177 # check that MAILER is defined
178 if test -z "$MAILER"; then
179 if test x"$request" = x"email" || test x"$request" = x"tty-email"; then
180 answer=`_ "<none> %s: Can't send email because MAILER is not defined" "$myname"`
181 echo `_ 'Exit ->'` $answer >> $logfile
190 echo `_ ' -> status %s' "$tape"` >> $logfile
191 if amdevcheck_status $tape; then
192 echo `_ ' -> offline %s' "$tape"` >> $logfile
193 try_eject_device $tape
197 answer=`_ '<none> %s: %s' "$myname" "$amdevcheck_message"`
200 echo `_ 'Exit ->'` $answer >> $logfile
205 abort_filename="$abort_dir/$abort_file"
210 echo `_ ' -> status %s' "$tape"` >> $logfile
211 if amdevcheck_status $tape; then
214 answer="0 $tape $amdevcheck_message"
216 echo `_ 'Exit ->'` $answer >> $logfile
224 echo `_ ' -> status %s' "$tape"` >> $logfile
225 # amdevcheck returns zero if the tape exists.
226 amdevcheck_status $tape;
235 load=`expr $slot + 1`
236 [ $load -gt $lastslot ] && load=$firstslot
239 load=`expr $slot - 1`
240 [ $load -lt $firstslot ] && load=$lastslot
249 if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
250 answer=`_ '<none> %s: slot must be %s .. %s' "$myname" "firstslot" "$lastslot"`
251 echo `_ 'Exit ->'` $answer >> $logfile
258 answer=`_ '<none> %s: illegal slot: %s' "$myname" "$1"`
259 echo `_ 'Exit ->'` $answer >> $logfile
265 if [ $tape_status -eq 0 -a $load = $slot ];then
268 echo `_ 'Exit ->'` $answer >> $logfile
273 if [ X"$whichslot" = X"current" ]; then
274 answer="<none> Current slot not loaded"
275 echo `_ 'Exit ->'` $answer>> $logfile
280 expr $accesscount + 1 > $accessfile
282 if [ $tape_status -eq 0 ]; then
283 echo `_ " -> offline %s" "$tape"` >> $logfile
284 try_eject_device $tape
287 if [ $whichslot = advance ]; then
290 echo `_ ' -> load %s' "$load"` >> $logfile
293 echo `_ ' -> status %s' "$tape"` >> $logfile
294 if amdevcheck_status $tape; then
299 echo $load > $slotfile
301 echo `_ 'Exit ->'` $answer >> $logfile
309 echo `_ ' -> status %s' "$tape"` >> $logfile
310 if amdevcheck_status $tape; then
311 answer="$slot $lastslot 1"
313 answer="0 $lastslot 1"
315 echo `_ 'Exit ->'` $answer >> $logfile
324 echo `gettext "args ->"` "$@" >> $logfile
325 while [ $# -ge 1 ];do
344 fmt=`gettext "<none> %s: Unknown option %s\n"`
345 printf $fmt $myname $1