Update for new upstream release.
[sapphire-remote.git] / sapphire_startup.sh
1 #!/bin/bash
2 #
3 # Some distros seem to be building the hid-topseed driver into
4 # the core kernel image, rather than leaving as a loadable module.
5 #
6 # So, for our sapphire driver to bind to a device,
7 # we first have to get the hid-topseed driver to unbind from it.
8 #
9 TOPSEED=/sys/bus/hid/drivers/topseed
10 SAPPHIRE=/sys/bus/hid/drivers/sapphire
11 #rmmod hid-topseed      &>/dev/null
12 modprobe sapphire       &>/dev/null
13
14 # Transfer control of devices bound to hid-topseed over to sapphire
15 if [ -d $SAPPHIRE -a -e $TOPSEED/unbind ]; then
16         cd $TOPSEED
17         for dev in [0-9]*[-0-9A-F] ; do
18                 if [ -e "$dev" ]; then
19                         echo "$dev" > unbind
20                         echo "$dev" > $SAPPHIRE/bind
21                 fi
22         done
23 fi
24 rmmod hid-topseed       &>/dev/null
25
26 #
27 # Ubuntu/Mint kernels (and likely others too) don't like it
28 # when we unload and reload the sapphire driver.
29 # They disable the USB IR receiver and fail to reenable it.
30 # The workaround below seems to restore functionality.
31 #
32 cd $SAPPHIRE || exit 1
33 for dev in [0-9]*[0-9A-F] ; do
34         if [ -e "$dev" ]; then
35                 if cd -P "$dev/../.." ; then
36                         if [ -e authorized ]; then
37                                 echo 0 > authorized
38                                 echo 1 > authorized
39                         fi
40                         cd - >/dev/null
41                 fi
42         fi
43 done
44 [ -e /etc/sapphire.keymap -a -x /usr/local/bin/sapphire_keymap.sh ] && /usr/local/bin/sapphire_keymap.sh
45 exit 0