#!/bin/bash

export DISPLAY=:0

exec &> /tmp/hotplug.log;

umask 0

add() {
	case "$SUBSYSTEM" in
		block)
			mknod /dev/$DEV b $MAJOR $MINOR
			if [ `echo $DEV | wc -c` == 5 ]; then
			mkdir -p /mnt/$DEV
			mount /dev/$DEV /mnt/$DEV
			if [ ! $? -eq 0 ]; 
				then
					notify-send 'Device Found' "ERROR: /mnt/$DEV Not mounted" -i /usr/share/plate/chrome/content/image/kcmdevices.png -u critical
				else
					#/usr/bin/firefox file:///media/$DEV/ &
					notify-send 'Device Found' "/mnt/$DEV Mounted" -i /usr/share/plate/chrome/content/image/kcmdevices.png -u critical 
				fi
			fi
			;;
		*)
			mknod /dev/$DEV c $MAJOR $MINOR
	esac
}

remove() {
	umount /mnt/$DEV
	rm /dev/$DEV
	notify-send 'Device Removal' "/mnt/$DEV Unmounted" -i /usr/share/plate/chrome/content/image/kcmdevices.png -u critical
}

DEV=`basename $DEVPATH`

case "$ACTION" in
	add)
		add
		;;
	remove) 
		remove
		;;
	*)
		echo $0 $@ >> /tmp/hotplug.log
esac
