LDP/LDP/guide/docbook/abs-guide/ex40.sh

51 lines
1.5 KiB
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2005-05-08 20:09:31 +00:00
# ex40.sh (burn-cd.sh)
2002-07-22 15:11:51 +00:00
# Script to automate burning a CDR.
2001-07-10 14:25:50 +00:00
2008-11-23 22:43:47 +00:00
SPEED=10 # May use higher speed if your hardware supports it.
2001-07-10 14:25:50 +00:00
IMAGEFILE=cdimage.iso
CONTENTSFILE=contents
2009-03-24 18:46:05 +00:00
# DEVICE=/dev/cdrom For older versions of cdrecord
DEVICE="1,0,0"
2002-07-22 15:11:51 +00:00
DEFAULTDIR=/opt # This is the directory containing the data to be burned.
# Make sure it exists.
2004-03-15 13:47:54 +00:00
# Exercise: Add a test for this.
2001-07-10 14:25:50 +00:00
2004-03-15 13:47:54 +00:00
# Uses Joerg Schilling's "cdrecord" package:
# http://www.fokus.fhg.de/usr/schilling/cdrecord.html
2001-07-10 14:25:50 +00:00
2005-05-08 20:09:31 +00:00
# If this script invoked as an ordinary user, may need to suid cdrecord
2004-03-15 13:47:54 +00:00
#+ chmod u+s /usr/bin/cdrecord, as root.
# Of course, this creates a security hole, though a relatively minor one.
2001-07-10 14:25:50 +00:00
if [ -z "$1" ]
then
IMAGE_DIRECTORY=$DEFAULTDIR
2008-11-23 22:43:47 +00:00
# Default directory, if not specified on command-line.
2001-07-10 14:25:50 +00:00
else
IMAGE_DIRECTORY=$1
fi
2002-07-22 15:11:51 +00:00
# Create a "table of contents" file.
2001-07-10 14:25:50 +00:00
ls -lRF $IMAGE_DIRECTORY > $IMAGE_DIRECTORY/$CONTENTSFILE
# The "l" option gives a "long" file listing.
# The "R" option makes the listing recursive.
2001-09-04 13:27:31 +00:00
# The "F" option marks the file types (directories get a trailing /).
2001-07-10 14:25:50 +00:00
echo "Creating table of contents."
2002-07-22 15:11:51 +00:00
# Create an image file preparatory to burning it onto the CDR.
2004-03-15 13:47:54 +00:00
mkisofs -r -o $IMAGEFILE $IMAGE_DIRECTORY
2001-07-10 14:25:50 +00:00
echo "Creating ISO9660 file system image ($IMAGEFILE)."
2002-07-22 15:11:51 +00:00
# Burn the CDR.
2001-07-10 14:25:50 +00:00
echo "Burning the disk."
echo "Please be patient, this will take a while."
2009-03-24 18:46:05 +00:00
wodim -v -isosize dev=$DEVICE $IMAGEFILE
# In newer Linux distros, the "wodim" utility assumes the
2008-11-23 22:43:47 +00:00
#+ functionality of "cdrecord."
2009-03-24 18:46:05 +00:00
exitcode=$?
echo "Exit code = $exitcode"
2001-07-10 14:25:50 +00:00
2009-03-24 18:46:05 +00:00
exit $exitcode