#!/bin/bash
WEBSITE=http://ftp.nl.debian.org
DIST=unstable
SECTIONS="main contrib non-free"
PLATFORM=amd64

if test "$1" == "-p"
then
   PLATFORM=$2
   shift
   shift
fi

if test ! -f packages
then
   for name in $SECTIONS
   do
      wget -q -O -  $WEBSITE/debian/dists/$DIST/$name/binary-$PLATFORM/Packages.gz
      if test "$?" != "0"
      then
         exit 1
      fi
   done | gzip -cd > packages
fi
package=`echo $1 | sed 's/\+/\\\\\+/g'`
file=`cat packages | awk "BEGIN { found=0 } /^Package: $package\$/ { found=1} /^Filename: / { if (found == 1) { print \\$2 ; found=0}}"`
if test "$file" != ""
then
   wget -q $WEBSITE/debian/$file
else
   echo "File $1 not found."
fi
