if [ -f locations.include ] ; then
 . ./locations.include
else
  if [ -f ../locations.include ] ; then
    . ../locations.include
  fi
fi

UPDATES=/tmp/updates.img
MNTPOINT=/tmp/rhupdates
RHupdates=$TREE/$SITEDIR/RHupdates
if [ ! -d $RHupdates ] ; then
  echo "Not making a updates.img since there is no RHupdates directory"
  exit 
fi
#if [ -s $RHupdates/packages.py ] ; then
#  PACKAGESPY=$RHupdates/packages.py
#else
#  PACKAGESPY=$TREE/RHupdates/packages.py
#fi
#KERNELNAME=`find ../.. -follow -name "kernel-smp-2*" | grep -v headers`
#KERNELVERSION=`rpm -qp --queryformat "%{VERSION}-%{RELEASE}" $KERNELNAME`
#grep kernel-module-openafs-${KERNELVERSION} $PACKAGESPY
#if [ $? = 1 ] ; then
#  echo "You seem to have the wrong version in $PACKAGESPY for "
#  echo "kernel-module-openafs , it should be $KERNELVERSION"
#  exit 1
#fi

IMAGESIZE=`du -s $RHupdates | cut -f1`
if [ $IMAGESIZE -le 65 ] ; then
	echo "Image was too small so had to make it bigger"
	IMAGESIZE=65
fi
IMAGESIZE=`expr $IMAGESIZE + 1`
echo "IMAGESIZE IS $IMAGESIZE"
INODES=`find $RHupdates -print | wc -l`
INODES=`expr $INODES + 10`
echo "INODES is $INODES"
dd if=/dev/zero of=$UPDATES bs=1k count=$IMAGESIZE 
/sbin/mke2fs -F -m 0 -q -N $INODES -b 1024 $UPDATES $IMAGESIZE
rm -rf $MNTPOINT
mkdir $MNTPOINT
mount -o loop,sync -t ext2 $UPDATES $MNTPOINT
/bin/rm -r $MNTPOINT/lost+found
(cd $RHupdates ; find . | cpio -pvdum $MNTPOINT)
sync
sync
sync
df -k $MNTPOINT
df -i $MNTPOINT
umount $MNTPOINT
#CJS we need to verify that what we think we copied to the .img is really there
mount -o loop,ro -t ext2 $UPDATES $MNTPOINT
diff -r $MNTPOINT $RHupdates
if [ $? != 0 ] ; then
  echo "The newly created $UPDATES does not match $RHupdates"
  umount $MNTPOINT
  exit 1
else
  umount $MNTPOINT
fi
#cp -v $UPDATES $TREE/$SITEDIR/$DEFAULT/images/
cp -v $UPDATES $TREE/images/
