#!/bin/bash

MOUNT_FLAG=""
auto_mount() {
	# Do not mount root partition automatically
	if [ ${sd_node}p1 == /dev/${1} ] || [ ${sd_node}p2 == /dev/${1} ] || [ ${sd_node}p3 == /dev/${1} ] || [ ${sd_node}p4 == /dev/${1} ]; then
		return
	fi
	/bin/mkdir -p /media/sd-$1
	/bin/ln -s /media/sd-$1 /mnt/sd-$1
	/bin/mount -o $2$MOUNT_FLAG /dev/$1 /media/sd-$1
}

# Get rootfile system partition from cmdline. e.g. /dev/mmcblk0p2
root_part=$(cat /proc/cmdline)
root_part="${root_part##*root=}"
root_part="${root_part%% *}"

# Strip the partition number to fetch sd node e.g. /dev/mmcblk0
sd_node="${root_part%%p2}"

auto_mount $1 $2
