#!/bin/bash -
# cdburn--Trivially burn ISO images to disc

# $Id: cdburn 1748 2011-02-08 20:30:11Z root $
# $URL: file:///home/SVN/usr_local_bin/cdburn $

VERSION='$Id: cdburn 1748 2011-02-08 20:30:11Z root $'
COPYRIGHT='Copyright 2005-2011 JP Vossen (http://www.jpsdomain.org/)'
LICENSE='GNU GENERAL PUBLIC LICENSE v2'

# See also http://www.troubleshooters.com/linux/coasterless.htm

if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then
    cat <<-EoU
	$0 $VERSION
	Trivially burn ISO images to disc
	Usage: $0 </path/to/iso>
	    e.g.
	    $0 /home/jp/CD-image/image.iso
	EoU
    exit 0
fi

speed=''            # Use burner default
#speed='speed=4'    # Hard-code
#case "$HOSTNAME" in
#   drake* ) speed='speed=24' ;; # GCC-4244N, Write: 24x CD-R, Rewrite: 24x CDRW, Read: 8x DVD ROM, 24x CDROM
#   ringo* ) speed='speed=24' ;; # Man.Part# : G9P3H / Dell Part# : 318-0037
#   * )      speed='speed=4'  ;; # Ancient default, but it worked
#esac

# Make sure we have a burner
if   [ -x /usr/bin/wodim ]; then
    # Debian, Ubuntu
    CDBURNER='/usr/bin/wodim'
elif [ -x /usr/bin/cdrecord ]; then
    # CentOS, etc.
    CDBURNER='/usr/bin/cdrecord'
else
    echo "FATAL: Can't find wodim or cdrecord!  Is either installed?"
    exit 1
fi

ISO="$1"
[ -r "$ISO" ] || {
    echo "ISO '$ISO' not found or not readable!" >&2
    exit 2
}


# Debian uses wodim, CentOS uses the older/original cdrecord
# $ man wodim
#   speed=#
#          Set the speed factor of the writing process to #.  # is an inte-
#          ger,  representing a multiple of the audio speed.  This is about
#          150 KB/s for CD-ROM,  about  172 KB/s  for  CD-Audio  and  about
#          1385 kB/s  for  DVD media.  If no speed option is present, wodim
#          will try to get a drive  specific  speed  value  from  the  file
#          /etc/wodim.conf  and  if  it cannot find one, it will try to get
#          the speed value from the CDR_SPEED environment  and  later  from
#          the  CDR_SPEED=  entry  in  /etc/wodim.conf.   If no speed value
#          could be found, wodim uses a drive specific default speed.   The
#          default for all new (MMC compliant) drives is to use the maximum
#          supported by the drive.  If you use speed=0 with a MMC compliant
#          drive,  wodim will switch to the lowest possible speed for drive
#          and medium.  If you are using an old (non MMC)  drive  that  has
#          problems with speed=2 or speed=4, you should try speed=0.

# SEE ALSO: /usr/bin/wodim -prcap
#           /usr/bin/cdrecord -prcap
PS4=''
set -x
$CDBURNER -v -eject -dao $speed padsize=63s -pad "$ISO"
