#!/bin/bash
#
# [Type]
# mount_added_command
#
# [Description]
# This script automatically imports stashes on inserted devices.
# Note that MOUNT_DIR refers to the directory of the mounted device in the
# "mount_*_command" commands.

case "$SCRIPT_TYPE" in

	# make sure the script only runs in the right slot
	mount_added_command)
	
		# contains the mounted drive a valid stash?
		if gnome-encfs-manager --checkstash "$MOUNT_DIR" >/dev/null; then
		
			# Is the stash already registered in GEncfsM?
			if ! gnome-encfs-manager is_configured "$MOUNT_DIR" >/dev/null; then
			
				# Import the stash
				gnome-encfs-manager import_stash "$MOUNT_DIR" ":/`basename "$MOUNT_DIR"`"
				
				# Is it now in GEncfsM?
				if gnome-encfs-manager is_configured "$MOUNT_DIR" >/dev/null; then
				
					# Send some fancy notification
					notify-send --icon="gnome-encfs-manager" "`basename "$MOUNT_DIR"`" \
														"The stash was imported"
				fi
			fi
		fi
		;;
esac
