#!/bin/sh

MOUNT_POINT=/mnt/card
PRE_FIX="/dev/"
NUM="p1"
TEST_DEV=$PRE_FIX$MDEV$NUM

BOOTDEV=

tmp_str=$(cat /proc/cmdline)
tmp_str=${tmp_str#*root=}
tmp_str=${tmp_str%% *}

if [ "x${tmp_str%%k*}" == "x/dev/mmcbl" ]; then
	BOOTDEV=${tmp_str%%p*}
	if [ "x$BOOTDEV" == "x$PRE_FIX$MDEV" ]; then
		echo "skip boot device $BOOTDEV" > /dev/console
		exit
	fi
fi

if [ ! -f $MDEV ]; then
	if [ ! -d $MOUNT_POINT ]; then
		mkdir -p $MOUNT_POINT
	fi

	if [ ! -d $MOUNT_POINT ]; then
		echo "${MOUNT_POINT} can not create" > /dev/console
		exit
	fi

	echo "${MDEV} insert" > /dev/console
	sleep 1
	echo $TEST_DEV > /dev/console

	if [ -e $TEST_DEV ]; then
		echo "${MDEV} do not create" > /dev/console
		exit
	fi

	echo "start to mount ${MDEV} device" > /dev/console
	mount -t vfat -o iocharset=utf8,codepage=936 /dev/$MDEV $MOUNT_POINT
	if [ $? -eq 0 ]; then
		echo "mount ${MDEV} sdcard ok" > /dev/console
	else
		echo "mount ${MDEV} sdcard failed" > /dev/console
	fi
fi
