#! /bin/sh
# Modificaciones del script original de Tuxfamily 
#  por 2002 Sinner from the Prairy <sinner@escomposlinux.org>
# Este script se ofrece sin garantía alguna. 
# Si te funciona, ¡perfecto! Si no te funciona, mala suerte.
# Este script se distribuye bajo la licencia GPL de la FSF
# http://www.fsf.org/licenses/licenses.html

# Absolute directory containing the top of the apt repository 
APTDIR=/var/ftp/pub
# Relative directory from the top of the apt repository to the top of the mirror
MIRRORDIR=./

# Extra PATH for genbasedir/genpkglist etc
export PATH=/usr/local/sbin:$PATH

# 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 "quick"
#	* if extra packages are put in 'extra' repository, relaunch with "quick"
#	* if the main os packages change (should not), use "all"
if [ $# -ne 1 -o \( "$1" != "full" -a "$1" != "all" -a "$1" != "quick" \) ]; then
	echo "Usage: $0 [full|all|quick]"
	echo "        full: full apt repository creation"
	echo "        all: no apt repository creation, but full indexes regeneration"
	echo "        quick: no apt repository creation, only updates indexes regeneration"
	exit 1
fi
MODE=$1

###########################################################################
#### REDHAT 8.0 I386 MAIN OS
###########################################################################

if [ "$MODE" = "full" ]; then
	# Create directories
	mkdir -p $APTDIR/redhat/8.0/en/i386/base || exit 1

	# Put the symlinks for the base OS packages
	cd $APTDIR/redhat/8.0/en/i386/
	rm -f SRPMS.os
	ln -sf ../../../../$MIRRORDIR/redhat/linux/8.0/en/os/SRPMS SRPMS.os
	cd $APTDIR/redhat/8.0/en/i386/
	rm -f RPMS.os
	ln -sf ../../../../$MIRRORDIR/redhat/linux/8.0/en/os/RedHat/RPMS RPMS.os
fi

if [ "$MODE" = "full" -o "$MODE" = "all" ]; then
	# Generate APT indexes
	genbasedir-0.5 --flat --bloat $APTDIR/redhat/8.0/en/i386 os
fi

###########################################################################
#### REDHAT 8.0 updates
###########################################################################

if [ "$MODE" = "full" ]; then
	# Create directories
	mkdir -p $APTDIR/redhat/8.0/en/i386/base || exit 1
	mkdir -p $APTDIR/redhat/8.0/en/i386/RPMS.updates || exit 1

	# Put the symlinks for the updates packages
	cd $APTDIR/redhat/8.0/en/i386/
	rm -f SRPMS.updates
	ln -sf ../../../../$MIRRORDIR/redhat/linux/updates/8.0/en/os/SRPMS SRPMS.updates
fi

# Remove old symlinks
rm -f $APTDIR/redhat/8.0/en/i386/RPMS.updates/*
# Create new symlinks for all the updates
cd $APTDIR/redhat/8.0/en/i386/RPMS.updates/
find ../../../../../$MIRRORDIR/redhat/linux/updates/8.0/en/os/ -type f ! -name "*.src.rpm" -name "*.rpm" -exec ln -sf {} \;

# Regenerate the apt indexes
genbasedir-0.5 --flat --bloat $APTDIR/redhat/8.0/en/i386 updates

###########################################################################
#### REDHAT 8.0 extra packages
###########################################################################

if [ "$MODE" = "full" ]; then
	# Create directories
	mkdir -p $APTDIR/redhat/8.0/en/i386/base || exit 1
	cd $APTDIR/redhat/8.0/en/i386/
	rm -f SRPMS.extra
	ln -sf ../../../../$MIRRORDIR/redhat-extra-8.0/SRPMS SRPMS.extra
	cd $APTDIR/redhat/8.0/en/i386/
	rm -f RPMS.extra
	ln -sf ../../../../$MIRRORDIR/redhat-extra-8.0/RPMS RPMS.extra

fi

# Regenerate the apt indexes
genbasedir-0.5 --flat --bloat $APTDIR/redhat/8.0/en/i386 extra


####################################
########### Remake hash ############
####################################
genbasedir-0.5 --hashonly $APTDIR/redhat/8.0/en/i386 os updates extra

