VERSION=slc52
ARCH=`uname -i`
TREE=/scratch/$VERSION/$ARCH/
PROD=SL
NAME="\"Scientific Linux CERN\""
RELEASE="SLC"
COMPS="comps.xml"
UPDIMGSRC="$TREE/build/updates.img/"
UPDIMGDEST="/tmp/updates.img"
MNTPOINT="/tmp/rhupdates"
BREPO="/usr/bin/createrepo -g $TREE/$PROD/repodata/$COMPS $TREE/$PROD/"
BINST="/usr/lib/anaconda-runtime/buildinstall \
 --comps $TREE/$PROD/repodata/$COMPS --version $VERSION \
 --product $NAME --release $RELEASE --prodpath $PROD $TREE"

if [ -z $1 ]; then
   echo "say: $0 repo|install|updates"
exit 1
fi


case $1 in
  "repo")
	echo "running: $BREPO"
	$BREPO
    ;;
  "install") 
	echo "running: $BINST"
        /bin/rm -rf $TREE/$PROD/repodata
        /bin/mkdir $TREE/$PROD/repodata 
        /bin/cp -v $TREE/build/$COMPS $TREE/$PROD/repodata/
	#$BINST
        /usr/lib/anaconda-runtime/buildinstall --comps $TREE/$PROD/repodata/$COMPS --version $VERSION --product "Scientific Linux CERN" --release $RELEASE --prodpath $PROD $TREE
    ;;
   "updates")
   	echo "building updates.img"
	/bin/dd if=/dev/zero of=$UPDIMGDEST bs=1k count=256
	/sbin/mke2fs -F -m 0 -q $UPDIMGDEST 
	/bin/rm -rf $MNTPOINT
	/bin/mkdir $MNTPOINT
	/bin/mount -o loop,sync -t ext2 $UPDIMGDEST $MNTPOINT
	/bin/rm -r $MNTPOINT/lost+found
	(cd $UPDIMGSRC ; /usr/bin/find | /bin/cpio -pvdum $MNTPOINT)
	/bin/sync
	umount $MNTPOINT
	/bin/cp -vf $UPDIMGDEST $TREE/images/
    ;; 
   *)
   	echo "what ??" 
    ;; 	 	
esac  
