#! /bin/sh
#----------------------------------------------------------------------------
# /sbin/init - boot script
#
# Creation:	29.03.2000  fm
# Last Update:  06.10.2002  fm
#
# Copyright (c) 2000-2002 Frank Meyer
#----------------------------------------------------------------------------

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:.; export PATH

while [ 1 ]
do
    /bin/sh
done </dev/tty2 >/dev/tty2 2>&1 &

#----------------------------------------------------------------------------
# mount devices, e.g. /proc
#----------------------------------------------------------------------------
cd /						    # be in root directory
mount -av 2>/dev/null				    # mount /proc

#----------------------------------------------------------------------------
# get boot device
#----------------------------------------------------------------------------
boot_dev="`sed 's/.*boot=/\1/; s/ .*//1' /proc/cmdline`"
boot_fs=vfat

if [ "$boot_dev" = "" ]
then
    colecho "*** ERROR: check syslinux.cfg ***" br x br
    sleep 100000
    exit
fi

rcfile=rc.cfg
optfile=opt.tgz
mount -r $boot_dev -t "$boot_fs" /mnt

if [ ! -r /mnt/"$rcfile" ]
then
	umount /mnt

	echo
	echo "Please remove boot floppy and insert data floppy, then press ENTER"
	echo
	read dummy
	mount -r $boot_dev -t "$boot_fs" /mnt
fi

#----------------------------------------------------------------------------
# load configuration
#----------------------------------------------------------------------------
colecho "getting configuration from bootdisk ..." gn

cp /mnt/"$rcfile" /etc/rc.cfg
/usr/local/bin/dtou /etc/rc.cfg
. /etc/rc.cfg					    # get config

if [ "$?" != "0" ]
then
    colecho "*** ERROR: no rc.cfg found ***" br x br
    sleep 100000
    exit
fi

#----------------------------------------------------------------------------
# unzip all files from bootdevice to optfiles-location
#----------------------------------------------------------------------------
zcat /mnt/"$optfile" | tar xf -
if [ "$?" != "0" ]
then
    colecho "*** ERROR: opt.tgz not found or RAMSIZE to small ***" br x br
    sleep 100000
    exit
fi
/usr/local/bin/dtou /etc/setflags.sh
. /etc/setflags.sh

#----------------------------------------------------------------------------
# run rc.local, normal bootsequence from here
#----------------------------------------------------------------------------
/usr/local/bin/dtou /etc/rc.local		    # strip CRs
. /etc/rc.local
