Register
It is currently Tue Oct 21, 2014 1:27 pm

BASH SCRIPT : Turning a cd into an ISO image file


All times are UTC


Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 PostPosted: Thu Feb 05, 2004 11:14 pm   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
keep in mind...this took about 3 days to write (not straight) :lol:
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


Last edited by jbsnake on Sat Aug 07, 2004 5:50 pm, edited 3 times in total.

Top
 Profile  
 PostPosted: Thu Feb 05, 2004 11:48 pm   
Site Admin
User avatar

Joined: Sat Apr 19, 2003 5:55 pm
Posts: 6489
Location: Georgia
Verry :cool: Now I could use this!


Top
 Profile WWW  
 PostPosted: Thu Feb 05, 2004 11:57 pm   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
i think i should start adding a start date/time and a finish date/time...that way i can see how much time i've wasted :lol:


Top
 Profile  
 PostPosted: Fri Feb 06, 2004 12:06 am   
Site Admin
User avatar

Joined: Sat Apr 19, 2003 5:55 pm
Posts: 6489
Location: Georgia
:D


Top
 Profile WWW  
 PostPosted: Wed Feb 18, 2004 12:39 am   
Keeper of the BIG STICK
User avatar

Joined: Wed Apr 30, 2003 7:16 pm
Posts: 12677
Location: Planet Earth
Sweet. :D

_________________
Laptop: Kubuntu 14.04
Desktop: Mageia 1 - kernel 2.6.38.7-desktop-mga


Top
 Profile YIM  
 PostPosted: Wed Feb 18, 2004 12:49 am   
User avatar
Love it. Does it work for all UNIX based OS's because I not only use Linux but am required to use OpenBSD at home..so does it work? Hopefully it does.:D


Top
  
 PostPosted: Wed Feb 18, 2004 12:55 am   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
i say try it...i'd like to know myself...i think it only requires bash and the dd command
maybe try
Code:
whereis dd

and see what comes of it


Top
 Profile  
 PostPosted: Wed Feb 18, 2004 1:40 am   
User avatar
thanks! I will try and see if it works!


Top
  
 PostPosted: Mon Mar 01, 2004 7:31 pm   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
i think i'll add an option to make an iso of a directory too :)


Top
 Profile  
 PostPosted: Thu Apr 01, 2004 4:15 am   
Advanced Member
User avatar

Joined: Tue Mar 30, 2004 4:56 am
Posts: 791
Location: Texas, USA, Terra
jbsnake wrote:
i think i'll add an option to make an iso of a directory too :)


That would come in handy for me, too. I have a project on the (far) back burner to make a bootable CD (LiveCD) from FreeDOS. My problem is that I don't know how to make a CD bootable! :?


Top
 Profile  
 PostPosted: Thu Apr 01, 2004 4:21 am   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
maillion...i left the command line one alone...but i created a dialog driven version that includes the directory ability here
hope that can help


Top
 Profile  
 PostPosted: Thu Apr 01, 2004 2:39 pm   
. . . .
User avatar

Joined: Mon Apr 21, 2003 3:56 pm
Posts: 8044
Well, I hate to do this, but I'm going to go on record with the following statement... not meaning to diss your effort, jbsnake, just trying to prevent misconceptions about ISO9660 formats.

As used herein, the terms 'create an ISO' and 'ISO image' are being used to refer to what is more accurately called a directory snapshot.
A true ISO9660 image is NOT created by the script as the script is currently presented (above). The full ISO9660 standard is not implemented by this script, and, thusly, the output of this script is not a true ISO9660 structure.
If you ever try to use a CD which includes a directory structure created by this method, the target OS might balk at the CD if the target OS requires strict enforcement of the ISO9660 standards (which this script does not enforce).
To create a true ISO9660 compliant image, please use the Linux command 'mkisofs'.

You, the reader, have been warned.


Sorry for the ominous tone, but the potential for problems later on is my concern. I just want people to know there is a bad habit developing here by using the term ISO when ISO is not correct.

BTW, to make an image of a directory, I believe you only need to specify the path to the directory instead of the path to the drive... the directory is already mounted, so that might need a handler, but should be good to go.

Anyways, that is very nice work on the script, jbsnake! I no longer write code, but I definitely see how that works, I like the scripting language!


Last edited by mmmna on Thu Apr 01, 2004 3:09 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Thu Apr 01, 2004 2:53 pm   
. . . .
User avatar

Joined: Mon Apr 21, 2003 3:56 pm
Posts: 8044
maillion wrote:
I have a project on the (far) back burner to make a bootable CD (LiveCD) from FreeDOS. My problem is that I don't know how to make a CD bootable! :?
I thought that a FreeDOS bootable CD has been around for a spell? I believe I own a bootable CD version, IIRC uses a vmlinuz boot kernel.


Top
 Profile  
 PostPosted: Thu Apr 01, 2004 4:09 pm   
Advanced Member
User avatar

Joined: Tue Mar 30, 2004 4:56 am
Posts: 791
Location: Texas, USA, Terra
jbsnake wrote:
maillion...i left the command line one alone...but i created a dialog driven version that includes the directory ability here
hope that can help


It will, I'm sure. I'm still studying shell scripting, so at least it will teach me something! 8)


Top
 Profile  
 PostPosted: Thu Apr 01, 2004 5:49 pm   
Moderator
User avatar

Joined: Tue Dec 02, 2003 7:48 pm
Posts: 1723
Location: Georgia
mmmna wrote:
BTW, to make an image of a directory, I believe you only need to specify the path to the directory instead of the path to the drive... the directory is already mounted, so that might need a handler, but should be good to go.

if you notice...the way i create the image from a directory uses mkisof not dd...have you compared the checksums between a .iso file created using that script versus one created using other software.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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


Powered by phpBB © 2012 phpBB Group
© 2003 - 2012 USA LINUX USERS GROUP