#!/bin/sh

# This is small wrapper for cdrdao
# written by Alexander Wirt <formorer@formorer.de>
# This is free Software under the Terms of the GNU Foundation www.gnu.org

source=/dev/cdrecorder
sourcedriver=generic-mmc
writer=/dev/cdbrenner
driver=generic-mmc
tmpdir=/tmp
speed=24
debug=0


#here starts the script

if [ -e "/usr/bin/volname" ]; then 
	tmpname=$tmpdir/`volname $source`.iso
else 
	tmpname=$tmpdir/cdcopy.iso
fi

if [ -e "$tmpdir/$tmpname"  ]; then
	echo "The iso already exists"
	exit 1
fi

#this are the base options
opts="--source-device $source --device $writer --driver $driver --source-driver $sourcedriver --speed $speed --datafile $tmpname"

#lets do a loop over the options
while test $# -gt 0; do
	case "$1" in
	keep)
		opts="$opts --keepimage"
	;;
	force)
		echo "Force Copy !!!!"
		opts="$opts --force"
	;;
	simulate)
		opts="$opts --simulate"
	;;
	*)
		echo "Unknown option: $1"
		echo "Usage cdcopy.sh [options]"
		echo "Options are:"
		echo "keep :keep the image after copying"
		echo "force :forces the copy in some cases (see cdrdao Documentation)"
		echo "simulate :enables dummy mode"
		exit 1
	;;
	esac
shift
done


echo "Starting now cdrdao"
cdrdao copy $opts
