#!/bin/bash

# This script is responsible for causing the AMIVmouse Xinput driver to wake
# up and rescan the devices.  It's intended to be called when a hotplug event
# happens, which means it needs to have a config line in
# /etc/hotplug/usb.usermap to get control when the event happens.  The
# interface to the driver is through a fifo that should already exist and be
# opened by the X driver.  The only supported command we can send the driver
# is "add" right now.

# If we don't have the fifo, we'd better create it.
if [ ! -p /tmp/AMIVmouseHP ]; then
	mkfifo --mode=600 /tmp/AMIVmouseHP
fi
 
# The only action we should get is add.  If we get anything else,
# I don't know what it is, and don't want to risk confusing the
# driver with it.
if [ $ACTION = "add" ]; then
	# Send the action to the fifo, where the driver can read it
	echo $ACTION >> /tmp/AMIVmouseHP

	# Restart hostmouse - it will do it's own rescan when it restarts
	service virtualmouse restart
fi
