| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # ex40.sh (burn-cd.sh) |
| 3 | # Script to automate burning a CDR. |
| 4 | |
| 5 | |
| 6 | SPEED=10 # May use higher speed if your hardware supports it. |
| 7 | IMAGEFILE=cdimage.iso |
| 8 | CONTENTSFILE=contents |
| 9 | # DEVICE=/dev/cdrom For older versions of cdrecord |
| 10 | DEVICE="1,0,0" |
| 11 | DEFAULTDIR=/optscip-shell filesystem . . `/opt`. # This is the directory containing the data to be burned. |
| 12 | # Make sure it exists. |
| 13 | # Exercise: Add a test for this. |
| 14 | |
| 15 | # Uses Joerg Schilling's "cdrecord" package: |
| 16 | # http://www.fokus.fhg.de/usr/schilling/cdrecord.html |
| 17 | |
| 18 | # If this script invoked as an ordinary user, may need to suid cdrecord |
| 19 | #+ chmod u+s /usr/bin/cdrecord, as root. |
| 20 | # Of course, this creates a security hole, though a relatively minor one. |
| 21 | |
| 22 | if [scip-shell system . . `[`. -z "$1" ] |
| 23 | then |
| 24 | IMAGE_DIRECTORY=$DEFAULTDIR |
| 25 | # Default directory, if not specified on command-line. |
| 26 | else |
| 27 | IMAGE_DIRECTORY=$1 |
| 28 | fi |
| 29 | |
| 30 | # Create a "table of contents" file. |
| 31 | lsscip-shell system . . ls. -lRF $IMAGE_DIRECTORY > $IMAGE_DIRECTORY/$CONTENTSFILE |
| 32 | # The "l" option gives a "long" file listing. |
| 33 | # The "R" option makes the listing recursive. |
| 34 | # The "F" option marks the file types (directories get a trailing /). |
| 35 | echoscip-shell system . . echo. "Creating table of contents." |
| 36 | |
| 37 | # Create an image file preparatory to burning it onto the CDR. |
| 38 | mkisofs -r -o $IMAGEFILE $IMAGE_DIRECTORY |
| 39 | echoscip-shell system . . echo. "Creating ISO9660 file system image ($IMAGEFILE)." |
| 40 | |
| 41 | # Burn the CDR. |
| 42 | echoscip-shell system . . echo. "Burning the disk." |
| 43 | echoscip-shell system . . echo. "Please be patient, this will take a while." |
| 44 | wodim -v -isosize dev=$DEVICE $IMAGEFILE |
| 45 | # In newer Linux distros, the "wodim" utility assumes the |
| 46 | #+ functionality of "cdrecord." |
| 47 | exitcode=$? |
| 48 | echoscip-shell system . . echo. "Exit code = $exitcode" |
| 49 | |
| 50 | exit $exitcode |