#!/bin/sh
#
# indexcd - Create CDROM Index
# Copyright 1996 - NPX Enterprises - Richmond, BC

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# 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.

# Written by Cory Omand.

## These are the only things you really need to change....
###########################################################

DRIVE=/dev/hdc  	# Replace with your CDROM device.
TEMP=/tmp/      	# Where Temp. Mounts should be made.
COMP=0			# Gzip Index {0=NO | 1=YES}

###########################################################

if [ -z $1 ] || [ -z $2 ] || [ -z $3 ] || [ -z $4 ] || [ -z $5 ]; then
	echo " IndexCD v1.0 - Create CD indicies.
       Usage:
		indexcd <path to CD> <DiscNo> <Release_Name> <Release_Date> <Output File>

       Example:

		indexcd /cdrom Disc3 RedHat_Linux March_1996 INDEX.cd
      "
	exit
fi

TMPFILE=$TMPindexcd.$$$ 
TEMP2=$TEMP$2
CWD=`pwd`

echo -n "Identifying CD..."
grep iso9660 /etc/mtab > $TMPFILE
if [ -s $TMPFILE ]; then
	umount $1 
fi
mkdir $TEMP2
mount -t iso9660 $DRIVE $TEMP2 -o ro 2>&1

echo -n "IndexCD Now Processing $3 $4 $2...." 
cd $TEMP
find $2 -type f -printf "$3 * $4\t%s\t%p\n" | grep -v TRANS.TBL | grep -v rr_moved >$CWD/$5
cd $CWD
echo "Done."

if [ $COMP -eq 1 ]; then
	echo -n "Compressing index file..."
	gzip -9 $5
	echo "Complete."
fi

echo -n "Remounting CD..."
umount $DRIVE
rmdir $TEMP2
mount -t iso9660 $DRIVE $1 -o ro 2>&1
echo "Indexing complete."
