#!/bin/bash

# Written and (c) 2005 by Florian octo Forster <octo a verplant.org>

DISTS='stable testing unstable'
ARCHS='alpha arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sh sparc';
ORIGN='Florian octo Forster'
LABEL='octo'

for DIST in $DISTS; do
	[ -d "dists/$DIST" ] || continue;

	for COMP in `ls dists/$DIST`; do
		[ -d "dists/$DIST/$COMP" ] || continue;

		for ARCH in $ARCHS; do
			if [ ! -e "dists/$DIST/$COMP/binary-$ARCH" -a -e "dists/$DIST/$COMP/all" ]; then
				mkdir "dists/$DIST/$COMP/binary-$ARCH"
			fi

			if [ -e "dists/$DIST/$COMP/binary-$ARCH" ]; then
				echo "Archive: $DIST"       >"dists/$DIST/$COMP/binary-$ARCH/Release"
				echo "Component: $COMP"    >>"dists/$DIST/$COMP/binary-$ARCH/Release"
				echo "Origin: $ORIGN"      >>"dists/$DIST/$COMP/binary-$ARCH/Release"
				echo "Label: $LABEL"       >>"dists/$DIST/$COMP/binary-$ARCH/Release"
				echo "Architecture: $ARCH" >>"dists/$DIST/$COMP/binary-$ARCH/Release"
				
				dpkg-scanpackages -a$ARCH "dists/$DIST/$COMP" /dev/null 2>/dev/null | gzip >"dists/$DIST/$COMP/binary-$ARCH/Packages.gz"
				echo "[$DIST] $COMP/$ARCH"
			fi
		done

		if [ -e "dists/$DIST/$COMP/source" ]; then
			dpkg-scansources "dists/$DIST/$COMP" 2>/dev/null | gzip >"dists/$DIST/$COMP/source/Sources.gz"
			echo "[$DIST] $COMP/source"
		fi
	done
done
