#!/bin/bash ################################################## # # qburn (quick burn) May-03 by Rick Miles rewritten Jan-04 # A command line application for copying cd's, data disks, music cd's, etc. # Copy to /usr/local and run in any shell with "qburn". # This script works as is for me. Read the help message if it don't work for you # GPL terms and conditions apply to this script # Post to rickfrm@optusnet.com.au if you have comment, or constructive criticism # ################################################## ##### Global variables, change paths to suit. EJECT=/usr/bin/eject SLEEP=/bin/sleep SLEEPTIME=60s CDROM=/dev/scd0 CDROMDEV=0,0,0 SPEED=4 TARGET=/home/toast/burn.data #### FUNCTIONS FOLLOW NEXT ################## ## Function for copying contents of cd to hard drive.##### copy_disk(){ clear echo -e "Enter your source disk." $EJECT sleep 3 echo -e "\nPress \"Enter\" to continue, or \"Ctrl+c\" to quit \c" read allset echo -e "OK, we are going to write to /home/burn.data.\n" test -d /home/toast if [ 0$? -eq 0 ] then dd if=$CDROM of=$TARGET else mkdir /home/toast dd if=$CDROM of=$TARGET fi } ## Function for burning to disk.########################## burn_disk(){ echo -e "\nRemove your source disk and insert a blank disk." $EJECT sleep 2 echo -e "\nPress \"Enter\" to continue, or \"Ctrl+c\" to quit" read allset cdrecord dev=$CDROMDEV speed=$SPEED -v -eject $TARGET end_script } ## Function to start script and check for old file. ########## start_script(){ test -f $TARGET if [ 0$? -eq 0 ]; then clear echo -e "A file $TARGET already exists." echo -e "Enter \"d\" to delete $TARGET, or \nEnter \"b\" to burn the existing $TARGET to a cd. \c" read answer case $answer in b) #!!!!!!!!!!!!!!!!!!NEED TO RE_WORK HERE!!!!!!!!!!!!!!!!!!!!!!!!!! cdrecord dev=$CDROMDEV speed=$SPEED -v -eject $TARGET end_script #!!!!!!!!!!!!!!!!!!MAYBE USE TWO SEPERATE BURNING FUNCTIONS!!!!!!!!!!!!!!!!!!!!!! ;; d) rm $TARGET copy_disk ;; *) clear echo -e "Usage: \"d\" to delete file, \"b\" to burn it to disk!" echo -e "Exiting script. Try again." sleep 3 exit ;; esac else copy_disk fi } ## Function tidying up and closing script. ############### end_script(){ FILESIZE=`du -m /home/toast/burn.data | tr -d "[a-x,/,.] [:space:]"` while true; do echo -e "\nDo you want to burn another disk from $TARGET?\t\c" read answer if [ $answer = "no" -o $answer = "n" ] ; then echo -e "\nThe file $TARGET is $FILESIZE Mbs." echo -e "Do you want to delete it before exiting script?\t\c" read answer if [ $answer = "no" -o $answer = "n" ] ; then echo -e "\nExiting qburn script now" sleep 2 clear exit elif [ $answer = "yes" -o $answer = "y" ] ; then echo -e "Deleting $TARGET now" rm $TARGET echo -e "\nExiting qburn script now" sleep 2 clear exit fi elif [ $answer = "yes" -o $answer = "y" ] ; then echo -e "\nburn_disk\n" fi done } ## Here's the help message displayed using "less". ####### help_message(){ echo -e " \"qburn\" is a script for copying ISO's, data\n" \ "and music from one cd to another.\n\n" \ "The script will first copy from a source cd\n" \ "using \"/usr/bin/dd\" and create a file called\n"\ "\"burn.data\" in a directory /home/toast.\n\n" \ "You will need to have enough room in your\n" \ "/home directory for whatever you will be\n" \ "burning to a new disk.\n\n" \ "Edit the variable \"TARGET\" in this script\n" \ "if you need to point \"dd\" somewhere else. \n\n" \ "This script will use \"/usr/bin/cdrecord\"\n" \ "to burn data to to a blank disk.\n\n" \ "The burning device used by cdrecord in\n" \ "this script is \"0,0,0\". If you don't know\n" \ "what your burning device is, you can run\n" \ "the command \"cdrecord -scanbus\" to find\n" \ "out, then edit the \"CDRWDEV\" variable.\n" \ "if necessary.\n\n" \ "I have re-written and tested this script in\n" \ "a Slackware-9.1 box. I put the script in\n" \ "/usr/local/bin and \"suid\" /usr/bin/cdrecord\n" \ "so that the script can be run by a regular user.\n\n" \ "You might also want to check to see that you can\n" \ "run /usr/bin/eject as a regular user\n\n" \ "If you have all that sorted out then this script\n" \ "may be all you need for burning cd's.\n\n" \ "Use \"yes\", \"y\", \"no\", or \"n\" when prompted.\n\n" \ "Enter \"q\" to close this message.\n" } ## MAIN ################################################## clear echo -e "# qdisk ############################################" echo -e "A script for quickly copying anything from one cd to another." echo -e "Enter \"help\" if you need some help first time around, or" echo -e "just hit \"Enter\" if you want to continue. \c" read answer case $answer in help) clear help_message | less exit ;; *) start_script ;; esac if [ -f $TARGET ] ; then echo -e "\nA file named \" burn.data\" has been created.\n" echo -e "Do you want to burn a cd now?\t\c" read answer if [ $answer = "no" -o $answer = "n" ]; then echo -e "\nOK, exiting script.\n" echo -e "Don't forget you have created a new file, $TARGET." exit elif [ $answer = "yes" -o $answer = "y" ] ; then burn_disk fi fi # End script