#!/bin/sh

# 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.01
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

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

#ifdef ARCH_i386
initramfs-tools
discover
discover1
grub
lilo
/* Note that we do not have to include every optimised kernel flavor for
 * i386. Kernel headers are included as third party modules are commonly
 * used on this architecture.
 */
kernel-image-2.4-386
kernel-pcmcia-modules-2.4-386
kernel-headers-2.4-386
linux-image-2.6-386
linux-headers-2.6-386
/* 486 are same images, new name */
linux-image-2.6-486
linux-headers-2.6-486
#endif

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

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

#ifdef ARCH_hppa
initramfs-tools
discover1
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
yaird
discover1
initrd-tools
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
yaird
arcboot
sibyl
EOF

# Only include mips kernels that d-i base-installer installs.
# XXX once mips gets kernel-image-2.4-<subarch> packages, use those
# instead.
for subarch in r4k-ip22 r5k-ip22 sb1-swarm-bn; do
    zcat $MIRROR/dists/$CODENAME/main/binary-mips/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_mipsel
yaird
sibyl
colo
delo
EOF

# Only include mipsel kernels that d-i base-installer installs.
# XXX once mips gets kernel-image-2.4-<subarch> packages, use those
# instead.
for subarch in r3k-kn02 r4k-kn04 cobalt lasat; do
    zcat $MIRROR/dists/$CODENAME/main/binary-mipsel/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_powerpc
initramfs-tools
discover1
quik
yaboot
powerpc-utils
hfsutils
mkvmlinuz
module-init-tools
initrd-tools
linux-image-2.6-powerpc
linux-image-2.6-powerpc-smp
linux-image-2.6-powerpc64
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.
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_sparc
yaird
silo
discover1
initrd-tools
linux-image-2.6-sparc64
linux-image-2.6-sparc64-smp
kernel-image-2.4-sparc32
kernel-image-2.4-sparc32-smp
kernel-image-2.4-sparc64
kernel-image-2.4-sparc64-smp
#endif

#ifdef ARCH_m68k
yaird
fileutils
vmelilo
EOF

# Get all the latest 2.2 for mac kernel
  zcat $MIRROR/dists/$CODENAME/main/binary-m68k/Packages.gz | \
      sed -n 's/Package: \(kernel-image-2.2.*-mac\)$/\1/p' | \
      tail -n 1 \
      >> debian-installer+kernel-$DI_CODENAME
# Get the latest 2.4 kernels, except mac
# XXX once m68k gets kernel-image-2.4-<subarch> packages, use those
# instead.
zcat $MIRROR/dists/$CODENAME/main/binary-m68k/Packages.gz | \
    sed -n 's/Package: \(kernel-image-2.4.*\)$/\1/p' | \
    tail -n 7 | \
    grep -v mac >> debian-installer+kernel-$DI_CODENAME

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

#ifdef ARCH_arm
initramfs-tools
discover1
EOF

zcat $MIRROR/dists/$CODENAME/main/binary-arm/Packages.gz | \
    sed -n 's/Package: \(kernel-image-2.4.*\)$/\1/p' | \
    tail -n5 \
    >> debian-installer+kernel-$DI_CODENAME

cat >> debian-installer+kernel-$DI_CODENAME << EOF
linux-image-2.6-s3c2410
linux-image-2.6-footbridge
#endif
EOF
