#!/bin/bash

set -x

dpkg-scanpackages --arch all pool/ > dists/stable/main/binary-all/Packages
cat dists/stable/main/binary-all/Packages | gzip -9 > dists/stable/main/binary-all/Packages.gz

do_hash() {
    HASH_NAME=$1
    HASH_CMD=$2
    echo "${HASH_NAME}:"
    for f in $(find dists/stable -type f -not -name '.*' -not -name 'Release'); do
        echo " $(${HASH_CMD} $f | cut -d" " -f1) $(wc -c $f | sed 's|dists/stable/||')"
    done
}

cat > dists/stable/Release << EOF
Origin: Elwig
Suite: stable
Codename: stable
Version: 1.0
Architectures: all
Components: main
Date: $(date -Ru)
EOF
do_hash "MD5Sum" "md5sum" >> dists/stable/Release
do_hash "SHA1" "sha1sum" >> dists/stable/Release
do_hash "SHA256" "sha256sum" >> dists/stable/Release
