#!/bin/bash

ME=$(basename $0)
DIR=$(dirname $0)
RSYNC="rsync -CHav --no-motd --fuzzy --partial --progress --times --delete --delete-after --delay-updates --numeric-ids --exclude-from=all.exclude"

# Choose one from http://www.caosity.org/download/mirrors
#MIRROR="rsync://rsync.gtlib.gatech.edu/centos/4"
#MIRROR="rsync://mirrors.cat.pdx.edu/CentOS/4"
#MIRROR="rsync://ftp.linux.ncsu.edu/CentOS/4"
MIRROR="rsync://mirror.chpc.utah.edu/pub/centos/4"
#MIRROS="rsync://mirror.anl.gov/centos/4"

set -x

if [ -z "$1" ]; then
  for REPO in os apt updates addons centosplus contrib extras ; do
    $DIR/$ME $REPO
  done
else

[ "$1" != "os" ] && DELETE_EXCLUDED="--delete-excluded"

if [ "$1" == "apt" ]; then

$RSYNC $DELETE_EXCLUDED --exclude-from=$1.exclude $MIRROR/$1/ $1/

else

MY_EXCLUDE=""
test -f ${1}.exclude && MY_EXCLUDE="--exclude-from=${1}.exclude"
$RSYNC $DELETE_EXCLUDED $MY_EXCLUDE $MIRROR/$1/ $1/

fi

fi
