#!/bin/bash

#set -x
bind_usb() {
  echo "$1" >/sys/bus/usb/drivers/usb/bind
}

unbind_usb() {
  echo "$1" >/sys/bus/usb/drivers/usb/unbind
}

for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev | grep mouse); do
    (
        syspath="${sysdevpath%/dev}"
        #echo $syspath
        devname="$(udevadm info -q name -p $syspath)"
        [[ "$devname" == "bus/"* ]] && exit
        eval "$(udevadm info -q property --export -p $syspath)"
        [[ -z "$ID_MODEL_ID" ]] && exit
        #echo "/dev/$devname - $ID_MODEL_ID"
        port=`grep $ID_MODEL_ID /sys/bus/usb/devices/*/idProduct | cut -d'/' -f6`
        #echo $port
        unbind_usb "$port"
        sleep 0.1 # enable delay here
        bind_usb "$port"
    )
done
