#!/bin/sh

REPO_DIR=/home/martyn/debian/
CURRENT_DIR=`pwd`
DIST="$1"
COMPONENT="$2"

cd ${REPO_DIR}

if [ -z "$DIST" ] || [ ! -d dists/$DIST ]; then
    echo "Invalid dist $DIST"
    exit 1;
fi

if [ -z "$COMPONENT" ] || [ ! -d dists/$DIST/$COMPONENT ]; then
    echo "Invalid component $COMPONENT"
    exit 1;
fi

cd ${REPO_DIR}/dists/${DIST}/${COMPONENT}

find -type l -exec rm {} \;

( cd binary-i386/;  find ../binary-all -name '*.deb' -exec ln -s {} ./ \; )
( cd binary-amd64/; find ../binary-all -name '*.deb' -exec ln -s {} ./ \; )

cd ${REPO_DIR}

COMPONENTS=`( cd dists/etch; perl -e 'print join(" ", grep { -d } glob "*");' )`
cat apt-ftparchive.conf.template | sed "s/__DIST__/$DIST/" | sed "s/__SECTIONS__/$COMPONENTS/" > apt-ftparchive.conf

rm packages*.db

apt-ftparchive -qq generate apt-ftparchive.conf

cat <<EOF >dists/$DIST/Release
Origin: Dollyfish
Label: $COMPONENT
Suite: $DIST
EOF
apt-ftparchive release dists/$DIST >> dists/$DIST/Release


cd ${CURRENT_DIR}
