#!/bin/bash source /etc/conf.d/usbipdevd source /usr/lib/alxconfig-ng/functions/mysqlfunctions CLIENTIP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') # create a new ip entry if none exist if [[ -z $(mysqldo "select ip from clients where ip='${CLIENTIP}'") ]] then mysqldo "insert into clients (ip,connected) values('${CLIENTIP}','0')" fi while true do BUSID=$(bind_driver --list | grep -i ${USBIP_DEVICE_ID} | cut -d ' ' -f4) if [[ -n ${BUSID} ]] then echo "BUSID: ${BUSID}" # abort if nothing has changed if [[ $(mysqldo "select connected from clients where ip='${CLIENTIP}'") = 1 ]] && [[ $(mysqldo "select busid from clients where ip='${CLIENTIP}'") = ${BUSID} ]] then echo "USBID is the same; nothing changed" else echo "exporting Logitech Pen with ID ${BUSID}" bind_driver --usbip ${BUSID} mysqldo "update clients set connected='1', busid='${BUSID}' where ip='${CLIENTIP}'" fi else echo "No Logitech Pen (${USBIP_DEVICE_ID}) found ..." mysqldo "update clients set connected='0', busid='${BUSID}' where ip='${CLIENTIP}'" fi sleep ${USBIP_WAIT_TIMEOUT} done