#!/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.us.debian.org/debian"
#mirror="http://ftp.debian.org/debian"

umask 002
set -e

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
    # For timestamping to work, copy to .new (not link, wget will not break
    # the link)
    cp -a $2 $2.new || true
    # Beware that -N conflicts with -O (#88176, #202911)
    if wget -U pts -q -O $2.new $1 ; then
        mv $2.new $2
    else
        echo "Downloading $1 failed, $2 is stale now"
        rm -f $2.new
    fi
}

# Download all Sources.gz
for comp in main contrib non-free
do
    for dist in oldstable stable testing unstable experimental
    do
	nice_wget $mirror/dists/$dist/$comp/source/Sources.gz \
	    Sources_${dist}_$comp.gz
    done
    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 http://security.debian.org/dists/oldstable/updates/$comp/source/Sources.gz \
	Sources-security-oldstable_$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
    nice_wget http://volatile.debian.org/debian-volatile/dists/stable/volatile/$comp/source/Sources.gz \
	Sources-volatile_$comp.gz
done

# Download update_excuses.html
nice_wget http://ftp-master.debian.org/testing/update_excuses.html.gz \
    update_excuses.html.gz

# Download PTS subscription count
nice_wget http://packages.qa.debian.org/data/pts-subscription-count.txt count.txt

# Download override disparities
nice_wget http://qa.debian.org/data/ftp/override-disparities.unstable \
    override-disparities.unstable
nice_wget http://qa.debian.org/data/ftp/override-disparities.experimental \
    override-disparities.experimental

# Download bugs summary
nice_wget http://merkel.debian.org/~hertzog/pts/bugs.txt bugs.txt
nice_wget http://qa.debian.org/data/ddpo/results/bugs.txt bugs-src.txt
nice_wget http://qa.debian.org/data/bts/sources sources
# Temporary measure because merkel is fucked
#nice_wget http://www.wolffelaar.nl/~jeroen/pts.bugs.txt bugs.txt
#cp /org/bugs.debian.org/etc/indices/sources ./
cut -f1,3 sources >sources.map.new
touch -r sources sources.map.new
mv sources.map.new sources.map

# Download debcheck lists
DCROOT=http://qa.debian.org/data/debcheck/result
nice_wget $DCROOT/stable/lists/ALL-pkglist debcheck-stable
nice_wget $DCROOT/testing/lists/ALL-pkglist debcheck-testing
nice_wget $DCROOT/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
nice_wget http://qa.debian.org/data/bts/wnpp_rm wnpp_rm

# get patches from ubuntu
nice_wget http://patches.ubuntu.com/PATCHES patches.ubuntu
# get packages version in Ubuntu (preprocessed by Lucas on merkel)
nice_wget http://qa.debian.org/~lucas/ubuntu/sources-versions.txt versions.ubuntu
# get bugs in Ubuntu (preprocessed by Lucas on merkel)
nice_wget http://qa.debian.org/~lucas/ubuntu/ubuntu-bugs.txt bugs.ubuntu

# download LowThresholdNmu list
nice_wget 'http://wiki.debian.org/LowThresholdNmu?action=raw' \
    low_threshold_nmu.txt

# ongoing transitions
nice_wget http://ftp-master.debian.org/transitions.yaml \
    transitions.yaml

# download the list of packages indexed by svnbuildstat
nice_wget http://svnbuildstat.debian.net/packages/flatlist \
    svnbuildstat_list.txt

# download DEHS (http://dehs.alioth.debian.org)
nice_wget http://dehs.alioth.debian.org/no_updated.txt \
    dehs_out_of_date.txt
nice_wget http://dehs.alioth.debian.org/no_upstream.txt \
    dehs_error.txt

# What more ?

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

# vim: ts=8
