#!/bin/bash

# which architectures are used
ARCHS=("i386" "amd64" "ia64")

# creates the relase file for each architecture, which contains informations about the repository
# this is not the same as the Release file at the end of this script
function makeRelease () {
	echo "  Release"
	if [ -z "${1}" ]
  then
    echo "  Please call with a Architecture as first argument"
    exit 1 
  fi
	if [ "${1}" = "Source" ]
	then
		# we have a source mirror here
		RELFILE="dists/10.04/contrib/source/Release"
	else
		RELFILE="dists/10.04/contrib/binary-${1}/Release"
	fi
  if [ ! -e "${RELFILE}" ]; then
    echo "Archive: unstable" > "${RELFILE}"
    echo "Component: contrib" >> "${RELFILE}"
    echo "Origin: EngSaS" >> "${RELFILE}"
    echo "Label: Engineering Solutions and Services Langenbach" >> "${RELFILE}"
    echo "Architecture: ${1}" >> "${RELFILE}"
  fi
}

# the fisrt parameter is the directory, which contains the repository
# related to pb it's the distribution folder like ubuntu
if [ ! -d "${1}" ]
then
	echo "Please set an directory";
	exit 1;
fi

CURDIR=`pwd`
cd "${1}"

for ARCH in ${ARCHS[*]}
do
	echo "Processing $ARCH"

	# Packages.* erzeugen
	echo "  Packages.gz|bz2"
	apt-ftparchive packages "10.04" | gzip > "dists/10.04/contrib/binary-$ARCH/Packages.gz"
	apt-ftparchive packages "10.04" | bzip2 > "dists/10.04/contrib/binary-$ARCH/Packages.bz2"
	
	# Contents erzeugen
	echo "  Contents-$ARCH.gz"
	apt-ftparchive contents "10.04" | gzip > "dists/10.04/Contents-$ARCH.gz"

	# Release file
	makeRelease "${ARCH}"
	
	i=$[$i+1]
done

# Source packages
echo "Source"
echo "  Source.gz"
apt-ftparchive sources "10.04" | gzip > "dists/10.04/contrib/source/Sources.gz"
makeRelease "Source"

# release file
echo "Release"
apt-ftparchive release "dists/10.04" > "dists/10.04/Release"

cd "${CURDIR}"
exit 0;
