#!/bin/sh
num=0
num=`if [ -f /proc/mtd ]; then cat /proc/mtd | grep \"app\" | awk -F' ' '{print $1}' | tr -d 'mtd' | tr -d ':'; fi`;
if [ ! -z "$num" ]; then
	echo "mount app partition mtdblock$num"
	mount -t jffs2 /dev/mtdblock$num /mnt/app
else
	if [ "$NVT_ROOTFS_TYPE" == "NVT_ROOTFS_TYPE_EXT4" ]; then
		mount -t vfat /dev/mmcblk2p2 /mnt/cache
	fi
	mount -t ext4 /dev/mmcblk2p3 /mnt/app

	if [ ! mount -t ext4 /dev/mmcblk2p5 /mnt/emmc1 ]; then
		echo yes | mke2fs -T ext4 /dev/mmcblk2p5
	fi
	mount -t ext4 /dev/mmcblk2p5 /mnt/emmc1
fi

CONFIGS_DIR=/mnt/app/configs
CONFIGS_FILE=/mnt/app/configs/configs.ini

if [ ! -f $CONFIGS_DIR ]; then
	mkdir $CONFIGS_DIR
fi

if [ ! -e $CONFIGS_FILE ]; then
    cp /etc/default_configs.ini $CONFIGS_FILE
fi

CONFIGS_NETWORK_FILE=/mnt/app/configs/configs_network.ini
if [ ! -e $CONFIGS_NETWORK_FILE ]; then
    cp /etc/default_configs_network.ini $CONFIGS_NETWORK_FILE
fi
