#!/bin/sh

mount -w /proc /proc -t proc
if [ ! -f /etc/rc.d/rc.rofilesys -o ! -x /etc/rc.d/rc.rofilesys ];then   
    mount -o remount -w %root% /
fi
    mount -o remount -w %root% /

mkfs -t ext2 /dev/ram0 > /dev/null 2>&1
mount -t ext2 /dev/ram0 /mnt/ram0
tar xvfz /root/var.tar.gz -C /mnt/ram0 > /dev/null 2>&1
mkdir /mnt/ram0/tmp
sync

# Set the hostname
if [ -f /etc/sysconfig/network ]; then
    . /etc/sysconfig/network
else
    HOSTNAME=localhost
fi

hostname ${HOSTNAME}

# Run all rc.* files apart rc.local in /etc/rc.d
cd /etc/rc.d
for I in rc.rofilesys rc.modules rc.serial;do
  if [ -f ./$I ];then
    if [ -x ./$I ];then
      echo "*** Running $I"
      ./$I
    fi
  fi
done

#echo -n "Mounting local file-systems... "
#mount -a -t nonfs
#echo done

# Start all files in /etc/rc.d/init.d
cd /etc/rc.d/init.d
for I in *;do
  if [ -f ./$I ];then
    if [ -x ./$I ];then
      echo "*** Attempting to start $I"
      ./$I start
    fi
  fi
done

#echo -n "Mounting remote file-systems... "
#mount -a -t nfs
#echo done

# Finish by running rc.local
cd /etc/rc.d
if [ -f "./rc.local" ];then
  if [ -x "./rc.local" ];then
    echo "*** Running rc.local"
    ./rc.local
  fi
fi

mount -o remount -r %root% /
