#!/bin/sh

umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin

mount -t proc proc /proc
mount -t sysfs sysfs /sys  
mount -t usbfs usbfs /proc/bus/usb 

if [ -x /etc/ptmalloc.conf ]
then
	. /etc/ptmalloc.conf
fi

# This doesn't really belong here, but we have start this so early
start_bootchart(){
	if [ -e /bootchart -a -e /etc/init.d/bootchart ]
	then
		/etc/init.d/bootchart start
	fi
}

mount_devpts() {
	TTYGRP=5
	TTYMODE=620

	if [ ! -d /dev/pts ]
	then
	    mkdir /dev/pts
	fi

	if [ ! -c /dev/ptmx ]
	then
	    mknod /dev/ptmx c 5 2
		chmod 666 /dev/ptmx
	fi
			
	 mount -t devpts -ogid=$TTYGRP,mode=$TTYMODE devpts /dev/pts
#	 mount -t tmpfs  -osize=1M tmpfs /var/run
	rm -rf /var/run/*

	if [ ! -e /tmp/dsmesock ]
	then
		mount -o bind /mnt/initfs/tmp /tmp
	fi

}

# I hate this hack.  -- Md
make_extra_nodes () {
  grep '^[^#]' /etc/udev/links.conf | \
  while read type name arg1; do
    [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue
    case "$type" in
    L)
      ln -s $arg1 /dev/$name
      ;;
    D)
      mkdir -p /dev/$name
      ;;
    M)
      mknod /dev/$name $arg1
	  chmod 600 /dev/$name
      ;;
    *)
      echo "unparseable line ($type $name $arg1)"
      ;;
    esac
  done
}

# When modifying this script, do not forget that between the time that
# the new /dev has been mounted and udevstart has been run there will be
# no /dev/null. This also means that you cannot use the "&" shell command.

	start_bootchart

if [ -x /sbin/udevstart ]
then
	. /etc/udev/udev.conf
    ACTION=add
    echo -n "Mounting a tmpfs over /dev..."  
    mount -n -o size=1M,mode=0755 -t tmpfs none /dev  
    echo "done."  
    echo -n "Creating device nodes... "
	/sbin/udevstart
	echo -n " and some more.."
    make_extra_nodes
    echo "done."
fi

mount_devpts

chroot /mnt/initfs/ /usr/bin/retutime -i || true

hostname -F /etc/hostname
ifup lo &

echo /sbin/udevsend > /proc/sys/kernel/hotplug

#: > /var/run/utmp
#chmod 664 /var/run/utmp
#chgrp utmp /var/run/utmp

cat /proc/mounts > /etc/mtab

echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects 
echo 0 > /proc/sys/net/ipv4/conf/default/accept_redirects
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

exit 0
