#!/bin/bash # # write2cd - script for writing given directories on CD # # Author: Christoph Dalitz, Thomas Karsten # Version: 1.1 from 2004.04.23 # DIRS="" GRAFTPOINTS="" MSINFO="" MERGE="" FIRST="no" USAGEMSG="USAGE:\n\ \t`basename $0` [-?] [-close] [-first] [-merge] dirs\n\ OPTIONS:\n\ \t-? prints usage message\n\ \t-close close (multisession) CD\n\ \t-first do not read multi session info\n\ \t-merge merge into multisession CD image\n\ \tdirs directories to burn on CD\n\ \t must be in the form of a cdrecord dirlist\n\ \t eg. /home/chris or /home/=/home/chris/" # config params: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # SCSI device of cdwriter (needs to be configured!!) DEV="" #DEV="IODVDServices" # Apple SuperDrive or Apple Combo Drive #DEV="IOCompactDiscServices" # plain CD burner #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # temporary files TMPISO="/tmp/tmp.iso" TIMESTAMP="/tmp/timestmp" # options for mkisofs for omitting files/directories (-m ...) OMITOPTS="-m '*.o'" # options for multisession burning with cdrecord MULTIOPTS="-multi -data" # plausi check whether device is configured if [ -z "$DEV" ] then echo "ERROR:" 2>&1 echo " Before using $0 you must configure the variable DEV" 2>&1 echo " Open $0 in an editor and set this variable" 2>&1 exit 1 fi # argument loop while [ $# -gt 0 ] do case $1 in -?) echo -e "$USAGEMSG"; exit 0;; -close) MULTIOPTS="";; -first) FIRST="yes";; -merge) MERGE="-M $DEV";; -*) echo -e "$USAGEMSG" 1>&2; exit 1;; *) DIRS="$DIRS $1";; esac shift done if [ -z "$DIRS" ] then echo -e "$USAGEMSG" 1>&2 exit 1 fi echo "$DIRS" | grep -q '=' && GRAFTPOINTS="y" for d in $DIRS do hgp="" echo "$d" | grep -q '=' && d=`echo "$d" | cut -f 2 -d '='` if [ $? -eq 0 ]; then hgp="y" fi if [ "$GRAFTPOINTS" != "$hgp" ]; then echo "$d: graft point is missing." 1>&2 exit 1 fi test -e "$d" || { echo -e "$d not found\n$USAGEMSG" 1>&2; exit 1; } done # determine multisession info if [ $FIRST != "yes" ] then MSINFO="`cdrecord dev=$DEV -msinfo | awk '/^[0-9]+,[0-9]+$/ { print $1 }'`" test -z "$MSINFO" || MSINFO="-C $MSINFO" fi # add option "-graft-points", if the directories are given with # a destination if [ $GRAFTPOINTS ]; then GRAFTPOINTS=-graft-points fi # add timestamp date > $TIMESTAMP # write CD set -x # on some OSes/processors the output of mkisofs can also be piped # directly into cdrecord; this does not work however on Windows 2000 mkisofs -o $TMPISO -r -R -J $OMITOPTS $MSINFO $MERGE $GRAFTPOINTS $DIRS $TIMESTAMP && \ cdrecord -v dev=$DEV speed=16 $MULTIOPTS -eject $TMPISO # cleanup rm -f $TMPISO rm -f $TIMESTAMP