Register
It is currently Sun Apr 20, 2014 2:18 am

iso-tool (still in development though functional)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Tue May 17, 2005 7:35 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
this script is still in the process of being finished...i'd like some input on other features people would like to see...i've already thought about adding a feature that just let's you copy cd's without having to run the script twice...any other suggestions?

Code:
#!/bin/bash

# Author:   Joshua Bailey
# Purpose:   Creates an iso image from a cd/dvd-rom or directory.
#      Can also burn the image.
# Script name:   iso-tool
# Syntax:   iso-tool -make /dev/cdrom /home/user/iso/newISO.iso 
#      iso-tool -make /dev/dvd /home/user/iso/newISO.iso
#      iso-tool -make /home/user/scripts /home/user/backups/backup.iso
#      iso-tool -burn 4 /dev/cdrom /home/user/iso/newISO.iso
#      iso-tool
# Dependencies:   dd, cdrecord, root privalages

DEV=""
FILE=""
DIR=""

function gotRoot
{
   if [[ `id -u` != 0 ]]
   then
      echo "You must have root access!"
      exit
   fi
}

function gotDD
{
   dd -h 2> err
   error=`grep "unrecognized option" err`
   if [[ ${#error} > 0 ]]
   then
      return 0;
   else
      return 1;
   fi
   rm -f err
}

function gotCdRecord
{
   cdrecord -h 2> err
   error=`grep "Bad Option" err`
   if [[ ${#error} > 0 ]]
   then
      return 0;
   else
      return 1;
   fi
   rm -f err
}

# needed to get path and/or filename seperate
# begin filename/path search
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})}
}
# end filename/path search

# begin yes/no check
function YesNo
{
   ans=`echo $1 | tr [:upper:] [:lower:]`
   ans=${ans:0:1}
   if [[ $ans != "n" ]]
   then
      return 0
   else
      return 1
   fi
}
# end yes/no check

# begin getDevice
function getDevice
{
   read -p "Please specify the device to create the iso with: " DEV
}

# begin getDirectory
function getDirectory
{
   read -p "Please specify a directory you want to create an iso with: " DIR
}   

# begin getISOPath
function getISOPath
{
   if [[ ${#1} = 0 ]]
   then
      read -p "Please specify a filename and path for the new iso: " FILE
   else
      FILE=$1
   fi
   getPath $FILE
   isoPath=$newPath
}

# begin checkFilePath
function checkFilePath
{
   isoPath=$1
   if [[ ! -e $isoPath ]]
   then
      echo "The directory $isoPath does not exist!"
      read -p "Would you like to create it? [Y|n] " ans
      if `YesNo $ans`
      then
         mkdir $isoPath
      elif ! `YesNo $ans`
      then
         exit
      fi
   fi
}

# begin getSource
function getSource
{
   read -p "Please specify a source to make the iso from: [cd|dvd|dir] " Source
   Source=`echo $Source | tr [:upper:] [:lower:]`
}

# begin checkSource
function checkSource
{
   
   case $1 in
      cd)   getDevice;
         if [[ ! -e $DEV ]]
         then
            echo "$DEV does not exist!";
            exit;
         fi;;
      
      dvd)   getDevice;
         if [[ ! -e $DEV ]]
         then
            echo "$DEV does not exist!";
            exit;
         fi;;
      
      dir)   getDirectory;
         if [[ ! -e $DIR ]]
         then
            echo "$DIR does not exist!";
            exit;
         fi;;
      *)   echo "Not a valid responce!";
         exit;;
   esac
}

# begin createROMISO
function createROMISO
{
   # the command that makes an ISO from a cd/dvd
   # $1 should be the device path (/dev/cdrom)
   # $2 should be the iso path and filename
   dd if=$1 of=$2 bs=32k
}

# begin createDIRISO
function createDIRISO
{
   # the command that makes an ISO from a directory
   # $1 should be the iso path and filename
   # $2 should be the directory to backup
   mkisofs -l -o $2 $1
}

# begin makeit
function makeit
{
   if [[ ${#1} = 0 ]]
   then
      getSource
   else
      Source=`echo $1 | grep /dev`
      if [[ ${#Source} != 0 ]]
      then
         Source="cd"
         DEV=$1
      else
         Source="dir"
         DIR=$1
      fi
      
   fi
   
   if [[ ${#2} = 0 ]]
   then
      getISOPath
      checkFilePath $isoPath
   else
      getISOPath $2
      checkFilePath $isoPath
   fi
   
   checkSource $Source
   case $Source in
         cd)   createROMISO $DEV $FILE;
            ;;
         dvd)   createROMISO $DEV $FILE;
            ;;
         dir)   createDIRISO $DIR $FILE;
            ;;
         *)   echo "Not a valid response!";
            exit;
            ;;
   esac

}
# end makeit
###################################end create section################################

######################################burn section###################################
function getBurnPath
{
   read -p "Please specify the iso you would like to burn: [/home/$USER/LinuxOS.iso] " burnPath
}

function checkBurnPath
{
   if [[ ! -e $burnPath ]]
   then
      echo "$burnPath does not exist!"
      exit
   fi
   
   yesh=`echo $burnPath | grep ".iso"`
   if [[ ! $yesh ]]
   then
      echo "$burnPath is not an iso!"
      exit
   fi
}

function getBurnDevice
{
   read -p "Please specify a device to burn the iso with: [/dev/cdroms/cdrom0] " burnDEV
}

function checkBurnDevice
{
   if [[ ! -e $burnDEV ]]
   then
      echo "$burnDEV does not exist!"
      exit
   fi
   
   mounted=`cat /etc/mtab | grep $burnDEV`
   if [[ $mounted ]]
   then
      echo "$burnDEV is currently mounted!"
      read -p "Do you wish to unmount it now? [y|n] " ans
      ans=`echo $ans | tr [:upper:] [:lower:]`
      ans=${ans:0:1}
      if [[ $ans -eq "y" ]]
      then
         umount $burnDEV
         echo "$burnDEV is now unmounted"
      else
         exit
      fi
   fi
}

function getSpeed
{
   read -p "Please specify the speed in which you want to burn: [1-4] " speed
}

function checkSpeed
{
   case $speed in
      1) speed=1;;
      2) speed=2;;
      3) speed=3;;
      4) speed=4;;
      *) echo "Not valid!";echo "Burn speed must be 1-4";exit;;
   esac
}

function burnISO
{
   cdrecord -v -eject speed=$1 dev=$2 $3
}



# begin burnit
function burnit
{
   if [[ ${#1} = 0 ]]
   then
      getSpeed
   else
      speed=$1
   fi
   checkSpeed
   
   if [[ ${#2} = 0 ]]
   then
      getBurnDevice
   else
      burnDEV=$2
   fi
   checkBurnDevice
   
   if [[ ${#3} = 0 ]]
   then
      getBurnPath
   else
      burnPath=$3
   fi
   checkBurnPath
   
   echo "Now attempting to burn the ISO located: $burnPath"
   echo "Using the device: $burnDEV"
   echo "At burn speed: $speed"
   sleep 5
   burnISO $speed $burnDEV $burnPath
}
########################end burn section##########################

##############################main################################

gotRoot
if ! gotDD
then
   echo "You must have the program 'dd' in order to continue."
   exit
fi

if ! gotCdRecord
then
   echo "You must have the program 'cdrecord' in order to continue."
   exit
fi

echo $#
if [[ $# = 0 ]]
then
   echo "What would you like to do?"
   echo "(c)reate an iso"
   echo "(b)urn an iso"
   read -p "? " answ
   answ=`echo $answ | tr [:upper:] [:lower:]`
   answ=${answ:0:1}
   case $answ in
      c)   param1="-make";;
      b)   param1="-burn";;
      *)   param1="Not valid!";;
   esac
else
   param1=`echo $1 | tr [:upper:] [:lower:]`
fi

case $param1 in
   "-make")   makeit $2 $3;
         ;;
   "-burn")   burnit $2 $3 $4;
         ;;
   *)       echo "Not valid!";
         echo "Try:";
         echo "iso-tool";
         echo "iso-tool -make /dev/cdrom /home/$USER/new.iso";
         echo "iso-tool -burn 4 /dev/cdrom /home/$USER/SomeLinuxOS.iso";
         ;;
esac

maybe someone can put this on their pc and test it or atleast have it linkable for download :)
let me know what needs to be fixed...added...etc...definately pay close attention to the dvd parts...since i don't have a dvd burner :)


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

All times are UTC - 6 hours


Who is online

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


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