#!/bin/bash 

# defaults

DEVICE="/dev/sr1"
TRACK="1"
LIST=0

# process command-line options

while getopts ":d:t:l" optn; do
    case $optn in
    d ) DEVICE=$OPTARG
        ;;
    t ) TRACK=$OPTARG
        ;;
    l ) LIST=1
        ;;
    \? ) echo "Usage: `basename $0` [-d device] [-t track] [-l] [filespec]"
         echo ""
	 echo "Defaults: -d /dev/sr1"
	 echo "          -t 1"
         echo ""
	 echo "if -l is given, archive is listed not restored."
        exit 1  
        ;;
    esac
done
shift $(($OPTIND - 1))

#   process input-files

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

SPECOPT=""
for filespec in "$@"; do
    echo "$filespec" >>$TMP
    SPECOPT="-w $TMP"
    done
#echo "-$SPECOPT-"
#cat $TMP
#echo "--"

if [ $LIST -eq 1 ]; then
  aopt="-t"	# list archive
  echo "`basename $0`: listing archive"
else
  aopt="-i"	# restore archive
  echo "`basename $0`: restoring archive"
fi

cdrestore -d $DEVICE -t $TRACK | afio $aopt -vnz $SPECOPT -

rm -f $TMP
