#!/bin/bash set -e do_usage () { echo "usage: fedora-iso2dvd.sh {-Z device | -o file} images/dirs..." echo echo "with -Z, output is via: growisofs -Z device" echo "with -o, output is via: mkisofs -o file" echo echo "images can be specified directly, or are searched for in dirs" echo "specified on the command line" exit 0 } clean_up () { # Cleanup after ourselves echo Cleaning up ... rm -rf $DIR/mkisofs.* for d in $DIR/*; do umount $d || : rmdir $d || : done rmdir $DIR || : echo Done. } if [ "-o" = "$1" ]; then action="mkisofs" elif [ "-Z" = "$1" ]; then action="growisofs" else do_usage fi shift [ -z "$*" ] && do_usage output=$1 [ -z "$output" ] && do_usage shift [ -z "$*" ] && do_usage ISOS=() echo Finding ISO 9660 images ... for f in $*; do if [ -d "$f" ]; then for g in $f/*; do if file $g | grep 'ISO 9660' >/dev/null 2>&1; then ISOS=(${ISOS[@]} $g) fi done elif file $f | grep 'ISO 9660' >/dev/null 2>&1; then ISOS=(${ISOS[@]} $f) fi done if [ -z "$ISOS" ]; then echo No ISO 9660 images found exit 1 fi if [ -n "$TMPDIR" ]; then DIR=`mktemp -d $TMPDIR/mkisofs.XXXXXX` else DIR=`mktemp -d /tmp/mkisofs.XXXXXX` fi trap clean_up EXIT trap clean_up INT trap clean_up QUIT MAXDSK=0 cnt=1 echo Loop mounting ISO 9660 images ... for i in ${ISOS[@]}; do IDIR=$DIR/loop.$cnt cnt=$[cnt+1] mkdir $IDIR mount -t iso9660 -o ro,loop $i $IDIR IDIRS=(${IDIRS[@]} $IDIR) if [ -f $IDIR/.discinfo ]; then IDSK=`tail +4 $IDIR/.discinfo | head -1` else IDSK=0 echo Warning: found unknown disc fi IDSKS=(${IDSKS[@]} $IDSK) if [ $IDSK -gt $MAXDSK ]; then MAXDSK=$IDSK fi done NISOS=${#ISOS[*]} FIRST="" echo Sorting images ... for d in `seq 1 $MAXDSK` 0; do for k in `seq 0 $[NISOS-1]`; do if [ $d = ${IDSKS[$k]} ]; then if [ -z "$FIRST" ]; then FIRST=${IDIRS[$k]} fi ORDER=(${ORDER[@]} ${IDIRS[$k]}) if [ -z "$DISKS" ]; then DISKS=$d else DISKS="$DISKS,$d" fi fi done done if [ -z "$FIRST" ]; then echo Error sorting images exit 1 fi echo Generating temporary metadata ... mkdir $DIR/mkisofs.extras # Generate top level dir and merge lists add_args=() for d in ${ORDER[@]}; do find $d -type f -maxdepth 1 -exec cp \{\} $DIR/mkisofs.extras/ \; for i in `find $d -type d -maxdepth 1`; do base=`basename $i` if [ "$base" = "`basename $d`" ]; then : # Ignore starting point elif [ "$base" = "isolinux" ]; then # mkisofs wants this to be writable cp -a $i $DIR/mkisofs.extras/ else add_args=(${add_args[@]} $base=$i) fi done done # Update /.discinfo awk '{ if ( NR == 4 ) { print disks } else { print ; } }' \ disks="$DISKS" $FIRST/.discinfo > $DIR/mkisofs.extras/.discinfo if [ "$action" = "growisofs" ]; then command="growisofs -dvd-compat -Z $output" elif [ "$action" = "mkisofs" ]; then command="mkisofs -o $output" else echo "Warning: no output" exit 0 fi echo Generating DVD image ... $command -J -R -v -T -x TRANS.TBL --graft-points \ -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table \ $DIR/mkisofs.extras ${add_args[@]} # Conditionally implant the md5sum into the image [ "$action" = "growisofs" ] && exit 0 [ "$output" = "-" ] && exit 0 [ ! -f $output ] && exit 0 [ -x /usr/lib/anaconda-runtime/implantisomd5 ] && /usr/lib/anaconda-runtime/implantisomd5 --force $output exit 0