#!/bin/sh

# Copyright 2002 Raphaël Hertzog
# This file is distributed under the terms of the General Public License
# version 2 or (at your option) any later version.

#mirror="http://gluck.debian.org/debian"
mirror="http://ftp.debian.org/debian"
nonus="http://non-us.debian.org/debian-non-US"
wgetopt="-t 5 -q -N"

umask 002

if [ -d "../incoming" ]; then
    root=$PWD/..
elif [ -d "incoming" ]; then
    root=$PWD
else
    root=/org/packages.qa.debian.org/www
fi

cd $root/incoming

nice_wget() {
    # $1: url
    # $2: filename
    file=`basename $1`
    if [ -e "$2" ]; then
	cp -a $2 $file
    fi
    wget $wgetopt $1
    mv $file $2
}

# Download all Sources.gz
for comp in main contrib non-free
do
    for dist in stable testing unstable
    do
	nice_wget $mirror/dists/$dist/$comp/source/Sources.gz \
	    Sources_${dist}_$comp.gz
	nice_wget $nonus/dists/$dist/non-US/$comp/source/Sources.gz \
	    Sources-nonus_${dist}_$comp.gz
    done
    nice_wget $mirror/project/experimental/$comp/source/Sources.gz \
	Sources-experimental_$comp.gz
    nice_wget $mirror/dists/stable-proposed-updates/$comp/source/Sources.gz \
	Sources-spu_$comp.gz
    nice_wget $mirror/dists/testing-proposed-updates/$comp/source/Sources.gz \
	Sources-tpu_$comp.gz
    nice_wget $nonus/dists/stable-proposed-updates/non-US/$comp/source/Sources.gz \
	Sources-nonus-spu_$comp.gz
    nice_wget $nonus/dists/testing-proposed-updates/non-US/$comp/source/Sources.gz \
	Sources-nonus-tpu_$comp.gz
    nice_wget http://security.debian.org/dists/stable/updates/$comp/source/Sources.gz \
	Sources-security-stable_$comp.gz
    nice_wget http://security.debian.org/dists/testing/updates/$comp/source/Sources.gz \
	Sources-security-testing_$comp.gz
done

# Download update_excuses.html
wget $wgetopt http://ftp-master.debian.org/testing/update_excuses.html.gz

# Download PTS subscription count
wget $wgetopt http://master.debian.org/~hertzog/pts/count.txt

# Download bugs summary
wget $wgetopt http://merkel.debian.org/~hertzog/pts/bugs.txt
wget $wgetopt http://merkel.debian.org/~hertzog/pts/sources
# Temporary measure because merkel is fucked
#wget $wgetopt -O bugs.txt http://www.wolffelaar.nl/~jeroen/pts.bugs.txt
#cp /org/bugs.debian.org/etc/indices/sources ./
cut -f1,3 sources >sources.map
touch -r sources sources.map

# Download debcheck lists
nice_wget http://qa.debian.org/~weasel/debcheck-result/stable/lists/ALL-pkglist \
    debcheck-stable
nice_wget http://qa.debian.org/~weasel/debcheck-result/testing/lists/ALL-pkglist \
    debcheck-testing
nice_wget http://qa.debian.org/~weasel/debcheck-result/unstable/lists/ALL-pkglist \
    debcheck-unstable

# Download the list of packages with debconf templates
# DISABLED until ddtp.debian.org is back up
#nice_wget http://ddtp.debian.org/cgi-bin/debconf_list.cgi debconf-list

# Get wnpp information (and parse it) [PvR]
wget $wgetopt -O wnpp.html "http://bugs.debian.org/cgi-bin/pkgreport.cgi?which=pkg&data=wnpp&archive=no&pend-exc=done"
../bin/parse-wnpp.pl < wnpp.html > wnpp.txt

# What more ?

# Decompress all files
for file in *.gz; do
    gzip -d -c $file > ${file%%.gz}
done

