#!/bin/sh

#SERVER='ftp://ftp.us.debian.org'
export SERVER="http://ftp.at.debian.org"

# $1 is the architecture name

archname=$1

LIBSET='libdb1-compat$ libc6$ libc6.*-dev$'

case $1 in
  alpha)
    LIBSET='libc6.[0-9]*$ libc6.[0-9]*-dev$'
    debarch=alpha ;;

        arm*)
          debarch=arm ;;

        hppa*)
          debarch=hppa ;;

        i486*)
          debarch=i386 ;;

        ia64*)
    LIBSET='libc6.[0-9]*$ libc6.[0-9]*-dev$'
          debarch=ia64 ;;

        m68k*)
          debarch=m68k ;;

        mipsel*)
	  debarch=mipsel ;;

        mips*)
          debarch=mips ;;

        ppc*)
          debarch=powerpc ;;

        sparc*)
          debarch=sparc ;;

        *)
          echo "Hmph - dunno the $1 arch" >&2
                exit 2
esac

wget $SERVER/debian/dists/testing/main/binary-${debarch}/Packages.gz -O /tmp/packageset.gz || exit 2

rm -f /tmp/packageset
gzip -d /tmp/packageset.gz || exit 2

DOWNLOADEDDEBS=""

for PATTERN in $LIBSET
do
        debfilename=`dpkg-awk -f /tmp/packageset "Package:"$PATTERN -- "Filename" | sed --silent 's/Filename: \(.*\)$/\1/p'`

        DEBHERENAME=/tmp/`basename $debfilename`
        wget $SERVER/debian/${debfilename} -O $DEBHERENAME || exit 2
	DOWNLOADEDDEBS="$DOWNLOADEDDEBS $DEBHERENAME"
done
dpkg-cross -a ${debarch} -i $DOWNLOADEDDEBS || exit 2
