#!/bin/bash export LC_ALL=C source /etc/conf.d/usbipdevd # some sane defaults [[ -z ${USBIP_POLLING_TIME} ]] && USBIP_POLLING_TIME="10" [[ -z ${USBIP_TEMP} ]] && USBIP_TEMP="/var/lib/usbipdevd" install -d ${USBIP_TEMP} while true do BUSID=$(bind_driver --list | grep -i "${USBIP_DEVICE_ID}" | sed 's|.*busid\ \([0-9].*\)\ (${USBIP_DEVICE_ID}).*|\1|') if [[ -n ${BUSID} ]] then # abort here if the busid is the same, because the client connection is lost on new exports if [[ -f ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_} ]] && [[ ${BUSID} = $(< ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_}) ]] then echo "USBID is the same; nothing changed" else echo "Exporting USB Device with ID ${BUSID}" bind_driver --usbip ${BUSID} echo "${BUSID}" > ${USBIP_TEMP}/${USBIP_DEVICE_ID//:/_} fi else echo "USB Device '${USBIP_DEVICE_ID}' not found ..." fi sleep ${USBIP_WAIT_TIMEOUT} done