#!/bin/sh

# starts the application
StartApp() {

	if [ -x "/home/smc/startup" ]
	then
		cd /home/smc
		su -l -c ./startup smc
	elif [ -x "/home/smc0/startup" ]
	then
		cd /home/smc0
		su -l -c ./startup smc0
	else
		echo "S98-smc: no application available to be started"
	fi
	
}

# make sure the XDATA directory exists and is mounted if there
# is a 3rd partition
MountXDATA() {

	MNTDEV=/dev/mmcblk0p3
	MNTDEVTYPE=`blkid -s TYPE -o value $MNTDEV`
	MNTPT=/mnt/XDATA
	
	if [ ! -b "$MNTDEV" ]
	then
		echo "$MNTDEV does not exist, so storage at $MNTPT is not available"
	
	elif [ -z "$MNTDEVTYPE" ]
	then
		echo "$MNTDEV partition type cannot be determined: storage at $MNTPT is not available"
	
	elif [ "$MNTDEVTYPE" != "ext3" ]
	then
		echo "$MNTDEV partition type is \"$MNTDEVTYPE\" not ext3: storage at $MNTPT is not available"
	
	else 
	    if [ ! -d "$MNTPT" ]
	    then
	        echo "Warning: $MNTPT does not exist, it is being created"
                mkdir /mnt/XDATA
	    fi
	
	    MOUNTSTR=`mount | grep $MNTDEV`
	    MOUNTSTR2=""
	
	    if [ ! -z "$MOUNTSTR" ]
	    then
	        MOUNTSTR2=`echo $MOUNTSTR | grep $MNTPT`
	
	        if [ -z "$MOUNTSTR2" ]
	        then
	            echo "Warning: $MNTDEV is not mounted at $MNTPT, it will be remounted"
	            umount "$MNTDEV"
	        else
	            echo "$MNTDEV is already mounted at $MNTPT"
	        fi
	    fi

            if [ -z "$MOUNTSTR2" ]
            then
                #echo "Mounting $MNTDEV at $MNTPT"
                mount "$MNTDEV" "$MNTPT"
            fi

	fi

	return 0	
}

MountXDATA

# to start the application, uncomment the next line
StartApp
