Imported Upstream version 2.6.1
[debian/amanda] / changer-src / chg-manual.sh
index d480de976568da4a95e6d59f802ed1bb68837542..1490a4d7a345aa2e54c2e503e5ddcbe45ad4f29d 100644 (file)
@@ -26,14 +26,13 @@ amlibexecdir=@amlibexecdir@
 #
 #
 
-
 if [ -d "@AMANDA_DBGDIR@" ]; then
        logfile=@AMANDA_DBGDIR@/changer.debug
 else
        logfile=/dev/null
 fi
 
-myname=$0
+myname=`basename $0`
 
 EGREP='@EGREP@'
 
@@ -42,9 +41,9 @@ if ! error=`try_find_mt`; then
     exit 2
 fi
 
-MAILER=@MAILER@
 ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
 REPORTTO=`amgetconf mailto`
+MAILER=`amgetconf mailer`
 tape=`amgetconf tapedev`
 
 if [ -z "$tape" ]; then
@@ -58,6 +57,8 @@ firstslot=1
 lastslot=99
 resend_mail=900                # 15 minutes
 timeout_mail=604800    # 7 days
+abort_file="chg-manual.abort"
+abort_dir=`pwd`
 
 changerfile=`amgetconf changerfile`
 
@@ -83,11 +84,23 @@ slot=`cat $slotfile`
 
 request_tty() {
        if > /dev/tty; then
-               echo -n `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
+               echo "$amdevcheck_message" >> /dev/tty
+               # message parsed by ZMC:
+               echo `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
+               echo `_ ' or type "NONE" to abort'` > /dev/tty
                read ANSWER < /dev/tty
+               if [ X"$ANSWER" = X"NONE" ]; then
+                       echo `_ 'Aborting request'` > /dev/tty
+                       answer=`_ '<none> Aborting request'`
+                       echo `_ 'Exit ->'` $answer >> $logfile
+                       echo $answer
+                       exit 2
+               fi
        else
-               echo -n `_ 'no /dev/tty to ask to change tape'`
-               exit 1
+               answer=`_ '<none> no /dev/tty to ask to change tape'`
+               echo `_ 'Exit ->'` $answer >> $logfile
+               echo $answer
+               exit 2
        fi
 }
 
@@ -103,13 +116,23 @@ request_email() {
        # the E-mail once an hour in case it gets lost.
        timeout=0
        gtimeout=$timeout_mail
+       rm -f $abort_filename
        while true;do
            if [ $gtimeout -le 0 ]; then
-               echo -n `_ 'timeout waiting for tape online'`
-               exit 1;
+               answer=`_ '%s %s: timeout waiting for tape online' "$load" "$myname"`
+               echo `_ 'Exit ->'` $answer >> $logfile
+               echo $answer
+               exit 2;
+           fi
+           if [ -f $abort_filename ]; then
+               rm -f $abort_filename
+               answer=`_ '<none> Aborting request'`
+               echo `_ 'Exit ->'` $answer >> $logfile
+               echo $answer
+               exit 2
            fi
            if [ $timeout -le 0 ]; then
-               msg=`_ 'insert Amanda tape into slot %s (%s)' "$1" "$tape"`
+               msg=`_ '%s\nInsert Amanda tape into slot %s (%s)\nor \`touch %s\` to abort.' "$amdevcheck_message" "$1" "$tape" "$abort_filename"` 
                subject=`_ '%s AMANDA TAPE MOUNT REQUEST FOR SLOT %s' "$ORG" "$1"`
                echo "$msg" | $MAILER -s "$subject" $REPORTTO
                timeout=$resend_mail
@@ -126,8 +149,7 @@ request_email() {
 
 request_tty_email() {
        if > /dev/tty; then
-               echo -n `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
-               read ANSWER < /dev/tty
+               request_tty "$1"
        else
                request_email "$1"
        fi
@@ -158,7 +180,7 @@ if test -z "$MAILER"; then
        answer=`_ "<none> %s: Can't send email because MAILER is not defined" "$myname"`
        echo `_ 'Exit ->'` $answer >> $logfile
        echo $answer
-       exit 1
+       exit 2
     fi
 fi
 
@@ -172,7 +194,7 @@ eject() {
            answer="$slot $tape"
            code=0
        else
-           answer=`_ '<none> %s: Drive was not loaded' "$myname"`
+           answer=`_ '<none> %s: %s' "$myname" "$amdevcheck_message"`
            code=1
        fi
        echo `_ 'Exit ->'` $answer >> $logfile
@@ -180,6 +202,8 @@ eject() {
        exit $code
 }
 
+abort_filename="$abort_dir/$abort_file"
+
 #
 
 reset() {
@@ -187,7 +211,7 @@ reset() {
         if amdevcheck_status $tape; then
                answer="$slot $tape"
        else
-               answer="0 $tape"
+               answer="0 $tape $amdevcheck_message"
        fi
        echo `_ 'Exit ->'` $answer >> $logfile
        echo $answer
@@ -206,9 +230,6 @@ loadslot() {
        case $whichslot in
        current)
                load=$slot
-               [ $load -eq 0 ] && load=$firstslot
-               [ $load -gt $lastslot ] && load=$firstslot
-               [ $load -lt $firstslot ] && load=$lastslot
                ;;
        next|advance)
                load=`expr $slot + 1`
@@ -249,6 +270,13 @@ loadslot() {
                exit 0
        fi
 
+       if [ X"$whichslot" = X"current" ]; then
+               answer="<none> Current slot not loaded"
+               echo `_ 'Exit ->'` $answer>> $logfile
+               echo $answer
+               exit 1
+       fi
+
        expr $accesscount + 1 > $accessfile
 
        if [ $tape_status -eq 0 ]; then
@@ -313,7 +341,7 @@ while [ $# -ge 1 ];do
                eject
                ;;
        *)
-               fmt`gettext "<none> %s: Unknown option %s\n"`
+               fmt=`gettext "<none> %s: Unknown option %s\n"`
                printf $fmt $myname $1
                exit 2
                ;;