hostname 8300

echo "Mounting filesystems..."
mount -t proc proc /proc
mount -t sysfs sys /sys
mkdir -m 755 /dev/pts
mount -t devpts devpts /dev/pts
mount -t tmpfs -o size=8M tmpfs /tmp
mount -t tmpfs -o size=8M tmpfs /var
mkdir -m 1777 /var/tmp
mkdir -m 755 /var/log
mkdir -m 755 /var/run
mkdir -m 1777 /var/lock
mkdir -m 755 /var/empty
mkdir -m 755 /var/mnt
# init devices before we need any
cp -ra /lib/udev/devices/. /dev

echo "Loading crypto modules..."
modprobe ocf
modprobe mv_cesa
modprobe cryptodev

echo "Initializing network interfaces..."
echo 1 >/proc/sys/net/ipv4/conf/all/promote_secondaries
ifconfig lo 127.0.0.1
setmac -n 3
/etc/switch.sh

echo "Mounting config filesystem ..."
if ! mount -t ubifs ubi0:config /etc/config
then
	echo "Cannot mount /etc/config as ubifs, reformatting..."
	flash_erase /dev/flash/config 0 0
	echo "Mounting config filesystem after reformat..."
	if ! mount -t ubifs ubi0:config /etc/config
	then
		echo "Failed to mount flash based config filesystem"
		echo "Using tmpfs for /etc/config."
		mount -t tmpfs -o size=4M tmpfs /etc/config
	fi
	touch /etc/config/.init
fi
[ "$(echo /etc/config/*)" = '/etc/config/*' ] && touch /etc/config/.init

if [ -f /etc/config/.init ]; then
	echo "Factory defaulting config ..."
	find /etc/config -name '*' | grep -v '/etc/config$' | xargs rm -rf
	cp -ra /etc/default/. /etc/config/.
fi

echo "Running init scripts..."
for i in /etc/init.d/S*
do
	printf "Starting %s:" `expr "$i" : '.*/S..\(.*\)$'`
	$i start
done

cat /etc/motd

exit 0
