#!/bin/sh
#
#	$Id: populate,v 1.8.2.4 1999/05/07 10:02:30 abial Exp $
#

. ../Version

pwd=`pwd`

echo "-> Populating MFS tree..."
cd ../${TYPE}/mfs.tree
make
if [ X"${NO_DEVFS}" != X"" ]
then
	make devnodes
fi
if [ "X$?" != "X0" ]
then
	echo "-> ERROR while making \"${TYPE}\" hierarchy in /mnt..."
	echo "-> Aborting $0"
	exit 10
fi
if [ "${TYPE}" = "router" ]
then
	cat ../lang/mfs.rc.${LANGUAGE}| \
		sed -e "s/@VER@/${VER}/g" > \
		/mnt/etc/oinit.rc
else
	cat ../lang/mfs.rc.${LANGUAGE} | \
		sed -e "s/@VER@/${VER}/g" > \
		/mnt/etc/rc
	cp ../../dial/mfs.tree/login.conf /mnt/etc/login.conf
	cat ../lang/README.${LANGUAGE} | \
		sed -e "s/@VER@/${VER}/g" > \
		/mnt/README
fi
cp ../lang/update.${LANGUAGE} /mnt/stand/update
if [ "${TYPE}" = "dial" ]
then
	cp ../lang/reboot.${LANGUAGE} /mnt/stand/reboot
	ln -f /mnt/stand/reboot /mnt/stand/shutdown
	cp ../lang/login.${LANGUAGE} /mnt/stand/login
	cp ../lang/dialup.${LANGUAGE} /mnt/stand/dialup
	(cd ../../help;\
	rm -rf tmp_hlp;\
	mkdir tmp_hlp;\
	for i in `ls *.hlp.${LANGUAGE}`;\
	do \
		cp $i tmp_hlp/`basename $i .hlp.${LANGUAGE}`;\
	done;\
	cd tmp_hlp;\
	ar -cru help.a *;\
	cp help.a /mnt/help.a)
fi

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 "-> Fixing permissions"; cd /mnt; chown -R root *)
