#!/bin/bash

REPO=$1

if [ -z "$REPO" ]; then
    echo
    echo "Usage: $0 <repo>"
    echo
    exit 1
fi

PROXY=`cat /etc/yum.conf|grep -e ^proxy | cut -d = -f 2`

if [ -z "$PROXY" ]; then
    echo
    echo yum not confgured to use proxy
    echo
    exit 1
fi

export http_proxy=$PROXY

basearch=`uname -i`

DISTROVERPKG=`cat /etc/yum.conf | grep -e ^distroverpkg | cut -d = -f 2`
if [ -z "$DISTROVERPKG" ]; then
    #
    # note, see bugzilla #430096
    # this should be DISTROVERPKG=redhat-release according to docs.
    #
    DISTROVERPKG=fedora-release
fi

releasever=`rpm -q $DISTROVERPKG --queryformat '%{VERSION}'`

if [ -z "$releasever" ]; then
    echo
    echo Cannot determine \$releasever
    echo
    exit 1
fi

echo releasever=$releasever
echo basearch=$basearch

cat /etc/yum.repos.d/$REPO.repo | grep -e ^baseurl | cut -d = -f 2 | while read BASEURL; do
    BASEURL=`eval echo $BASEURL`
    echo BASEURL=$BASEURL

    for F in filelists.xml.gz other.xml.gz primary.xml.gz repomd.xml filelists.sqlite.bz2 other.sqlite.bz2 primary.sqlite.bz2 ; do
	echo "  $F"
	wget --no-cache -q -O /dev/null $BASEURL/repodata/$F
    done
done

yum --disablerepo=* --enablerepo=$REPO clean all


