#!/bin/sh
######################################################################
# mkstn: Builds a ShareTheNet diskette
# To use this script, you need:
# - run it as root
# - A properly configured kernel (See README for details)
# - The rest of the STN package in the current directory
# - A freshly formatted (FAT) DOS bootable floppy diskette
######################################################################
# [00] 23Mar98 jl New Code
######################################################################

# Some modifyable constants
# -------------------------
INITRDSZ=6000
INITRDDIR=./initrd
LOOP=/dev/loop0
IMG=./initrdf

# Clean up the initrd directory tree
# ----------------------------------
rm -f $INITRDDIR/lib/modules/* 2> /dev/null

# kernel
# ------
cp /usr/src/linux/arch/i386/boot/bzImage /mnt/bzimage

# ip_masq* modules
# ----------------
y=0
for x in `ls /usr/src/linux/modules/ip_masq*`; do
	cp $x $INITRDDIR/lib/modules/ipm$y.o
	y=$[$y+1]
done

# build initrd.gz
# ---------------
rm -f $IMG.gz $IMG
dd if=/dev/zero of=$IMG bs=512 count=$INITRDSZ
losetup -d $LOOP 2> /dev/null;sync
losetup $LOOP $IMG
mkfs.minix -i 512 $LOOP $INITRDSZ
mount -t minix $LOOP /mnt
(cd $INITRDDIR; tar cf - *|(cd /mnt; tar xvf -))
umount $LOOP
losetup -d $LOOP 2> /dev/null;sync
gzip -9 $IMG
mv $IMG.gz initrd.gz

# Get the new diskette from the user
# ----------------------------------
echo "Put in a freshly formatted (format a:/s) MSDOS diskette..."
read

# Prep the diskette
# -----------------
mount -t msdos /dev/fd0H1440 /mnt
mkdir /mnt/modules 2> /dev/null

# Copy the files to the diskette
# ------------------------------
cp ./autoexec.bat /mnt
cp ./loadlin.exe /mnt
cp /usr/src/linux/arch/i386/boot/bzImage /mnt/bzimage
cp initrd.gz /mnt
cp ./rc /mnt
cp ./diald.cfg /mnt
cp ./named* /mnt
cp ./chat /mnt
cp ./secret /mnt
cp ./options /mnt
for x in *.o; do
	cp $x /mnt/modules
done

# Wrap up
# -------
umount /mnt
