#!/bin/sh
#
# Creates the Packages.gz and Sources.gz files for the Debian HTTP archive

# Variables

distdir=/var/www/debian/dists

# Build contents files

for release in unstable testing stable; do
	rdir="$distdir/$release"
	echo "Release: $release"
	for arch in all i386 hurd-i386 powerpc alpha; do
		dir="$rdir/main/binary-$arch"
		alldir="$rdir/main/binary-all"
		ftpdir="dists/$release/main/binary-$arch"
		if test -d $dir; then
			echo " Arch: $arch"
			apt-ftparchive packages $ftpdir > "$dir/Packages"
			if test $arch != "all" && test -d $alldir; then
				cat $alldir/Packages >> $dir/Packages
			fi
			gzip --force -9 "$dir/Packages"
			apt-ftparchive packages $ftpdir > "$dir/Packages"
			if test $arch != "all" && test -d $alldir; then
				cat $alldir/Packages >> $dir/Packages
			fi
			apt-ftparchive contents $ftpdir > "$rdir/Contents-$arch"
			if test $arch != "all" && test -d $alldir; then
				zcat $rdir/Contents-all.gz >> $rdir/Contents-$arch
			fi
			gzip --force -9 "$rdir/Contents-$arch"
		fi
	done
	dir="$rdir/main/source"
	ftpdir="dists/$release/main/source"
	apt-ftparchive sources $ftpdir > $dir/Sources
	gzip --force -9 $dir/Sources
	apt-ftparchive sources $ftpdir > $dir/Sources
done

# Fix perms

chown -R nobody.nogroup /var/www/debian

