Programming and Scripting :: ISO image maker



Well. At least zsh should be able to run bash scripts. Anyway shebang (#!/bin/bash) should make sure that the script is being run with right program.

Here's an updated version. It should be "idiotproof". ;) Also few new features. Check --help section.
Code Sample
#!/bin/bash

# mkiso.sh
# Bash script for making CD-images out of files and/or directories easily.
# Burned images should work with old CD drives as well with new ones
# and with many OS:es too.
# _Should_ be idiot proof.
# Multiple file/directory support tested and seems to work just fine.

# Copyright Zucca. Licence: public domain.

VERSION="0.4b"

if [ -z "$1" ]
then
   echo "`basename $0` ver. $VERSION"
   echo "Nothing to do. --help for help." >&2
   exit 1
fi

case $1 in
   --help)
       echo "USAGE: `basename $0` [-bz] [-nolimit] [--] <imgfile> <contents for ISO image>"
       echo " -bz makes image compressed."
       echo " -nolimit will allow oversized images (>330000sectors*2048b=675840000b)"
       echo "If \"imgfile\" is -, then output will be directed to stdout."
       echo "Adding -- will stop looking options any further."
       ;;
   *)
   
   function errorexit {
       echo "$@" >&2
       echo "Aborting..." >&2
       exit 1
   }
   
   if [ -z "$2" ]
   then
       # Early exit: we know for sure that something is missing if there
       # is less than 2 cl arguments
       errorexit "Missing arguments."
   elif which mkisofs &> /dev/null
   then
       
       MKISOFSOPTS="-JR -file-mode 0444 -dir-mode 0555"
       
       USEROPTS=""
       
       # Let's seperate options from other arguments
       while true
       # Rarely you need to use while true =D
       do
           if [ "$1" == "--" ]
           then
               # -- found --> stop looking for more options
               shift
               break
           elif echo $1 | egrep "^-" &> /dev/null
           then
               USEROPTS="$USEROPTS$1 "
               shift
           else
               break
           fi
       done
       
       if [ -z "$1" ]
       then
           errorexit "Missing arguments: iso file and files to add"
       elif [ -e "$1" ]
       then
           errorexit "File/directory $1 already exists."
       elif [ -z "$2" ]
       then
           errorexit "Missing arguments: files to add to $1"
       else
           
           # Let's seperate output file from files/directries
           ISOFILE="$1"
           shift
           
           # Specify your custom max size limit here if you like.
           # Standard rule is minimium of 330 000 sectors...
           # each sized 2048 bytes.
           # See http://stason.org/TULARC/pc/cd-recordable/7-6-How-much-data-can-they-hold-650MB-680MB.html
           # if you want to know more
           let "MAXSIZE=330000*2048"
           
           # Let's see if we need to have limited ISO size
           if ! echo $USEROPTS | egrep "\-nolimit" &> /dev/null
           then
               TAB=$(echo -ne "\t")
               TOTSIZE=$(du -bsc $@ | tail -n 1)
               TOTSIZE="${TOTSIZE%$TAB*}"
               
               test "$TOTSIZE" -gt "$MAXSIZE" && errorexit "Too much data to add. Use -nolimit to override."
           fi
           
           case $USEROPTS in
               *-bz*)
                   # Zipping
                   
                   BZIPCOMMAND="bzip2 -vzc9"
                   
                   if ! which bzip2 &> /dev/null
                   then
                       errorexit "bzip2 isn't in your \$PATH or isn't installed. Do not use -bz option"
                   elif [ "$ISOFILE" != "-" ]
                   then
                       # To file
                       mkisofs $MKISOFSOPTS $@ | $BZIPCOMMAND > $ISOFILE
                   else
                       # To stdout
                       shift
                       mkisofs $MKISOFSOPTS $@ | $BZIPCOMMAND
                   fi
               ;;
               *)
                   # No zipping
                   case $ISOFILE in
                       -)
                           # To stdout
                           mkisofs $MKISOFSOPTS $@
                       ;;
                       *)
                           # To file
                           mkisofs $MKISOFSOPTS -o $ISOFILE $@
                       ;;
                   esac
               ;;
           esac
       fi
   else
       errorexit "mkisofs isn't in your \$PATH or isn't installed."
   fi
esac


original here.