#!/bin/bash 

# defaults

LABEL="Afio-Backup"
SCSIDEV="0,4,0"
DEVICE="/dev/sr1"
SPEED="8"
LEN="702"
MULTI=""

# process command-line options

while getopts ":a:d:r:s:l:m" optn; do
    case $optn in
    a ) LABEL=$OPTARG
        ;;
    d ) DEVICE=$OPTARG
        ;;
    r ) SCSIDEV=$OPTARG
        ;;
    s ) SPEED=$OPTARG
        ;;
    l ) LEN=$OPTARG
        ;;
    m ) MULTI="-m"
        ;;
    \? ) echo "Usage: `basename $0` [-a label] [-l cd_len] [-m] [-d device] [-r scsidev] [-s speed] file1 file2 ..."
         echo ""
	 echo "Defaults: -a Afio-Backup"
	 echo "          -d /dev/sr1"
	 echo "          -r 0,4,0"
	 echo "          -s 8"
	 echo "          -l 702"
        exit 1  
        ;;
    esac
done
shift $(($OPTIND - 1))

#   process input-files

TMP="/tmp/cdsave.$$"
rm -f $TMP

for filename in "$@"; do
    case $filename in
    *[*?]*  )   # means shell couldnīt extend *.wav, etc.
        echo "warning: no $filename file(s) found"
        ;;
    *   )
        echo >>$TMP "$filename"
        ;;
    esac
done

if [ -s $TMP ] ; then
    cat $TMP | \
    afio -o -uz - | \
    cdbackup -v -a "$LABEL" $MULTI -l "$LEN" -d "$DEVICE" -r "$SCSIDEV" -s "$SPEED" -- -v fs=8m
else
    echo "Error: no files specified"
fi
rm -f $TMP

