#!/bin/bash
# prodvd : script to burn DVD-R/RW and DVD+R/RW with cdrecord-ProDVD Key
# Thomas Chung <tchung@fedoranews.org>
# 2005-10-31

##############################################################################
# mkisofs options:
#
# -J     Generate Joliet directory records in addition to regular iso9660
#        file names.  This is primarily useful when the discs are  to  be
#        used on Windows-NT or Windows-95 machines.
#
# -R     Generate SUSP and RR records using the Rock  Ridge  protocol  to
#        further describe the files on the iso9660 filesystem.
#
# -v     Verbose  execution.
#
# -r     This is like the -R option, but file ownership and modes are set
#        to more useful values.  The uid and gid are set to zero, because
#        they  are  usually  only  useful on the author’s system, and not
#        useful to the client.
# 
# -o filename 
#        name of the file to which the  iso9660  filesystem  image
#        should be written.    
##############################################################################

if ! [ -f ~/.prodvd.conf ]; then
  echo "DVDRW_DEVICE=" >   ~/.prodvd.conf
  echo "DVDRW_SPEED="  >>  ~/.prodvd.conf
  echo ""            >>  ~/.prodvd.conf
  # cdrecord -scanbus  >>  ~/.prodvd.conf
  echo 
  echo "Please enter DVDRW_DEVICE and DVDRW_SPEED in ~/.prodvd.conf file"
  echo
  exit 0
fi

DEVICE=`grep DVDRW_DEVICE ~/.prodvd.conf`
DEVICE=${DEVICE#DVDRW_DEVICE=}
SPEED=`grep DVDRW_SPEED ~/.prodvd.conf`
SPEED=${SPEED#DVDRW_SPEED=}

if [ -z $DEVICE ]; then
  echo
  echo "Please enter DVDRW_DEVICE and DVDRW_SPEED in ~/.prodvd.conf file"
  echo
  exit 0
fi

echo
echo "DVD RW DEVICE = $DEVICE"  
echo "DVD RW SPEED  = $SPEED"
echo

if [ -z $1 ]; then
   echo "Usage: `basename $0` [ key | {iso file} | {directory} ]"
   echo	
   exit 0
fi

if [ $1 = "key" ]; then
  grep "CDR_SECURITY=" /usr/lib/xcdroast-0.98/bin/cdrecord-wrapper.sh
  echo
  exit 0
fi

if [ -f $1 ]; then
   cdrecord-wrapper.sh -eject -v -dao driveropts=burnfree speed=$SPEED dev=$DEVICE $1
else
   if [ -d $1 ]; then
      mkisofs -J -R -v -r -o /tmp/DVD.iso $1
      cdrecord-wrapper.sh -eject -v -dao driveropts=burnfree speed=$SPEED dev=$DEVICE /tmp/DVD.iso
   rm -rf /tmp/DVD.iso
   else
       echo "Sorry, can't find $1"
       echo
       exit 0
   fi
fi
