#! /bin/sh
# Bootstrap script
# $Id: bootstrap 264 2003-11-22 16:28:54Z sam $

set -ex
export LANG=C

#
# Update Debian stuff
#
for dist in woody sarge sid; do
  for arch in i386 powerpc sparc; do
    d="dists/$dist/main/binary-$arch"
    if [ -d "$d" ]; then
      # Build a fake tree
      rm -Rf packages-tmp
      for dir in `find pool -type d`; do
        mkdir -p "packages-tmp/$dir"
      done
      for file in `find pool -name '*_'$arch'.deb' -o -name '*_all.deb'`; do
        ln -s "`pwd`/$file" "packages-tmp/$file"
      done
      # Remove unwanted stuff
      if [ "$dist" != "woody" ]; then
        rm -f `find packages-tmp -type l -name '*woody*'`
      fi
      if [ "$dist" != "sarge" ]; then
        rm -f `find packages-tmp -type l -name '*sarge*'`
      fi
      if [ "$dist" = "woody" ]; then
        rm -f `find packages-tmp -type l ! -name '*woody*'`
      fi
      if [ "$dist" = "sarge" ]; then
        rm -f `find packages-tmp -type l ! -name '*sarge*'`
      fi
      # Build package list
      cd packages-tmp
      #dpkg-scanpackages pool /dev/null | gzip -9c >| "$d/Packages.gz"
      dpkg-scanpackages pool /dev/null | gzip -9c >| "../$d/Packages.gz"
      cd ..
      rm -Rf packages-tmp
    fi
  done
  d="dists/$dist/main/source"
  if [ -d "$d" ]; then
    # Build a fake tree
    rm -Rf packages-tmp
    for dir in `find pool -type d`; do
      mkdir -p "packages-tmp/$dir"
    done
    for file in `find pool -name '*.dsc' -o -name '*.tar.gz'`; do
      ln -s "`pwd`/$file" "packages-tmp/$file"
    done
    # Remove unwanted stuff
    if [ "$dist" != "woody" ]; then
      rm -f `find packages-tmp -type l -name '*woody*'`
    fi
    if [ "$dist" != "sarge" ]; then
      rm -f `find packages-tmp -type l -name '*sarge*'`
    fi
    if [ "$dist" = "woody" ]; then
      rm -f `find packages-tmp -type l ! -name '*woody*'`
    fi
    if [ "$dist" = "sarge" ]; then
      rm -f `find packages-tmp -type l ! -name '*sarge*'`
    fi
    # Build sources list
    cd packages-tmp
    #dpkg-scansources pool /dev/null | gzip -9c >| "$d/Sources.gz"
    dpkg-scansources pool /dev/null | gzip -9c >| "../$d/Sources.gz"
    cd ..
    rm -Rf packages-tmp
  fi
done