#!SCRIPTSHELLCMD_MARKER PROGNAME=`basename $0` ############################################################################### # # TAPE LABELLER # ############################################################################### ############################################################################### # # CONFIGURABLE STUFF # ############################################################################### ############################################################################### # # CONFIGURABLE STUFF ENDS HERE # ############################################################################### # Set a load of important variables PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc:/usr/etc:/usr/local/bin:/usr/local/sbin VERBOSE_LEVEL=2 # verbosity level:3=info,warnings,errors TMP_DIR=/var/tmp # where to stash temporary files ERRORS_CAUSE_EXITS=true # error() calls without options do exits # $Id: dailybackup-hpux10.in,v 1.1 1998/05/05 16:29:06 alexis Exp $ VERSION="PATCHLEVEL_MARKER" # version id NEW_LABEL_SIZE=1k NEW_LABEL_VERSION=1 ############################################################################### # # MAIN FUNCTION (called from very bottom of script) # ############################################################################### main() { ########################################################################### # # PROCESS OPTIONS # ########################################################################### # default values for things modified by options MODE=unset TAPE_DEVICE=$TAPE FORCE=false debug 5 "before option processing" # process command line REAL options while [ "X$1" != X ]; do debug 5 "considering $1" case $1 in -V) if expr "$VERSION" : 'P.*R$' > /dev/null; then warning "this is development version; use 'ident'" exit 1 else echo "$PROGNAME version $VERSION" exit 0 fi ;; -r) MODE=read ;; -s) MODE=skip ;; -w) MODE=write ;; -f) FORCE=true ;; -v) VERBOSE_LEVEL=3 ;; -d) [ "X$2" == X ] && usage VERBOSE_LEVEL=$2 shift ;; -t) [ "X$2" == X ] && usage TAPE_DEVICE=$2 shift ;; -*) usage ;; *) break ;; esac shift done debug 5 "after option processing" case $MODE in unset) usage ;; read) [ "X$1" != X ] && usage ;; skip) [ "X$1" != X ] && usage ;; write) debug 5 "mode is write" [ "X$1" == X -o "X$2" != X ] && usage NEW_LABEL_TEXT="$1" shift ;; esac debug 5 "mode is $MODE, new label is $NEW_LABEL_TEXT" # check device set [ "X$TAPE_DEVICE" = X ] && error -e "tape device unknown, use '-t' option" debug 5 "tape device is $TAPE_DEVICE" # check the device file is valid debug 5 "checking device $TAPE_DEVICE is a valid backup device" if [ ! -c "$TAPE_DEVICE" -o ! -r "$TAPE_DEVICE" -o ! -w "$TAPE_DEVICE" ]; then error "$TAPE_DEVICE: invalid backup device (not character device)" fi # try to open tape device for reading; open() can fail the first time! debug 5 "checking tape is present" mt -t $TAPE_DEVICE rewind 2>/dev/null || { warning "Cannot open tape device '$TAPE_DEVICE', retrying" sleep 1 mt -t $TAPE_DEVICE 2>/dev/null || { error "$TAPE_DEVICE: unreadable (tape not inserted/wrong device?)" } } # check if tape already has label delonexit /tmp/$PROGNAME.$$.label dd if=$TAPE_DEVICE bs=$NEW_LABEL_SIZE count=1 of=/tmp/$PROGNAME.$$.label 2>/dev/null OLD_LABEL_VERSION=`sed -n 's/^Version: //p' /tmp/$PROGNAME.$$.label` OLD_LABEL_TEXT=`sed -n 's/^Label: //p' /tmp/$PROGNAME.$$.label` rm /tmp/$PROGNAME.$$.label dontdelonexit /tmp/$PROGNAME.$$.label if [ $MODE != write -a "X$OLD_LABEL_TEXT" = X ]; then mt -t $TAPE_DEVICE rewind error "no label" elif [ $MODE = read ]; then echo "$OLD_LABEL_TEXT" mt -t $TAPE_DEVICE fsf elif [ $MODE = skip ]; then mt -t $TAPE_DEVICE fsf elif [ $MODE = write -a "X$OLD_LABEL_TEXT" != X -a $FORCE = false ]; then mt -t $TAPE_DEVICE rewind error "tape is labelled already, use '-f' to force" elif [ $MODE = write ]; then mt -t $TAPE_DEVICE rewind ( echo "Version: $NEW_LABEL_VERSION" echo "Label: $NEW_LABEL_TEXT" dd if=/dev/zero 2>/dev/null ) | dd of=$TAPE_DEVICE bs=$NEW_LABEL_SIZE count=1 2>/dev/null info labelled fi } ############################################################################### # # RESILIANT MESSAGING FUNCTIONS # ############################################################################### usage() { { echo "Usage: $PROGNAME [ -t ] [ -f ] { -r | -w