Register
It is currently Wed Apr 16, 2014 6:50 pm

make an iso image from a cd using the command line interface


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 7:39 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
originally posted here at usalug.org

keep in mind...this took about 3 days to write (not straight) :)
and it's just a part of the utility i'm currently working on
but since it works great for ripping a disk stand alone
i'm setting it free into the wild...and plan to add it as a function
in my cd burning script (the prementioned work in progress)

NOTE: This script will not burn an ISO...just create one from an existing cd

this script can take either no arguments...or one of the two...or both
best thing to do is just take it home and play with it :)
and here it is...
Code:
#!/bin/bash
# Author:  Joshua Bailey
# Script:  makeISO
# Syntax:  makeISO /dev/cdrom /home/$USER/newOS.iso
# Summary: This script takes a cd-rom in the drive
#          you specify and creates an iso image
#          that you can distribute and/or burn
#          yourself

((n=0))

function notAForwardSlash
{
   if [[ $1 != '/' ]]
        then
      return 0
        else
           return 1
        fi
}

function getFile
{
   STRING=$1
        LENGTH=${#STRING}
   n=0
   for ((n=0;n <= $LENGTH; n++))
        do
      CHAR=${STRING:$n:1}
      if notAForwardSlash $CHAR
      then
         FileName=$FileName$CHAR
      else
         FileName=""
      fi
   done
}

function getPath
{
   getFile $1
   newPath=${1:0:(${#1}-${#FileName})}
}

function getDevice
{
   read -p "Please input the device name (/dev/cdrom): " DEV
   if [[ $DEV = "" ]]
   then
      DEV=/dev/cdrom
   fi
}
function getFileName
{
   read -p "Please state the path for the ISO (/home/$USER/newOS.iso): " fISO
   if [[ $fISO = "" ]]
   then
      fISO=/home/$USER/newOS.iso
   fi
}

numArgs=$#
while [[ $n != 1 ]]
do
   if [[ $numArgs > 1 ]]
   then
      if [[ `echo $1 | grep /dev` ]]
      then
         DEV=$1
      elif [[ `echo $1 | grep .iso` ]]
      then
         fISO=$1
      elif [[ `echo $2 | grep /dev` ]]
      then
         DEV=$2
      elif [[ `echo $2 | grep .iso` ]]
      then
         fISO=$2
      fi
   else
      if [[ $numArgs -eq 1 ]]
      then
         if [[ `echo $1 | grep /dev` ]]
         then
            DEV=$1
            getFileName
         else
            fISO=$1
            getDevice
         fi
      else
         getDevice
         getFileName
      fi
   fi
   getPath $fISO
   while [[ ! -d $newPath ]]
   do
      echo "$newPath does not exist!"
      read -p "Would you like me to create it? (y/n) " ans
      ans=`echo $ans | tr [:upper:] [:lower:]`
      ans=${ans:0:1}
      if [[ $ans != "n" ]]
      then
         mkdir $newPath
      else
         getFileName
      fi
      getPath $fISO
   done
echo "About to create $fISO from disk in $DEV"
read -p "Is this correct? (y/n)" ans
ans=`echo $ans | tr [:upper:] [:lower:]`
ans=${ans:0:1}
if [[ $ans != "n" ]]
then
   echo "*** making iso ***"
        umount $DEV > /dev/null
   dd if=$DEV of=$fISO bs=32k
   if [[ $? != 0 ]]
   then
      echo "*** Error ***"
      read -p "Would you like to try again? (y/n) " ans
      ans=`echo $ans | tr [:upper:] [:lower:]`
      ans=${ans:0:1}
      if [[ $ans != "y" ]]
      then
         echo "*** exiting ***"
         eject
         exit
      fi
   else
      echo "*** iso created ***"
      echo "*** located at:$fISO ***"
                # forgot this part in the first post
                # it ends the loop and asks if you want
                # to make another iso
                read -p "Would you like to create another? (y/n) " ans
                ans=`echo $ans | tr [:upper:] [:lower:]`
                ans=${ans:0:1}
                if [[ $ans != "y" ]]
                then
                        n=1
                else
                        n=0
                        DEV=""
                        fISO=""
                fi
   fi
else
   read -p "Would you like to try again? (y/n)" ans
   ans=`echo $ans | tr [:upper:] [:lower:]`
   ans=${ans:0:1}
   if [[ $ans != "y" ]]
   then
      echo "*** exiting ***"
      eject
      exit
   else
      echo "*** trying again ***"
      numArgs=0
   fi
fi
done
eject


please please please
give me feed back on this script
i'd like to know what you think i should add or subtract from this portion
all ideas are very much appreciated


Top
 Profile  
 PostPosted: Mon Dec 11, 2006 1:28 pm   

Joined: Mon Sep 18, 2006 1:16 pm
Posts: 27
im curious if this script will copy a cd to an iso fully.

for instance, if i have lets say a linux livecd thats bootable, could this script copy it to an iso and when i burn the iso, have the exact same cd as the original bootable and all?


Top
 Profile  
 PostPosted: Mon Dec 11, 2006 6:00 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
katasuka wrote:
im curious if this script will copy a cd to an iso fully.

for instance, if i have lets say a linux livecd thats bootable, could this script copy it to an iso and when i burn the iso, have the exact same cd as the original bootable and all?


Short answer: probably

The whole script looks like it's built around this one command, which does the actual ripping:
    dd if=$DEV of=$fISO bs=32k

and, by default, will copy the entire contents of the CD......However, without the proper block size and count, it may not always be a totally accurate read......

This is a variation of a script called rawread, found on Steve Litt's "Coasterless CD Burning" page, under the section titled Accurately Reading a CD.....This section gives an overview of what is actually taking place, and shows how to accurately read the CD and have the checksum of the iso image agree with the checksum of the CD each time.......

Most of jbsnake's script is for error-checking and gathering user feedback, if needed, which is the bulk of any well-written program, whether it is a shell script or a C program..... :-)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP