#!/bin/bash ########################################################################## ## Create an ISO9660-Image and burn it on a cd recorder ########################################################################## ## $IMAGE_ROOT is set to a path where to store the image IMAGE_ROOT="/CD-master/image" ; # set this to your image path TEMP_SPACE="/scratch" ; # set this to a directory with enough space for holding your (maybe split) data INTERACTIVE=0 ; # set this to 1 for interactive loops and LOGFILE=/data/daten/cdlist.txt ; # Logfile - where burned data is recorded ########## ## CD Info used by mkisofs #VOLID="BurnIt - $*"; VOLID="BurnIt"; PREPID="Hirnforschung Uni Freiburg - root@brain.uni-freiburg.de Tel +49-761-203-9570"; PUBID="Hirnforschung Uni Freiburg - root@brain.uni-freiburg.de Tel +49-761-203-9570"; APPID="Hirnforschung Uni Freiburg - root@brain.uni-freiburg.de Tel +49-761-203-9570"; ########## ## device to use for burning DEVICENR="0,06,00"; DEVICEFIL="/dev/sr0"; SPEED=4 ########## ## support programs CDRECORD=/usr/bin/cdrecord MKISOFS=/usr/bin/mkisofs MYCMP=/usr/X11R6/lib/xcdroast-0.96e/bin/mycmp ########################################################################## ########################################################################## # DO NOT CHANGE ANYTHING BELOW! ########################################################################## ########################################################################## ######### ## private variables RUNAGAIN=1 ; FILES=$* ; ########################################################################## ################## initialization block ############################### function init() { # set filenames for images and log files MAGIC=$$ ; IMAGE=$IMAGE_ROOT/burnit-image.$MAGIC.raw ; MKISOLOG=$IMAGE_ROOT/burnit-mkisofs.$MAGIC.log ; CMPLOG=$IMAGE_ROOT/burnit-cmplog.$MAGIC.log ; echo "BurnIt - (c) 1999 Bastian Friedrich" ; echo "Burn your files on CDR" ; echo ; echo "Using image file base: $IMAGE" ; return 0 ; } ########################################################################## ################## parameter checking block ############################ function check_param() { # Any parameters given? if [ $# -eq 0 ]; then { return 1 ; } ; fi ; # Check whether all files to burn are valid for x in $* ; do if ! [ -f $x ] ; then if ! [ -d $x ] ; then echo "File not found: $x" ; return 1 ; else echo "Found directory $x" ; fi ; else echo "Found file $x" ; fi ; done ; return 0 ; } ########################################################################## ################## mkisofs block ##################################### function create_image() { $MKISOFS -o $IMAGE -R -l -r -L -J \ -m "*/lost+found" \ -V "$VOLID" \ -P "$PUBID" \ -p "$PREPID" \ -A "$APPID" \ $* 2>&1 |tee $MKISOLOG || { return 1 ; } SHALL_SIZE=`grep "Total extents scheduled to be written =" $MKISOLOG |sed -e 's/Total extents scheduled to be written =//'`; IS_SIZE=`grep "extents written" $MKISOLOG |sed -e 's/extents written.*//'`; # mkisofs successful? if [ $SHALL_SIZE -ne $IS_SIZE ] ; then return 1 ; else return 0 ; fi ; } ########################################################################## ################## cdrecord block ##################################### function burn() { $CDRECORD -v dev=$DEVICENR speed=$SPEED -data $IMAGE || { return 1; } } ########################################################################## ################## compare block ##################################### function comp() { $MYCMP $DEVICEFIL $IMAGE $IS_SIZE 2>&1 | tee $CMPLOG ; grep differ $CMPLOG ; CMPRES=$? ; return $CMPRES ; } ########################################################################## ################## delete files ##################################### function clean() { echo "Deleting image and log files" ; rm -f $IMAGE $MKISOLOG $CMPLOG } ########################################################################## ################## log entries ######################################### function log_burns() { for x in $* ; do echo ${x} \(by `logname` on `date "+%x at %T"`\) >> $LOGFILE; done ; sort +0 -1 -t '(' -u < $LOGFILE > $LOGFILE.uniq ; } ########################################################################## ########################################################################## ########################################################################## ########################################################################## ########################################################################## ########################################################################## ########################################################################## init ; # shouldn't return errors :) if ! check_param $FILES ; then { if [ $INTERACTIVE -ne 0 ] ; then dialog --title "Error" --msgbox "Please supply the files to burn on the command line as parameters! (No filenames supplied or unavailable)" 10 70 ; else echo "Please supply the files to burn on the command line as parameters! (No filenames supplied or unavailable)" ; fi ; exit 127 ; } fi ; echo -e "\nAll filenames are valid. Starting mkisofs."; echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="; if ! create_image $FILES ; then { if [ $INTERACTIVE -ne 0 ] ; then dialog --title "Error" --msgbox "An error occured while creating the image - maybe insufficient disk space?" 7 50 ; else echo "An error occured while creating the image - maybe insufficient disk space?" ; fi ; clean ; exit 127 ; } fi ; echo "Mastering successful. Starting cdrecord to burn the CD" ; echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="; while [ $RUNAGAIN -ne 0 ] ; do { if [ $INTERACTIVE -ne 0 ] ; then dialog --msgbox "Please insert an unused CDR in the recorder to continue." 10 50 ; fi ; echo "Starting cdrecord" ; if ! burn ; then { if [ $INTERACTIVE -ne 0 ] ; then dialog --title "Error" --msgbox "An error occured while burning the image - please see cdrecord's output. Aborting." 10 50 ; else echo "An error occured while burning the image - please see cdrecord's output. Aborting."; fi ; } else { echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="; echo echo "Starting mycmp to verify the burned CD. Values are in Percent"; echo if comp ; then { if [ $INTERACTIVE -ne 0 ] ; then dialog --title "Error" --msgbox "Verification UNSUCCESSFUL! The CD seems to have errors!" 10 50 ; else echo "Verification UNSUCCESSFUL! The CD seems to have errors!" ; fi ; } else { if [ $INTERACTIVE -ne 0 ] ; then dialog --title "Successful" --msgbox "Verification successfully completed; no errors found" 10 50 ; else echo "Verification successfully completed; no errors found" ; fi ; log_burns $FILES ; } ; fi ; } fi ; if [ $INTERACTIVE -ne 0 ] ; then if dialog --yesno 'Burn the same CD image again?' 10 50 ; then RUNAGAIN=1 ; else RUNAGAIN=0 ; fi ; else RUNAGAIN=0 ; fi ; } ; done ; if [ $INTERACTIVE -ne 0 ] ; then dialog --yesno "Delete the image and log files?" 10 50 && clean ; else clean ; fi ;