#!/bin/bash

# Description: roast_iso.sh
#
# This script has been written so that vdr users are able to burn
# their DVD iso's of their converted vdr recordings.
# 
#	This script is part of the vdr-roaster plugin
#
#		    TESTED WITH VDR-1.4.4
#
#
# command-line usage:   sh roast_iso.sh iso_image.iso
#
#
#					11/14/2006 John Germs

# Variables
ISO_FILE="$1"

# CHECK IF USER HAS THE PROPER DEPENDENCIES TO RUN THIS SCRIPT -----------------------
command_list=(echo grep growisofs which)

for command in ${command_list[@]}; do
        if [ ! -x "`which $command 2>&1`" ]; then
                echo -e "\nERROR: $command not found! "
                base=`basename $command`
                if [ "`which $base 2>&1 | grep "no \`basename $command\` in"`" != "" ]; then
                        echo -e "ERROR: $base was not found anywhere in your \$PATH."
                fi
                exit
        fi
done
# ------------------------------------------------------------------------------------

# check if its an iso file
case "$ISO_FILE" in
*.vdr)
  echo "This recording is still in vdr format"
  exit
  ;;
*.avi)
  echo "This recording is still in avi format"
  exit
  ;;
*.mpg)
  echo "This recording is still in mpg format"
  exit
  ;;
*.iso)
  echo "ISO file detected"
  ;;
*)
  echo "Unknown file format"
  exit
  ;;
esac

# Do we need to do a check here to make sure it will fit on a dvd???
# ... does dvdauthor automatically size it for that? .. maybe not
# do we need /dev/dvd as a variable?
# do we need to check if it exists?


# burn it to dvd disc
growisofs -dvd-compat -Z /dev/dvd=$ISO_FILE

exit
