6 |
|
|
7 |
# some sane defaults |
# some sane defaults |
8 |
[[ -z ${USBIP_POLLING_TIME} ]] && USBIP_POLLING_TIME="10" |
[[ -z ${USBIP_POLLING_TIME} ]] && USBIP_POLLING_TIME="10" |
9 |
[[ -z ${USBIP_TEMP} ]] && USBIP_TEMP="/var/lib/usbipdevd" |
|
10 |
install -d ${USBIP_TEMP} |
# version 0.1.7, no parseable list cmd |
11 |
|
if [[ -x /usr/bin/bind_driver ]] |
12 |
|
then |
13 |
|
BINDCMD="/usr/bin/bind_driver" |
14 |
|
else |
15 |
|
BINDCMD="/usr/sbin/usbip_bind_driver" |
16 |
|
fi |
17 |
|
|
18 |
while true |
while true |
19 |
do |
do |
20 |
BUSID=$(bind_driver --list | grep -i "${USBIP_DEVICE_ID}" | sed 's|.*busid\ \([0-9].*\)\ (${USBIP_DEVICE_ID}).*|\1|') |
# version =<0.1.7 has no parseable list cmd |
21 |
|
if [[ -z $(${BINDCMD} --help | grep -- --list2) ]] |
22 |
|
then |
23 |
|
BUSID=$(${BINDCMD} --list | grep -i "${USBIP_DEVICE_ID}" | sed 's:.*busid\ \([0-9].*\)\ (.*:\1:') # sanitizing syntax-highlighting ) |
24 |
|
BUSBINDING=$(${BINDCMD} --list | grep -A1 "${USBIP_DEVICE_ID}" | grep -- '->' | sed 's:.*->\ \(.*\):\1:') |
25 |
|
else |
26 |
|
BUSID=$(${BINDCMD} --list2 | grep "${USBIP_DEVICE_ID}" | cut -d'#' -f1 | sed 's:.*=\(.*\):\1:') |
27 |
|
BUSBINDING=$(${BINDCMD} --list2 | grep "${USBIP_DEVICE_ID}" | cut -d'#' -f3 | sed 's:.*=\(.*\):\1:') |
28 |
|
fi |
29 |
|
|
30 |
if [[ -n ${BUSID} ]] |
if [[ -n ${BUSID} ]] |
31 |
then |
then |
32 |
# abort here if the busid is the same, because the client connection is lost on new exports |
# abort here if the busid is the same, because the client connection is lost on new exports |
33 |
if [[ -f ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_} ]] && |
case ${BUSBINDING} in |
34 |
[[ ${BUSID} = $(< ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_}) ]] |
usbip) echo "USBID is the same; nothing changed" ;; |
35 |
then |
none) |
36 |
echo "USBID is the same; nothing changed" |
echo "Exporting USB Device with ID ${BUSID}" |
37 |
else |
${BINDCMD} --usbip ${BUSID} |
38 |
echo "Exporting USB Device with ID ${BUSID}" |
;; |
39 |
bind_driver --usbip ${BUSID} |
*) echo "Warning: unkown BUSBINDING '${BUSBINDING}' of BUSID '${BUSID}'" ;; |
40 |
echo "${BUSID}" > ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_} |
esac |
|
fi |
|
41 |
else |
else |
42 |
echo "USB Device '${USBIP_DEVICE_ID}' not found ..." |
echo "USB Device '${USBIP_DEVICE_ID}' not found ..." |
43 |
fi |
fi |
44 |
|
|
45 |
sleep ${USBIP_WAIT_TIMEOUT} |
sleep ${USBIP_POLLING_TIME} |
46 |
done |
done |