#!/bin/sh

# Find the a USB dir for a given manufacturer and product.
# Returns usb dir under /usr/bus/usb/devices if successful,
# else returns an empty string and an error if none.

# Optional 'sloppy' mode that will match either/or,
# eg for the K8055 board where randomly one or oher can go AWOL.
sloppy=false
con="-a"
if [ "x$1" = "x-sloppy" ]; then
    sloppy=true
    con="-o"
    shift
fi

# Arg 1 is the manufacturer.
# Arg 2 is the product.
# Quote the args if there are embedded spaces.

for d in /sys/bus/usb/devices/*/. ;
    do
      if [ \( -f $d/manufacturer -a "x`cat $d/manufacturer`" = "x$1" \) $con \
	   \( -f $d/product -a "x`cat $d/product`" = "x$2" \) ]; then
	  echo $d
	  exit 0
      fi
    done 2> /dev/null

# Exit silently but with an error if we can't find anything suitable.
exit 1
