====== burn.sh ====== **Parameters** | ''-s'' | Simulate - no real write will be done | | ''-n '' | Use given name instead of timestamp as CD name | #!/bin/bash # set up CD writer options CD_DEVICE="1,0,0" CD_SPEED=16 CD_OPTS="burnproof" # set up DVD writer options DVD_DEVICE="/dev/scd0" DVD_SPEED=4 # do not touch TOTAL=0 ERROR=0 ################# FUNCTIONS ########################## function showhelp(){ cat <] path [path [path [...]]] DESCRIPTION burn.sh is a frontend to mkisofs, cdrecord and growisofs. It accepts multiple files and directories as arguments which should be burned to a CD or DVD. burn.sh does some filesystem limitation checks and decides on its own if a CD or a DVD is created. OPTIONS -s Call the burning process in simulation mode -n Specifies the Joliet name for the new disk if none is given the current date is used EOF } function checkfiles(){ for file in "$@" do # check filename length=`basename "$file"|wc -c|awk '{print $1}'` if [ "$length" -gt "64" ] then echo " ERROR $file: filename too long ($length>64chars)" ERROR=1 fi # check filesize if [ -f $file ] then size=`du -k "$file"|awk '{print $1}'`; if [ "$size" -gt "2097152" ] then echo " ERROR $file: file too big (>2GB)" ERROR=1 fi let "TOTAL = TOTAL + size" fi # recurse directories if [ -d $file ] then checkfiles `find "$file" -maxdepth 1 -mindepth 1` fi done } function burn_dvd(){ if [ "$SIMULATE" == "1" ] then SIM="-dry-run" fi growisofs $SIM -dvd-compat -speed=$DVD_SPEED -Z $DVD_DEVICE -r -J -V "$NAME" $@ } function burn_cd(){ if [ "$SIMULATE" == "1" ] then SIM="-dummy" fi echo -n "mkisofs -V '$NAME' -r -J $@ | cdrecord -v -ignsize $SIM speed=$CD_SPEED " echo "driveropts='$CD_OPTS' -eject dev=$CD_DEVICE -data -" mkisofs -V "$NAME" -r -J $@ | cdrecord -v -ignsize $SIM speed=$CD_SPEED \ driveropts="$CD_OPTS" -eject dev=$CD_DEVICE -data - } ################# MAIN ########################## # get parameters while getopts "n:s" OPTION do case $OPTION in n ) NAME=$OPTARG;; s ) SIMULATE=1;; esac done shift $(($OPTIND - 1)) # set name if not set if [ -z "$NAME" ] then NAME=`date '+%Y%m%d-%H%M'` fi # check for at least one argument if [ -z $1 ] then showhelp exit 1 fi # check files echo "checking files please wait..." checkfiles "$@" # abort on error if [ "$ERROR" == "1" ] then echo "An error occured. Please fix and try again" exit 1 fi echo echo "A toal of $TOTAL kilobytes needs to be written" if [ "$SIMULATE" == "1" ] then echo "Simulation - using name '$NAME'" else echo "Real Write - using name '$NAME'" fi echo if [ "$TOTAL" -lt "716800" ] then echo "I think it should fit on a 700MB CD-R" echo "Insert media and hit enter when ready" read foo MEDIA="cd" else echo "This does not fit on a CD-R - We'll use a DVD-R" echo "Insert media and hit enter when ready" read foo MEDIA="dvd" fi if [ "$MEDIA" == "cd" ] then if dvd+rw-mediainfo $DVD_DEVICE >/dev/null 2>/dev/null then echo "CD-R would suffice but DVD Media detected - Using DVD-R" MEDIA="dvd" fi fi echo "------------------------------------------------------------" if [ "$MEDIA" == "cd" ] then burn_cd "$@" else burn_dvd "$@" fi