#!/bin/sh

# sixad-bin wrapper for udev
# written by smoku

hci_check () {
hcitool info $1 | grep -q -e 'Manufacturer: Cambridge Silicon Radio'
}

sixad_already_running_check () {
pgrep sixad-bin > /dev/null
}

bluetoothd_check () {
pgrep bluetoothd > /dev/null
}

modprobe_check () {
/sbin/modprobe uinput && /sbin/modprobe joydev
}

# Only start udev action if a Sixaxis or Keypad is detected
if hci_check $1 && modprobe_check && bluetoothd_check; then
	if ! sixad_already_running_check; then
		. /etc/default/sixad
		/usr/sbin/sixad-bin $Enable_leds $LED_js_n $LED_n $LED_plus $LED_anim $Legacy &
	fi
fi
