#!/bin/sh

SIZE=$1
LANG=$2
TYPE=$3
SRC=$4

pwd=`pwd`

echo "-> Populating MFS tree..."
cd ../${TYPE}/mfs.tree
find . -print |cpio -pmdu /mnt 2>&1 >/dev/null
if [ "X$?" != "X0" ]
then
	echo "-> ERROR while transfering ../${TYPE}/mfs.tree to /mnt..."
	echo "-> Aborting $0"
	exit 10
fi
cp ../lang/mfs.rc.${LANG} /mnt/etc/rc
cp ../lang/README.${LANG} /mnt/README
cp ../lang/reboot.${LANG} /mnt/stand/reboot
if [ "${TYPE}" = "dial" ]
then
	cp ../lang/login.${LANG} /mnt/stand/login
	cp ../lang/dialup.${LANG} /mnt/stand/dialup
	cp ../../help/*.hlp /mnt/help/
fi
ln -f /mnt/stand/reboot /mnt/stand/shutdown
cp ../lang/update.${LANG} /mnt/stand/update

echo "-> Making and installing crunch1..."
cd ../crunch1
make "SRC=${SRC}" && make install 2>&1 >/dev/null
if [ "X$?" != "X0" ]
then
	echo "-> ERROR while building ../${TYPE}/crunch1..."
	echo "-> Aborting $0"
	exit 10
fi

cd ${pwd}

echo "-> Preparing kernel symbols list..."
if [ ! -f ../tools/dumpnlist/dumpnlist ]
then
	(cd ../tools/dumpnlist; make)
fi
../tools/dumpnlist/dumpnlist ./kernel >/mnt/stand/symbols

echo "-> Preparing kernel config list..."
if [ ! -f ../tools/kget/kget ]
then
	(cd ../tools/kget; make)
fi
../tools/kget/kget ./kernel >/mnt/stand/vanilla
