#!/bin/sh
# makes a set of new debian floppies:
# * rescue floppy: rescue-new.bin
# * root floppy: root-new.bin
# * driver floppies: drivers-new-n.bin
#
# expects:
# * enough free diskspace to compile kernel and build floppies
# * ./linux must be the kernel src directory (or a symlink to it)
# * the kernel src should be configured before you start this script
#   if there is no .config in the kernel src directory, but in the current
#   dir, then this will be copied there

# kernel
APPENDTOVERSION=-bf24

# wget
DEBIANMIRROR=ftp://ftp.de.debian.org
WGETOPTS=--passive-ftp

# directories used
CURRDIR=`pwd`
LOOPMOUNT=$CURRDIR/tmp/loopmount
MODULESDIR=$CURRDIR/tmp/modules
DRIVERDIR=$CURRDIR/tmp/driver

# first get necessary archives, but only if they are not already there:
test -f root.bin       || wget $WGETOPTS $DEBIANMIRROR/debian/dists/woody/main/disks-i386/current/images-1.44/bf2.4/root.bin
test -f rescue.bin     || wget $WGETOPTS $DEBIANMIRROR/debian/dists/woody/main/disks-i386/current/images-1.44/bf2.4/rescue.bin
test -f drivers.tgz    || wget $WGETOPTS $DEBIANMIRROR/debian/dists/woody/main/disks-i386/current/bf2.4/drivers.tgz
test -f floppy_split.c || wget $WGETOPTS 'http://cvs.debian.org/*checkout*/boot-floppies/utilities/floppy_split.c?rev=HEAD&content-type=text/x-csrc' -O floppy_split.c
test -f floppy_split.h || wget $WGETOPTS 'http://cvs.debian.org/*checkout*/boot-floppies/utilities/floppy_split.h?rev=HEAD&content-type=text/x-csrc' -O floppy_split.h

# make working copies, leave originals untouched:
cp root.bin root-new.bin
cp rescue.bin rescue-new.bin

# modify the rescue (boot) disk with a fresh compiled kernel:
mkdir -p $LOOPMOUNT
mount -o loop -t msdos rescue-new.bin $LOOPMOUNT
gzip -dc $LOOPMOUNT/config.gz >.config-debian-old
rm $LOOPMOUNT/{sys_map.gz,linux.bin,config.gz}

pushd linux
test -f .config || cp ../.config .
make oldconfig
make clean bzImage modules
popd

cp linux/arch/i386/boot/bzImage $LOOPMOUNT/linux.bin
gzip -c linux/System.map >$LOOPMOUNT/sys_map.gz
cp linux/.config .config-new
gzip -c linux/.config >$LOOPMOUNT/config.gz

umount $LOOPMOUNT

# make drivers-new.tgz
pushd linux
mkdir -p $MODULESDIR
make INSTALL_MOD_PATH=$MODULESDIR modules_install
popd

pushd $MODULESDIR
tar cvzf ../modules.tgz .
popd

mkdir -p $DRIVERDIR
pushd $DRIVERDIR
tar xvzf $CURRDIR/drivers.tgz
rm pcmcia.tgz modules.tgz
cp ../modules.tgz .
# TODO: pcmcia.tgz should also be rebuilt
tar cvzf $CURRDIR/drivers-new.tgz .
popd

make floppy_split
./floppy_split drivers-new.tgz drivers-new 1440

# EOF
