#!/bin/sh
#
# Fetch list of packages with firmware to store in the data package,
# while we wait for DEP-11 to gain support for it and a lightweight
# method to look it up.

set -e

mirror=http://http.debian.net/debian

mkdir -p generated

for dist in jessie stretch sid; do
    archs="$(GET $mirror/dists/$dist/Release | awk -F: '/^Architectures/ {print $2}')"
    for arch in $archs; do
	for section in "main" "contrib" "non-free"; do
            # "" is main in Wheezy.
	    if [  main = "$section" ] && [ wheezy = "$dist" ]; then
		url="$mirror/dists/$dist/Contents-$arch.gz"
	    else
		url="$mirror/dists/$dist/$section/Contents-$arch.gz"
	    fi
	    echo "fetching $url"
	    if GET $url | gunzip | grep ^lib/firmware > generated/Fw-Contents-$arch-$dist-$section ; then
                :
            else
                echo "warning: unable to find any firmware for $arch in $dist section $section"
            fi
	done
    done
done
