#!/bin/sh

BOOTSIZE=600
RAMSIZE=2300
MOUNT=/mnt/ram

CUR=`pwd`

echo
echo "did you enter a parameter???"
echo
read

# from src/freeramdisk.c, this util frees up old ramdisks.
./freeramdisk

mke2fs -m 0 -i 16384 /dev/ram $BOOTSIZE

# add some special magic from Jakub
dd if=$CUR/boot of=/dev/ram bs=1k count=1

mount -t ext2 /dev/ram $MOUNT

# setup silo stuff
cd silo
echo
tar cvvf - boot sbin | tar -x -f - -C $MOUNT
echo
mkdir $MOUNT/etc
cd $CUR
cp silo.conf $MOUNT/etc/silo.conf
cp welcome.msg $MOUNT/etc/welcome.msg

$MOUNT/sbin/silo -f -p $1 -r $MOUNT

cp vmlinuz-install $MOUNT/vmlinuz

umount $MOUNT

dd if=/dev/ram bs="$BOOTSIZE"k count=1 of=initial.img

# from freeramdisk.c, this util frees up old ramdisks.
./freeramdisk

mke2fs -m 0 -i 16384 /dev/ram $RAMSIZE
mount -t ext2 /dev/ram $MOUNT

cd $CUR/../trees/boot2
echo
tar cvvf - * | tar -x -f - -C $MOUNT
echo
cd $CUR

echo
df
echo

umount $MOUNT

dd if=/dev/ram bs="$RAMSIZE"k count=1 | gzip -9 > root.img

cat initial.img root.img > complete$1.img
