#!@SHELL@ # # Exit Status: # 0 Alles Ok # 1 Illegal Request # 2 Fatal Error # # try to hit all the possibilities here prefix=@prefix@ exec_prefix=@exec_prefix@ sbindir=@sbindir@ libexecdir=@libexecdir@ PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin export PATH if [ -d "@AMANDA_DBGDIR@" ]; then logfile=@AMANDA_DBGDIR@/changer.debug else logfile=/dev/null fi USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@" if test "$USE_VERSION_SUFFIXES" = "yes"; then SUF="-@VERSION@" else SUF= fi myname=$0 tape=`amgetconf$SUF tapedev` TAPE=`amgetconf$SUF changerdev`; export TAPE # for mtx command if [ "$tape" = "/dev/null" -o "$TAPE" = "/dev/null" ]; then echo "Both tapedev and changerdev must be specified in config file"; exit 2; fi MTX=@MTX@ if [ -x $sbindir/ammt$SUF ]; then MT=$sbindir/ammt$SUF MTF=-f elif [ -x "@MT@" ]; then MT=@MT@ MTF=@MT_FILE_FLAG@ else answer=" $myname: mt program not found" code=1 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi echo MT "->" $MT $MTF >> $logfile if [ -x $sbindir/amdd$SUF ]; then DD=$sbindir/amdd$SUF elif [ -x "@DD@" ]; then DD=@DD@ else answer=" $myname: dd program not found" code=1 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi echo DD "->" $DD >> $logfile firstslot=1 lastslot=5 # counted from 1 !!! cleanslot=6 changerfile=`amgetconf$SUF changerfile` cleanfile=$changerfile-clean accessfile=$changerfile-access [ ! -f $cleanfile ] && echo 0 > $cleanfile [ ! -f $accessfile ] && echo 0 > $accessfile cleancount=`cat $cleanfile` accesscount=`cat $accessfile` # readstatus() { used=`$MTX -s | sed -n 's/Drive: No tape Loaded/-1/p;s/Drive: tape \(.\) loaded/\1/p'` if [ -z "$used" ]; then used="-1"; fi } eject() { readstatus if [ $used -gt 0 ];then $MTX -u $used answer="0 $tape" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code else answer=" $myname: Drive was not loaded" code=1 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi } reset() { readstatus if [ $used -gt 0 ];then $MTX -u $used fi res=`$MTX -l 1` if [ $? -eq 0 ];then answer="1 $tape" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code else answer="1 $res" code=1 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi } # # loadslot() { readstatus echo " -> loaded $used" >> $logfile whichslot=$1 case $whichslot in current) if [ $used -lt 0 ];then $MTX -l 1 used=1 fi answer="$used $tape" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code ;; next|advance) load=`expr $used + 1` [ $load -gt $lastslot ] && load=$firstslot ;; prev) load=`expr $used - 1` [ $load -lt $firstslot ] && load=$lastslot ;; first) load=$firstslot ;; last) load=$lastslot ;; [$firstslot-$lastslot]) load=$1 ;; clean) load=$cleanslot ;; *) answer=" $myname: illegal request: \"$whichslot\"" code=1 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code ;; esac if [ $load = $used ]; then answer="$used $tape" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi if [ $load = $cleanslot ]; then expr $cleancount + 1 > $cleanfile echo 0 > $accessfile else expr $accesscount + 1 > $accessfile if [ $accesscount -gt 9 ]; then $myname -slot clean >/dev/null fi fi # Slot 6 might contain an ordinary tape rather than a cleaning # tape. A cleaning tape auto-ejects; an ordinary tape does not. # We therefore have to read the status again to check what # actually happened. readstatus if [ $used -gt 0 ];then echo " -> unload $used" >> $logfile res=`$MTX -u $used` status=$? echo " -> status $status" >> $logfile echo " -> res $res" >> $logfile if [ $status -ne 0 ];then answer=" $myname: $res" code=2 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi fi if [ $whichslot = advance ];then answer="$load /dev/null" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code fi echo " -> load $load" >> $logfile res=`$MTX -l $load` status=$? echo " -> status $status" >> $logfile echo " -> res $res" >> $logfile if [ $status -eq 0 ];then echo " -> rew $load" >> $logfile $MT $MTF $tape rewind $DD if=$tape bs=32k count=1 >> $logfile 2>&1 answer="$load $tape" code=0 else answer="$load $res" code=2 fi echo "Exit -> $answer" >> $logfile echo "$answer" exit $code } # info() { readstatus echo " -> info $used" >> $logfile if [ $used -lt 0 ];then used=0 fi answer="$used $lastslot 1" code=0 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code } # echo Args "->" "$@" >> $logfile while [ $# -ge 1 ];do case $1 in -slot) shift loadslot $* ;; -info) shift info ;; -reset) shift reset ;; -eject) shift eject ;; *) answer=" $myname: Unknown option $1" code=2 echo "Exit -> $answer" >> $logfile echo "$answer" exit $code ;; esac done