#!/bin/sh

MMC_DEV="mmcblk0p1"
MMC_DIR="/mnt/mmc"

connect_stat=`grep $MMC_DEV /proc/partitions | wc -l`
mount_stat=`grep $MMC_DEV /proc/mounts | wc -l`

if [ ${connect_stat} -eq 1 ]
then
	#
	# MMC connected but not mounted.
	#
	if [ ${mount_stat} -eq 0 ]
	then
		if [ -b /dev/${MMC_DEV} ]
		then
			echo "Mounting SD card ..."
		
			[ -d ${MMC_DIR} ] || mkdir -p ${MMC_DIR}
			mount -tvfat /dev/${MMC_DEV} ${MMC_DIR}
		else
			echo "Not SD card device."
		fi
#	else	# Already mounted.
#		# Do nothing
	fi
else
	#
	# MMC disconnected but still mounted.
	#
	if [ ${mount_stat} -eq 1 ]
	then
		echo "Unmounting SD card ..."
	
		umount ${MMC_DIR}
#	else	# Not mounted.
#		# Do nothing
	fi
fi
