#! /bin/sh
. locations.include
# Hacked by bv@bnl.gov from the originals at
# Hacked by csieh@fnal.gov from the originals at
# ftp://apt-rpm.tuxfamily.org/pub/ftp.tuxfamily.org/apt-rpm/scripts/
# to be more generic.

# Relative directory from the top of the apt repository to the top of the mirror
#MIRRORDIR=../mirror
MIRRORDIR=.

# The idea of full/all/quick is:
#	* the first time you create the apt repository, choose "full".
#	* each night (when updates are downloaded), relaunch with "updates"
#	* if the main os packages change (should not), use "all"

if [ $# -ne 2 -o \( "$1" != "RPMS" -a "$1" != "all" -a "$1" != "updates" -a "$1" != "contrib" \) ]; then
	echo "Usage: $0 <mode> <default> "
	echo "  <mode> is one of:"
	echo "        \"ALL\": SL/RPMS repository creation"
	echo "        \"all\": no apt repository creation, but full indexes regeneration"
	echo "        \"updates\": no apt repository creation, only updates indexes regeneration"
	echo "        \"contrib\": no apt repository creation, only contrib indexes regeneration"
	exit 1
fi

MODE=$1
#getting from locations.include
DEFAULT=$2
echo "Using $MODE"

###########################################################################
####  I386 MAIN OS
###########################################################################

if [ "$MODE" = "RPMS" ]; then
	# Create directories
	# Create the release files
	cat >$RELEASEDIR/$ARCH/apt/base/release.os <<EOF
Archive: stable
Component: os
Version: ${APTVERSION}
Origin: ftp.scientificlinux.org
Label: ${APTVERSION}
Architecture: ${ARCH} 
EOF

	# Put the symlinks for the base OS packages
	cd $RELEASEDIR/$ARCH/apt
	rm -f RPMS.os
	ln -sf ../$DEFAULT/RPMS RPMS.os
fi

if [ "$MODE" = "ALL" ]; then
	# Generate APT indexes
	genbasedir --flat --bloat --progress $RELEASEDIR/$ARCH/apt os
fi

####################################
########### Remake hash ############
####################################
genbasedir --hashonly $RELEASEDIR/$ARCH/apt os updates contrib
