. ../locations.include
MYPWD=`pwd`
export MYPWD
if [ $ARCH != `uname -i` ] ; then
  echo "You seem to be trying to build arch $ARCH , on a `uname -i` system"
  echo "exiting"
  exit 1
fi
MEDIA=$1
if [ -z $MEDIA ] ; then
        echo "You must pass either \"CD\" or \"DVD\" "
        exit 1
fi
if [ $MEDIA = "dvd" -o $MEDIA = "DVD" ] ; then
  TOTISO=$TOTDVD
  MEDIA="DVD"
else
  if [ $MEDIA = "cd" -o $MEDIA = "CD" ] ; then
        MEDIA="CD"
        if [ $CD_TOTISO_PLUS -ne $TOTCD ] ; then
           TOTISO=$CD_TOTISO_PLUS
        else
           TOTISO=$TOTCD
        fi
  else
        echo "You must pass either \"CD\" or \"DVD\" "
        exit 1
  fi
fi
if [ ! -f $RELEASEDIR/$ARCH-disc0-disc1/.$MEDIA ] ; then
  echo "The iso tree area has not been built for $MEDIA"
  echo "Please run \"make.isos.just.dirs.sh $MEDIA\""
  echo "and then run \"make.isos.just.mkisofs.sh $MEDIA\""
  exit 1
fi
echo "You selected to build $MEDIA iso images"
cd $RELEASEDIR
echo ""
#Now make the iso images
#CHECK that $CDISOAREA exists and make if it does not
if [ -d $CDISOAREA ] ; then
  echo "Creating CD iso images in $CDISOAREA"
else
  mkdir -p $CDISOAREA 
fi
#
# Make disc1 FIRST DISK is special because of booting
CDNAME=$CDISOAREA/$DEFAULT.$VERSION.$DATE.$MEDIA.$ARCH
CDNUM=1
#
cd $RELEASEDIR/$ARCH-disc0-disc$CDNUM
#splittree.py make this dir and we do not need it since we put the rpms in $DEFAULT
if [ -d $DEFAULT/RPMS ] ; then
    rmdir $DEFAULT/RPMS
fi
$MYPWD/subscripts/mkisoimage.disc$CDNUM.sh . "$CDNAME.disc$CDNUM.iso" 
echo "implanting md5sum in disc$CDNUM now"
/usr/lib/anaconda-runtime/implantisomd5 $CDNAME.disc$CDNUM.iso
dd if=/dev/zero count=15 bs=2048 >> $CDNAME.disc$CDNUM.iso
CDNUM=2

# Make discx
if [ $TOTISO -lt $CONTRIB_ISO -a $MEDIA = "CD" ] ; then
   $TOTISO=$CONTRIB_ISO
fi
while [ $CDNUM -le $TOTISO ]
do
  cd $MYPWD/subscripts
  if [ -d $RELEASEDIR/$ARCH-disc0-disc$CDNUM ] ; then
  	cd $RELEASEDIR/$ARCH-disc0-disc$CDNUM
#splittree.py make this dir and we do not need it since we put the rpms in $DEFAULT
	if [ -d $DEFAULT/RPMS ] ; then
    		rmdir $DEFAULT/RPMS
	fi
  	$MYPWD/subscripts/mkisoimage.discx.sh . "$CDNAME.disc$CDNUM.iso" 
  	echo "implanting md5sum in disc$CDNUM now"
  	/usr/lib/anaconda-runtime/implantisomd5 $CDNAME.disc$CDNUM.iso
  	dd if=/dev/zero count=15 bs=2048 >> $CDNAME.disc$CDNUM.iso
  fi
  CDNUM=`expr $CDNUM + 1`
done
cd $CDISOAREA
echo "Making sha1sum now, this will take a while"
sha1sum $DEFAULT.$VERSION.$DATE.$MEDIA.$ARCH.disc*.iso > $CDNAME.SHA1SUM
echo "Making md5sum now, this will take a while"
md5sum $DEFAULT.$VERSION.$DATE.$MEDIA.$ARCH.disc*.iso > $CDNAME.md5sum
