#!/bin/sh # # DIGImend specific driver rebinding script. To be invoked by udev. # Author: Nikolai Kondrashov # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Write a string to a file, ignoring ENODEV. write_ignore_enodev() { local str="$1" local path="$2" local output="" # Write the string with tee, capturing error output if ! output="`(echo \"$str\" | tee \"$path\" >/dev/null) 2>&1`"; then # Raise anything except ENODEV if [ "${output##*: }" != "No such device" ]; then echo "$output" >&2 return 1 fi fi } ( set -e -u progname="`basename \"$0\"`" id="`basename $DEVPATH`" current_driver_path="`readlink -v -f /sys${DEVPATH}/driver`" if [ -e "$current_driver_path" ]; then current_driver="`basename \"$current_driver_path\"`" else current_driver="" fi specific_module="`modprobe -R $MODALIAS`" # Assume the driver would be called the same as module, # but without the "hid_" or "hid-" prefix specific_driver="${specific_module#hid[_-]}" specific_driver_path="/sys/bus/hid/drivers/$specific_driver" if [ "$current_driver" != "$specific_driver" ]; then logger -p daemon.notice -t "$progname" "rebinding $DEVPATH" # Ensure the specific driver module is loaded modprobe "$specific_module" # Unbind from the current driver, if any if [ -n "$current_driver" ]; then write_ignore_enodev "$id" "$current_driver_path/unbind" fi # Bind to the specific driver write_ignore_enodev "$id" "$specific_driver_path/bind" fi ) 2>&1 | logger -p daemon.warning -t "$progname"