#!/bin/sh
#
# hdw - linux /etc/init.d/boot (copied from ROCK Linux + modifications)
#
# modified for fai routine
#

exec 2>&1

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/fai/scripts

echo "** booting hdw-linux FAI routine ... **"

mount -v -n /dev
mount -v -n /proc ; mount -v -n /sys
mkdir -p /dev/shm ; mount -v -n /dev/shm
mkdir -p /dev/pts ; mount -v -n /dev/pts

echo "loading kernel modules and configuring the kernel ..."
. /etc/conf/kernel

echo "populating device nodes ..."
/etc/init.d/udev start

if [ -f /etc/conf/devfs ] ; then
	echo "configuring device nodes ..."
	. /etc/conf/devfs
fi

echo "activating swap-devices ..."
swapon -a

mount -v -n -o remount,rw /
mount -v -a -t nocoda,nfs

if type hostname > /dev/null 2>&1
then
	echo "set the hostname to [`cat /etc/HOSTNAME`] ..."
	hostname `cat /etc/HOSTNAME`
else
	echo "hostname not set: no 'hostname' command found"
fi

if type loadkeys > /dev/null 2>&1
then
	echo "set the keyboard keymappings ..."
	if [ -L /etc/default.keymap ] ; then
		oldpwd="`pwd`" ; cd /etc
		loadkeys `ls -l default.keymap | tr -s ' ' | cut -f11 -d' '`
		cd "$oldpwd" ; unset oldpwd
	elif [ -f /etc/default.keymap ] ; then
		loadkeys /etc/default.keymap
	else
		echo "no /etc/default.keymap found."
	fi
else
	echo "keymappings not configured: no 'loadkeys' command found."
fi

if type ifconfig > /dev/null 2>&1
then
	echo "setting up loopback networking ..."
	ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
	route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
fi

echo 'setting overflow UID and GID kernel parameters ...'
sysctl -w kernel.overflowuid=`id -u nobody` | tr -d '\n'
echo -n ', ' ; sysctl -w kernel.overflowgid=`id -g nobody`

echo "initializing kernel random number generator ..."
[ -f /var/state/random-seed ] && cat /var/state/random-seed >/dev/urandom

echo
echo
echo "start of FAI (fully automated installation) process, good luck ..."
echo
echo
echo -en "starting portmap ..."
/sbin/portmap
echo " done"
