#!/bin/bash

while [ $# -gt 0 ]; do
    case $1 in
	--dest)
	    shift
	    DEST=$1
	    ;;

	--subdir)
	    shift
	    SUBDIR=$1
	    ;;

	*)
	    break
	    ;;
    esac

    shift
done

#. $MYPWD/locations.include
echo $SITE
echo $RELEASEDIR
echo $TREE

if [ ! -d $RELEASEDIR/$SUBDIR ]; then
    echo "subdir must be the directory to place at the root of the CD"
    exit 1
fi

if [ -z "$DEST" ]; then
    echo "--dest needs to be defined"
    exit 1
fi

echo "Creating $DEST from $RELEASEDIR/$SUBDIR"

cd $RELEASEDIR/$SUBDIR
BOOTIMG="isolinux/isolinux.bin"
echo "Boot image is" $BOOTIMG
BOOTCAT="isolinux/boot.cat"
BOOTOPTS="-no-emul-boot -boot-load-size 4 -boot-info-table"

# Create the image (This is for disk 1)
mkisofs \
	-A "$SITE $DEFAULT DVD" \
	-R -l -v -J \
	-x ./lost+found \
        -c $BOOTCAT $BOOTOPTS \
 	-b $BOOTIMG \
	-o $DEST \
	. 
