#!/bin/sh
# netapp_init_netboot (modified from netapp_init) :
# The SP will now be running entirely from a RAM based root-fs. This
# will facilitate in-place updates of the SP's file system while it
# is running, giving the advantages of having the initrd mechanism
# and that of having the JFFS2 mechanism with 25% less RAM utilization

echo "Starting netapp_init_netboot process"

if [ -L "tmp" ]
then
	rm -rf tmp
fi

if [ -d var/tmp ]
then
	rm -rf var/tmp
fi

if [ -d var/log ]
then
	rm -rf var/log
fi

if [ -d newroot ]
then
	rmdir newroot
fi

# Creating all the other necessary dirs in /
mkdir tmp
mkdir tmp/oem
mkdir tmp/auth
mkdir tmp/firmware
mkdir tmp/firmware/battery
mkdir var/dhcp
mkdir var/log
mkdir install_tmp
cp -a install/Metadata install_tmp/.
rm -rf install
mkdir install
cp -a install_tmp/. install/.
rm -rf install_tmp

# Used to check the firmware type
touch /var/run/netboot_fw

# Change permissions as needed
chmod a+rwx netapp
chmod a+rwx netapp/run
chmod a+rwx tmp
chmod a+rwx tmp/oem
chmod a+rwx tmp/firmware
chmod a+rwx tmp/firmware/battery

# Mounting /proc
mount /proc
# Mounting /sys
mount -t sysfs sysfs /sys
# Mount /dev/pts
mount -t devpts devpts /dev/pts -o gid=5,mode=620

exec /sbin/init

# This shouldn't return
exit
