#!/bin/bash export LC_ALL=C source /etc/conf.d/usbipdevd # some sane defaults [[ -z ${USBIP_POLLING_TIME} ]] && USBIP_POLLING_TIME="10" # version 0.1.7, no parseable list cmd if [[ -x /usr/bin/bind_driver ]] then BINDCMD="/usr/bin/bind_driver " else BINDCMD="/usr/sbin/usbip_bind_driver" fi while true do # version 0.1.7, no parseable list cmd if [[ ${BINDCMD} = /usr/bin/bind_driver ]] then BUSID=$(${BINDCMD} --list | grep -i "${USBIP_DEVICE_ID}" | sed 's:.*busid\ \([0-9].*\)\ (.*:\1:') # sanitizing syntax-highlighting ) BUSBINDING=$(${BINDCMD} --list | grep -A1 "${USBIP_DEVICE_ID}" | grep -- '->' | sed 's:.*->\ \(.*\):\1:') else BUSID=$(${BINDCMD} --list | grep "${USBIP_DEVICE_ID}" | cut -d'#' -f1 | sed 's:.*=\(.*\):\1:') BUSBINDING=$(${BINDCMD} --list | grep "${USBIP_DEVICE_ID}" | cut -d'#' -f3 | sed 's:.*=\(.*\):\1:') fi if [[ -n ${BUSID} ]] then # abort here if the busid is the same, because the client connection is lost on new exports case ${BUSBINDING} in usbip) echo "USBID is the same; nothing changed" ;; none) echo "Exporting USB Device with ID ${BUSID}" ${BINDCMD} --usbip ${BUSID} ;; *) echo "Warning: unkown BUSBINDING '${BUSBINDING}' of BUSID '${BUSID}'" ;; esac else echo "USB Device '${USBIP_DEVICE_ID}' not found ..." fi sleep ${USBIP_POLLING_TIME} done