. ../locations.include
ISOBINSAVEDIR=$TREE/build/isolinux/
DATE=`date "+%m%d%y"`
if [ -d $CDISOAREA ] ; then
  echo "Creating CD iso images in $CDISOAREA"
else
  mkdir -p $CDISOAREA 
fi
BOOTIMG="isolinux/isolinux.bin"
BOOTCAT="isolinux/boot.cat"
BOOTOPTS="-no-emul-boot -boot-load-size 4 -boot-info-table"
#
CDNUM=1
CDNAME=$CDISOAREA/$DEFAULT-$VERSION-$DATE-$ARCH
DEST="$CDNAME-DVD.iso"

  echo "Creating $DEST from $TREE ..."
  cd $CDISOAREA
  if [ -d /tmp/work ] ; then
     rm -r /tmp/work
  fi
  mkdir /tmp/work
  cd /tmp/work
  mkdir isolinux
  cp -af $TREE/isolinux/* isolinux/
  if [ -s $BOOTCAT ] ; then
  	rm $BOOTCAT
  fi
  if [ -s $TREE/build/isolinux/isolinux.cfg.cd ] ; then
  	cp -af $TREE/build/isolinux/isolinux.cfg.cd isolinux/isolinux.cfg
  fi
  cp -af $ISOBINSAVEDIR/isolinux.bin isolinux/
  mkdir images
  cp -af $TREE/images/* images/
  RPMS="SL=$TREE/SL"
  FILES="/=$TREE/GPL /=$TREE/$DEFAULT.releasenote /=$TREE/README "
  SECURITY="updates/security=$TREE/updates/security/"
  DIRS1="$DEFAULT.documentation=$TREE/$DEFAULT.documentation RPM-GPG-KEYs=$TREE/RPM-GPG-KEYs "
  if [ $ARCH = "i386" ] ; then
  	SRPMS="SRPMS=$RELEASEDIR/SRPMS/SL/" 
  	FASTBUGS="updates/fastbugs=$TREE/updates/fastbugs/"
  	CONTRIB="contrib=$TREE/contrib/"
  	DIRS2="build=$TREE/build build/RHupdates/=$TREE/RHupdates/"
  else
#we do not have space on the dvd so they will just have to make a cd for these
  	SRPMS=""
  	FASTBUGS=""
  	CONTRIB=""
	DIRS2=""
	SECURITY=""
  fi
  if [ ! -d $TREE/sites/example ] ; then
  	SITESEXAMPLE="sites=$RELEASEDIR/temp/$ARCH/sites/" 
  else
	SITESEXAMPLE="sites=$TREE/sites/"
	SITESEXAMPLE=""
  fi 
  echo "Boot image is" $BOOTIMG
# Create the image (This is for disk 1)

  mkisofs \
	-A "$VERSION DVD" \
	-V "$DEFAULT $VERSION $ARCH" \
	-R -l -v -J \
	-x ./lost+found \
        -c $BOOTCAT $BOOTOPTS \
 	-b $BOOTIMG \
	-o $DEST \
        -graft-points isolinux=./isolinux  images=./images /=$TREE/.discinfo $RPMS $FILES $SECURITY $FASTBUGS $CONTRIB $DIRS1 $DIRS2 $SRPMS $SITESEXAMPLE
  echo "implanting md5sum in $DEST now"
  /usr/lib/anaconda-runtime/implantisomd5 $DEST
  dd if=/dev/zero count=2 bs=2048 >> $DEST
  if [ $ARCH = "x86_64" ] ; then
#Need to make the cd with all the extra stuff for x86_64
  	SRPMS="SRPMS=$RELEASEDIR/SRPMS/SL/" 
  	FASTBUGS="updates/fastbugs=$TREE/updates/fastbugs/"
  	CONTRIB="contrib=$TREE/contrib/"
  	DIRS="build=$TREE/build build/RHupdates/=$TREE/RHupdates/"
        SECURITY="updates/security=$TREE/updates/security/"
	DEST="$CDNAME-DVD-security-contrib-srpms.iso"
  	if [ ! -d $TREE/sites/example ] ; then
  		SITESEXAMPLE="sites=$RELEASEDIR/temp/$ARCH/sites/" 
  	else
		SITESEXAMPLE="sites=$TREE/sites/"
  	fi 
  	mkisofs \
		-A "$VERSION DVD-2" \
		-V "$DEFAULT $VERSION $ARCH" \
		-R -l -v -J \
		-x ./lost+found \
		-o $DEST \
        	-graft-points /=$TREE/.discinfo $SECURITY $FASTBUGS $CONTRIB $DIRS $SRPMS $SITESEXAMPLE
  fi
  cd $CDISOAREA
  echo "Making SHA1SUMS now, this will take a while"
  sha1sum $DEFAULT-$VERSION-$DATE-$ARCH-*.iso > $DEFAULT-$VERSION-$DATE-$ARCH.SHA1SUM
