#! /bin/sh

cd `dirname $0`

RELEASES="stable unstable common"
if [ "$1" = "s" ]; then
    RELEASES="stable"
elif [ "$1" = "u" ]; then
    RELEASES="unstable"
elif [ "$1" = "c" ]; then
    RELEASES="common"
fi

echo $RELEASES
for RELEASE in $RELEASES
do
    if [ ! -s $RELEASE/apt-release.conf ]
    then
        echo "Not repo directory"
        exit 1
    fi

    echo $RELEASE Packages; apt-ftparchive packages $RELEASE > $RELEASE/Packages
    echo $RELEASE Sources; apt-ftparchive sources $RELEASE > $RELEASE/Sources
    echo $RELEASE Contents-amd64; apt-ftparchive contents $RELEASE > $RELEASE/Contents-amd64
    for COMP in Packages Sources Contents-amd64
    do
	echo "$RELEASE $COMP.xz"
	xz -kf $RELEASE/$COMP
    done

    apt-ftparchive -c $RELEASE/apt-release.conf release $RELEASE > $RELEASE/Release
    rm -f $RELEASE/InRelease $RELEASE/Release.gpg
    gpg --clearsign --digest-algo SHA512 -o $RELEASE/InRelease $RELEASE/Release && gpg -abs -o $RELEASE/Release.gpg $RELEASE/Release

done
