#!/bin/bash ################################################################### # #Copyright (c) 2007, Harald Schioeberg # #All rights reserved # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions #are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR #CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, #PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # #################################################################### source `amgetconf changerfile` #CONFIGS='Daily Weekly' #CONFSTAT='/tmp/confstat' if [ -z "$CONFIGS" ]; then echo "Please configure multiplex correctly" exit 1 fi echo $CONFSTAT CHGDIR=`dirname $0` CONFDIR=$cwd if [ -f $CONFSTAT ]; then read CURRENTCONF < $CONFSTAT; else CURRENTCONF=( $CONFIGS ) fi total_slots=0 go_back=1 has_label=1 for conf in $CONFIGS; do cd ../$conf read curslot_${conf} numslots_${conf} canback_${conf} cansearch_${conf} < <( $CHGDIR/`amgetconf $conf tpchanger` -info) eval canback=\$canback_${conf} if [ $canback -ne 1 ]; then go_back=0 fi eval slotoffset_${conf}=$total_slots eval total_slots=\$\(\( $total_slots + \$numslots_${conf} \)\) labelstr=`amgetconf $conf labelstr` eval labelstr_${conf}=\"$labelstr\" done case $1 in -info) eval cur_off=\$slotoffset_${CURRENTCONF} eval cur_slot=\$curslot_${CURRENTCONF} eval echo $(( $cur_off + $cur_slot )) $total_slots $go_back $has_label exit 0 ;; -slot) slotnum=$2 case $2 in [0-9]*) for conf in $CONFIGS; do eval conf_off=\$slotoffset_${conf} if [ $conf_off -ge $slotnum ]; then break; fi config=$conf done eval conf_off=\$slotoffset_${config} echo $config > $CONFSTAT local_slot=$(($slotnum - $conf_off)) cd ../$config $CHGDIR/`amgetconf $config tpchanger` -slot $local_slot exit $? ;; *) cd ../$CURRENTCONF $CHGDIR/`amgetconf $CURRENTCONF tpchanger` -slot $2 exit $? ;; esac ;; -search) label=$2 for conf in $CONFIGS; do eval labelstr=\$labelstr_${conf} echo $label | egrep -e $labelstr >/dev/null && break done if [ $? -ne 0 ]; then echo 0 label matches no config; exit 1; fi eval can_search=\$cansearch_${conf} if [ x$can_search = x1 ]; then cd ../$conf $CHGDIR/`amgetconf $conf tpchanger` -search $2 exit $? else amtape $conf label $2 2>&1 | grep "label $label is now loaded" > /dev/null if [ $? -eq 0 ]; then cd ../$conf $CHGDIR/`amgetconf $conf tpchanger` -slot current exit $? else echo 0 tape not found exit 1 fi fi ;; *) cd ../$CURRENTCONF $CHGDIR/`amgetconf $CURRENTCONF tpchanger` $1 exit $? ;; esac;