#!/bin/sh -e
# Set up apt sources list.

# On new installs, comment out the shipped sources.list, since it assumes
# they are on the network, which is wrong if this is a CD install (this may
# no longer br true; debootstrap generates a pretty decent sources.list).
# Anyway ap-setup generates a better one. Touch the file in any case, because
# apt-setup requires it exist.
touch /etc/apt/sources.list
if [ "$1" = "new" ]; then
	sed 's/^\([^#]\)/#\1/' /etc/apt/sources.list > /etc/apt/sources.list.new
	mv -f /etc/apt/sources.list.new /etc/apt/sources.list
fi

# Probe for cd's in the drive prior to setting up apt.
apt-setup probe || true

# Update available file; tasksel and dselect need it later.
# (but first, get the configuration from /etc/apt/apt.conf)
DPKG="/usr/bin/dpkg"
DPKG_OPTS="--admindir=/var/lib/dpkg"
APTCACHE="/usr/bin/apt-cache"
CACHEDIR="/var/cache/apt"
RES=`apt-config shell \
      DPKG Dir::Bin::dpkg/f \
      APTCACHE Dir::Bin::apt-cache/f \
      CACHEDIR Dir::Cache/d \
`
eval $RES
$APTCACHE dumpavail > $CACHEDIR/available
$DPKG "$DPKG_OPTS" --update-avail $CACHEDIR/available
rm -f $CACHEDIR/available
