hostname 5300-RM
echo "Mounting RAM/pseudo 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 "Mounting config filesystem ..."
if ! mount -t jffs2 /dev/flash/configblock /etc/config
then
	echo "Cannot mount /etc/config as jffs2, reformatting..."
	flash_erase /dev/flash/config 0 0
	echo "Mounting config filesystem after reformat ..."
	if ! mount -t jffs2 /dev/flash/configblock /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

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

cat /etc/motd

exit 0
