#!/bin/sh

source ${CONF_DIR}/config;
ERR=0;

# If the root filesystem is in RAM it will not have anything. We must
# fill it with a tar file that is assumed to be in the root of the
# initrd, be compressed using gzip and be named rootfs.tgz
if [ "X${CONFIG_ROOTFS_DEVICE_RAM}" == "Xy" ] && [ -r /rootfs.tgz ]; then
	/bin/mount /rootfs -o remount,rw
	if [ "X$?" != "X0" ]; then
		echo "ERROR: failed to remount rootfs read-write.";
		ERR=1;
	fi
	echo -ne "Installing root filesystem, please wait ... ";
	/bin/tar -zxf /rootfs.tgz -C /rootfs
	if [ "X$?" != "X0" ]; then
		echo -ne "ERROR\nFailed to create RAM root filesystem.\n";
		ERR=2;
	fi
	echo -ne "done\n";
	/bin/mount /rootfs -o remount,ro
	if [ "X$?" != "X0" ]; then
		echo "ERROR: failed to remount rootfs read-only.";
		ERR=3;
	fi
fi

exit $ERR;
