#! /bin/sh
#
# mountall	Mount all filesystems.
#

. /etc/default/rcS

[ "$VERBOSE" != no ] && echo "Mounting local filesystems..."
# mount root and /proc
mount -t proc /proc
mount -o remount,rw /
mount -t sysfs /sys

# extract compressed files for jffs2
FS_TYPE=`mount | /usr/bin/awk '/mtdblock/{print $5}'`
if [ "$FS_TYPE" = "jffs2" ]; then
	[ "$VERBOSE" != no ] && echo "Extracting compressed files......"

	EXTRACT_MP=/extract
	mount -t tmpfs -o size=8M tmpfs $EXTRACT_MP

	for file in `(cd /bz_file; ls *.tar.bz2)`; do
		dir=`echo $file | sed 's/.tar.bz2//g'`
		(cd $EXTRACT_MP; bzcat /bz_file/$file | tar -xf -)
	done

	(cd $EXTRACT_MP; chown -R 0:0 *)
fi

# mount a writable filesystem on /tmpfs
[ "$VERBOSE" != no ] && echo "Mounting temp filesystems..."
TMP_MP=/tmpfs
mount -t tmpfs -o size=512M tmpfs $TMP_MP
mkdir $TMP_MP/tmp; chmod 1777 $TMP_MP/tmp
(cd $TMP_MP; mkdir mnt mnt/pool mnt/snap mnt/dom root var var/lock var/run var/spool var/tmp)

# restore configuration from NVRAM
#cp /etc/shadow.clean $TMP_MP/etc/shadow
#/usr/bin/use_cfg_passwd
#/usr/bin/load_cfg_file TZ auto-snap.conf mail.conf snmp.conf resolv.conf

: exit 0

