ISO image maker
Forum: Programming and Scripting
Topic: ISO image maker
started by: Zucca
Posted by Zucca on Mar. 06 2008,01:36
First I just thought to add an alias, but then I found myself scripting...
In case anyone finds this useful... Does it work on DSL?
Code Sample | #!/bin/bash
# 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. # May not work if you specify multiple files/directories to add... But should.;)
# Copyright Zucca. Licence: public domain.
if [ -z "$1" ] then echo "Nothing to do. --help for help." >&2 exit 1 fi
case $1 in --help) echo -e "USAGE: `basename $0` [-bz] <imgfile> <contents for ISO image>\n -bz makes image compressed." echo "If \"imgfile\" is -, then output will be directed to stdout." ;; *) if [ -z "$2" ] then echo "Missing arguments." >&2 exit 1 elif which mkisofs &> /dev/null then MKISOFSOPTS="-JR -file-mode 0444 -dir-mode 0555" case $1 in -bz) # Zipping BZIPCOMMAND="bzip2 -vzc9" if [ -z "$3" ] then echo "Missing arguments." >&2 exit 1 elif ! which bzip2 &> /dev/null then echo "bzip2 isn't in your \$PATH or isn't installed. Do not use -bz option" >&2 exit 1 elif [ "$2" != "-" ] then DESTFILE="$2" shift shift # To file mkisofs $MKISOFSOPTS $@ | $BZIPCOMMAND > $DESTFILE else # To stdout shift shift mkisofs $MKISOFSOPTS $@ | $BZIPCOMMAND fi ;; *) # No zipping DESTFILE="$1" shift case $DESTFILE in -) # To stdout mkisofs $MKISOFSOPTS $@ ;; *) # To file mkisofs $MKISOFSOPTS -o $DESTFILE $@ ;; esac ;; esac else echo "mkisofs isn't in your \$PATH or isn't installed." >&2 exit 1 fi esac |
I'd add a size limit there if I knew the precise size of 650Mb CD. Anyone know this? Or any other suggestions?
Posted by Zucca on Mar. 06 2008,11:58
I found a quite good page about < the actual size of CD >.
Here's in short:Quote | Spelled out simply: 21 minutes == 94,500 sectors == 184.6MB CD-ROM == 212.0MB CD-DA 63 minutes == 283,500 sectors == 553.7MB CD-ROM == 635.9MB CD-DA 74 minutes == 333,000 sectors == 650.3MB CD-ROM == 746.9MB CD-DA 80 minutes == 360,000 sectors == 703.1MB CD-ROM == 807.4MB CD-DA 90 minutes == 405,000 sectors == 791.0MB CD-ROM == 908.4MB CD-DA 99 minutes == 445,500 sectors == 870.1MB CD-ROM == 999.3MB CD-DA |
Posted by ^thehatsrule^ on Mar. 06 2008,14:40
What about DVDs then?
You can also use single quotes so that you don't have to escape certain characters on your output strings.
Any reason for making this a bash-specific script?
Posted by Zucca on Mar. 06 2008,16:55
Quote (^thehatsrule^ @ Mar. 06 2008,11:40) | What about DVDs then?
You can also use single quotes so that you don't have to escape certain characters on your output strings.
Any reason for making this a bash-specific script? |
I could add DVD image creating too. Anyway. I designed this script primary for myself. Later I decided to share this.
Bash is common and I don't know much perl or any other language suitable for this. Well... I could do this with php, but then there would be php depency. ;P
Posted by curaga on Mar. 06 2008,17:13
I guess hats meant it has some bash-specific syntax, so it might or might not work with ash, dash, lash, etc. other shells. Though bash is a standard component, so you're likely to find it on any linux system.
Posted by Zucca on Mar. 06 2008,17:43
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 |
|