#!/bin/sh

module="mmcdev"
device="mmcdev"
group="root"
mode="664"

MMC_MODULE_PATH=char/mmc/era/shared/driver/linux/$module.o
PATH_MODIFIER=""
KERNEL=$(uname -r)

if [ "$(uname -r | grep -E "^2.2")" = "" ]; then
  PATH_MODIFIER=kernel/drivers
fi

if [ "$(grep mmcdev /proc/devices)" = "" ]; then
	# insert the module in executing kernel
	/sbin/insmod -f /lib/modules/$KERNEL/$PATH_MODIFIER/$MMC_MODULE_PATH $* || exit 1
fi

# get the major number automatically assigned for us
major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}"`

# Remove stale nodes and replace them, then give gid and perms
rm -f /dev/${device}
mknod /dev/${device} c $major 0
chgrp $group /dev/${device} 
chmod $mode  /dev/${device}
