#!/bin/sh

if [ -d .olddata ]
then
	mv .olddata .olddata.orig
fi

if [ $# -eq 0 ]
then
	echo "Usage: $0 dir..."
	exit -1
else
	DIRS="$*"
fi

for d in `find $DIRS -name repodata | sed 's/repodata.*//'`
do
	pushd $d
	TITLE=`echo $d | sed 's/.*\(NauLinux\|SLCE\).*\/\([0-9][^\/]*\)\/.*$/\1 \2/'`
        if [ -f repodata/comps-sl.xml ]
	then
		COMPS="-g repodata/comps-sl.xml"
	elif [ -f repodata/comps.xml ]
	then
		COMPS="-g repodata/comps.xml"
	else
		COMPS=""
	fi
	echo $d | grep -qv '\/6' && COMPS="$COMPS --checksum sha"
	echo createrepo --simple-md-filenames --update -d $COMPS .
	createrepo --simple-md-filenames --update -d $COMPS .
	echo repoview -t "$TITLE" .
	repoview -t "$TITLE" .
	popd
done

if [ -d .olddata.orig ]
then
        mv .olddata.orig .olddata
fi
