#!/bin/sh

set -e

# Generate a list of packages required for debian-installer
# This script makes use of the following variables that need to be preset:
# MIRROR, CODENAME, DI_CODENAME
if [ "$MIRROR"x = ""x ] ; then
    echo "\$MIRROR unset; abort!"
    exit 1
fi
if [ "$CODENAME"x = ""x ] ; then
    echo "\$CODENAME unset; abort!"
    exit 1
fi
if [ "$DI_CODENAME"x = ""x ] ; then
    echo "\$DI_CODENAME unset; abort!"
    exit 1
fi

DATE=`date`
cat > debian-installer+kernel-$DI_CODENAME << EOF
/* These packages + the ones needed by debootstrap are the ones needed for
 * debian-installer to be able to install a base Debian system.
 *
 * These packages are installed by various parts of the debian-installer,
 * mostly via its apt-install command.
 *
 * This list can be generated with the command:
 * ../tools/generate_di+k_list
 *
 * DO NOT EDIT THIS FILE, edit the above script
 *
 * Last update: $DATE
 */

#include <debian-installer-$DI_CODENAME>
eject
locales
libdevmapper1.02
lvm-common
lvm2
mdadm
aptitude
jfbterm
unifont
hotplug
usbutils
console-cyrillic
console-terminus
pcmcia-cs
pcmciautils
wireless-tools
xfsprogs
jfsutils
dosfsutils
reiserfsprogs
libfribidi0
localization-config
acpid
ppp
pppoeconf
udev
installation-report
openssh-server
cryptsetup
brltty

/* libsysfs2-udeb provides libsysfs2 so we have to make sure the deb
 * gets included on the first CD too
 */
libsysfs2

/* Needed for rootless installs. */
sudo

/* libdiscover1-udeb provides libdiscover1 so we have to make sure the
 * deb gets included on the first CD too for arches that get discover1
 */

/* #231583: Make life easier for Australian ISP users */
bpalogin

#ifdef ARCH_i386
initramfs-tools
discover
discover1
libdiscover1
grub
lilo
elilo
libc6-i686
/* Note that we do not have to include every optimised kernel flavor for
 * i386, but this does control what kernels are available on the netinst CD.
 * Kernel headers are included as third party modules are commonly
 * used on this architecture.
 */
linux-image-2.6-486
linux-headers-2.6-486
linux-image-2.6-686
linux-headers-2.6-686
#endif

#ifdef ARCH_amd64
initramfs-tools
discover
discover1
libdiscover1
grub
lilo
linux-image-2.6-amd64
linux-headers-2.6-amd64
#endif

#ifdef ARCH_alpha
initramfs-tools
aboot
aboot-base
discover1
libdiscover1
linux-image-2.6-alpha-generic
linux-image-2.6-alpha-smp
#endif

#ifdef ARCH_hppa
initramfs-tools
discover1
libdiscover1
linux-image-2.6-parisc
linux-image-2.6-parisc-smp
linux-image-2.6-parisc64
linux-image-2.6-parisc64-smp
palo
#endif

#ifdef ARCH_ia64
initramfs-tools
discover1
libdiscover1
linux-image-2.6-itanium
linux-image-2.6-itanium-smp
linux-image-2.6-mckinley
linux-image-2.6-mckinley-smp
elilo
#endif

#ifdef ARCH_mips
arcboot
sibyl
linux-image-2.6-r4k-ip22
linux-image-2.6-r5k-ip32
linux-image-2.6-sb1-bcm91250a
linux-image-2.6-sb1a-bcm91480b
#endif

#ifdef ARCH_mipsel
sibyl
colo
delo
linux-image-2.6-r3k-kn02
linux-image-2.6-r4k-kn04
linux-image-2.6-r5k-cobalt
linux-image-2.6-sb1-bcm91250a
linux-image-2.6-sb1a-bcm91480b
#endif

#ifdef ARCH_arm
initramfs-tools
discover1
libdiscover1
nwutil
slugimage
glantank
flash-kernel
nslu2-utils
apex-nslu2
linux-image-2.6-footbridge
linux-image-2.6-iop32x
linux-image-2.6-ixp4xx
linux-image-2.6-nslu2
linux-image-2.6-rpc
linux-image-2.6-s3c2410
#endif

#ifdef ARCH_sparc
initramfs-tools
silo
discover1
libdiscover1
libc6-sparcv9b
libc6-sparcv9
linux-image-2.6-sparc32
linux-image-2.6-sparc32-smp
linux-image-2.6-sparc64
linux-image-2.6-sparc64-smp
#endif

#ifdef ARCH_powerpc
initramfs-tools
discover1
libdiscover1
quik
yaboot
powerpc-utils
hfsutils
mkvmlinuz
module-init-tools
linux-image-2.6-powerpc
linux-image-2.6-powerpc-smp
linux-image-2.6-powerpc64
linux-image-2.6-prep
EOF

# Only include powerpc kernels that d-i base-installer installs.
# XXX once powerpc 2.4 gets kernel-image-2.4-<subarch> packages, use those
# instead, but beware of apus.
# Commented out as no longer relevant for Etch (see #401429)
#for subarch in powerpc power3 power4 power3-pmac power3-chrp-rs6k \
#		power4-pmac power4-chrp-rs6k powerpc-pmac \
#		powerpc-prep powerpc-chrp powerpc-chrp-rs6k apus; do
#	zcat $MIRROR/dists/$CODENAME/main/binary-powerpc/Packages.gz | \
#	    sed -n 's/Package: \(kernel-image-.*-.*\)$/\1/p' | \
#		grep -- "-$subarch$" | sort -n | tail -n 1 \
#                >> debian-installer+kernel-$DI_CODENAME
#done

cat >> debian-installer+kernel-$DI_CODENAME << EOF
#endif

#ifdef ARCH_m68k
fileutils
amiboot
atari-bootstrap
emile
vmelilo
linux-image-2.6-amiga
linux-image-2.6-mac
EOF

# Get the latest kernels for 2.4 d-i subarchs
# XXX once m68k gets kernel-image-2.4-<subarch> packages, use those
# instead.
for subarch in amiga atari bvme6000 mvme147 mvme16x q40; do
  zcat $MIRROR/dists/$CODENAME/main/binary-m68k/Packages.gz | \
    sed -n 's/Package: \(kernel-image-2.4.*\)$/\1/p' | \
    grep -- "-$subarch$" | sort -n | tail -n 1 \
		>> debian-installer+kernel-$DI_CODENAME
done

cat >> debian-installer+kernel-$DI_CODENAME << EOF

#endif

EOF

