#!/bin/bash
#
# Erik Troan <ewt@redhat.com> 
#
# Copyright 1998 Red Hat Software
#
# This software may be freely redistributed under the terms of the GNU
# public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

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

	--version)
	    shift
	    VERSION=$1
	    ;;

	*)
	    break
	    ;;
    esac

    shift
done

TREE=$1
if [ ! -d $1 ]; then
    echo "First parameter must be the directory to place at the root of the CD"
    exit 1
fi

DEST=$2
if [ -z "$2" ]; then
    echo "Second parameter must be the name of the final iso image."
    exit 1
fi

echo "Creating $2 from $1..."

if [ -z "$VERSION" ]; then
    if [ -f $TREE/RedHat/RPMS/redhat-release* ]; then
	VERSION=`rpm -qp --qf '%{VERSION}' $TREE/RedHat/RPMS/redhat-release*`
    elif [ -f $TREE/RedHat/RPMS/*fermi-release* ]; then
	VERSION=`rpm -qp --qf '%{VERSION}' $TREE/RedHat/RPMS/*fermi-release*`
    elif [ -f $TREE/RedHat/SRPMS/redhat-release* ]; then
	VERSION=`rpm -qp --qf '%{VERSION}' $TREE/RedHat/SRPMS/redhat-release*`
    fi
    VERSION=${VERSION}-`date +%m-%d-%Y`
fi

if [ -z "$ARCH" ]; then
    if [ -f $TREE/RedHat/RPMS/fileutils* ]; then
	ARCH=`rpm -qp --qf '%{ARCH}' $TREE/RedHat/RPMS/fileutils*`
    elif [ -d $TREE/SRPMS ]; then
	ARCH='Sources'
    fi
fi

    BOOT="-b dosutils/autoboot/cdboot.img$3 -c images/boot.cat"
    echo "Boot image is" $BOOT

cd $TREE
find . -name CVS -print > /tmp/73rolling.exclude.dvd
mkisofs \
	-A "Fermi Linux/$ARCH $VERSION DVD" \
	-V "Fermi Linux/$ARCH $VERSION" \
	-o $DEST \
	-R -l -v -J \
	$BOOT  \
	-x ./lost+found \
	-x ./RedHat/base/hdlist \
	-x ./RedHat/base/hdlist2 \
	-x ./RedHat/base/fileorder \
#	-x ./updates/obsolete/RPMS/anaconda-images-7.3-2f6.noarch.rpm \
#	-x ./updates/obsolete/RPMS/anaconda-images-7.3-2f8.noarch.rpm \
#	-x ./updates/obsolete/RPMS/anaconda-images-7.3-FL731.1.noarch.rpm \
#        -x ./updates/obsolete/RPMS/upsupdbootstrap-2.2-4.i386.rpm \
#        -x ./updates/obsolete/RPMS/upsupdbootstrap-2.2-5.i386.rpm \
#        -x ./updates/obsolete/RPMS/upsupdbootstrap-2.2-6.i386.rpm \
#	-x ./updates/obsolete/RPMS/php-manual-4.1.2-7.i386.rpm \
#	-x ./updates/obsolete/RPMS/ghostscript-6.52-9.4.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-source-2.4.18-4.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-doc-2.4.18-4.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-BOOT-2.4.18-4.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-2.4.18-3.athlon.rpm \
#	-x ./updates/obsolete/RPMS/kernel-2.4.18-3.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-2.4.18-3.i686.rpm \
#	-x ./updates/obsolete/RPMS/kernel-bigmem-2.4.18-3.i686.rpm \
#	-x ./updates/obsolete/RPMS/kernel-BOOT-2.4.18-3.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-debug-2.4.18-3.i686.rpm \
#	-x ./updates/obsolete/RPMS/kernel-smp-2.4.18-3.athlon.rpm \
#	-x ./updates/obsolete/RPMS/kernel-smp-2.4.18-3.i586.rpm \
#	-x ./updates/obsolete/RPMS/kernel-smp-2.4.18-3.i686.rpm \
#	-x ./updates/obsolete/RPMS/kernel-source-2.4.18-3.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-doc-2.4.18-3.i386.rpm \
#	-x ./updates/obsolete/RPMS/kernel-source-2.4.18-5.i386.rpm \
	-x ./images/ja \
	-x ./images/es \
	-x ./images/de \
	-x ./images/fr \
	-x ./images/it \
	-exclude-list /tmp/73rolling.exclude.dvd \
        -graft-points \
	 . \
      RedHat/base/=/mnt/src/tmp/hdlistdir \
      SRPMS/=../SRPMS/SRPMS \
#      SRPMS/=../SRPMS.redhat.original 
#      docs/=../docdisc \
      kernel-source/=/usr/src/linux-2.4.18-18.7.x 
