#!/bin/sh

# make-redhat-mirror
# create local subdirectory structure and download a mirror

# absolute directory for local redhat mirror
LOCALMIRRORDIR=/home/yumadm/pub/package
# remote mirror location
#REMOTEMIRROR=http://mirror.phy.bnl.gov
# remote mirror directory
#REMOTEMIRRORDIR=redhat-pub
# Name of distribution (case sensitive). Used below
DIST=RedHat
# directory where `os' packages reside,
# Relative to $LOCALMIRRORDIR/redhat/linux/$VERSION/en/os/i386/
OSDIR=$DIST/RPMS
# Directory where `base' files such as comps.xml reside.
BASE=$DIST/base

if [ $# -ne 2 -o \( "$1" != "full" -a "$1" != "all" -a "$1" != "quick" -a "$1" != "test" -a "$1" != "clean" \) ]; then
        echo "Usage: $0  "
        echo "   is one of:"
        echo "        \"full\": create mirror of os and updates"
        echo "        \"quick\": update mirror of updates"
        echo "        \"test\": output directory locations; does nothing"
        echo "   gives the Redhat version in canonical form"
        echo "        (eg: \"8.0\", \"9\")"
        exit 1
fi

MODE=$1
VERSION=$2

if [ "$MODE" = "test" ]; then
        echo "LOCAL OS DIR:"
        echo "$LOCALMIRRORDIR/redhat/linux/$VERSION/en/os/i386"
        echo "LOCAL UPDATES DIR:"
        echo "$LOCALMIRRORDIR/redhat/linux/updates/$VERSION/en/os"
#       echo "REMOTE OS MIRROR SITE:"
#       echo "$REMOTEMIRROR/$REMOTEMIRRORDIR/redhat/linux/$VERSION/en/os/i386"
#       echo "REMOTE UPDATES MIRROR SITE:"
#       echo "$REMOTEMIRROR/$REMOTEMIRRORDIR/redhat/linux/updates/$VERSION/en/os"
        exit 0
fi


# create local directory structure
if [ "$MODE" = "full" ]; then
mkdir -p $LOCALMIRRORDIR/redhat/linux/$VERSION/en/os/i386
mkdir -p $LOCALMIRRORDIR/redhat/linux/updates/$VERSION/en/os
fi

# mirror operating system
if [ "$MODE" = "full" ]; then
cd $LOCALMIRRORDIR/redhat/linux/$VERSION/en/os/i386
mkdir -p $OSDIR
mkdir -p $BASE
#lftp -e "open $REMOTEMIRROR/$REMOTEMIRRORDIR/redhat/linux/$VERSION/en/os/i386 && \
#mirror --delete --verbose -X *.src.rpm && \
#quit"
fi

# mirror updates
#cd $LOCALMIRRORDIR/redhat/linux/updates/$VERSION/en/os
#lftp -e "open $REMOTEMIRROR/$REMOTEMIRRORDIR/redhat/linux/updates/$VERSION/en/os && \
#mirror --delete --verbose -X *.src.rpm && \
#quit"

