- auto-export on host when a defined usb-device has been plugged
- auto-attachment on client when a disappeared remote-device is available, again.
README.md
[email protected]
[email protected]
- usbip
- lsusb (pre-installed on most distributions)
install the systemd-files as root.
usb-host:
install -m 644 -o root -g root -t /lib/systemd/system/ /your/filepath/[email protected]
usb-client:
install -m 644 -o root -g root -t /lib/systemd/system/ /your/filepath/[email protected]
execute on both sides:
systemctl daemon-reload
To export a pysical usb-device you have to determine the vendor and product id of your device with
lsusb
the format is [idVendor]:[idProduct] like: 301b:56f1
Now, you're able to export/provide your usb-device.
Syntax:
usbip-export@[idVendor]:[idProduct].service e.g:
systemctl start usbip-export@301b:56f1
At last, you're able to attach the usb-device from the remote IP on a client.
Syntax:
[email protected]@[host]_[idVendor]:[idProduct].service e.g.:
systemctl start [email protected]_301b:56f1
usbip-export human readable relevant code parts:
starting:
# bind
dev=%i
statePrev=1
state=$(/usr/bin/lsusb|grep -q $dev; echo $?)
while true; do
if [ $state -ne $statePrev ]; then
/usr/sbin/usbip bind --busid=$(/usr/sbin/usbip list -p -l | grep "$dev" | cut '-d#' -f1 | cut '-d=' -f2 | tr -d '[:space:]')
fi
sleep 1
statePrev=$state
state=$(/usr/bin/lsusb|grep -q $dev; echo $?)
done
stopping:
# unbind
/usr/sbin/usbip unbind --busid=$(/usr/sbin/usbip list -p -l | grep "%i" | cut '-d#' -f1 | cut '-d=' -f2 | tr -d '[:space:]')
killall usbipd
usbip-attach human readable relevant code parts:
starting:
# attach
host=$(echo %i|cut '-d_' -f1|tr -d '[:space:]')
dev=$(echo %i|cut '-d_' -f2|tr -d '[:space:]')
while true; do
/usr/bin/lsusb | grep -q $dev
if [ $? -ne 0 ]; then
busid=$(/usr/sbin/usbip list -p -r $host | grep $dev | cut '-d:' -f1 | xargs echo -n)
/usr/sbin/usbip port|grep -q $dev
if [ $? -ne 0 ]; then
/usr/sbin//usr/sbin/usbip attach --remote=$host --busid=$busid
fi
fi
sleep 1
done
stopping:
# detach
dev=$(echo %i|cut '-d_' -f2|tr -d '[:space:]')
/usr/sbin/usbip port | while read i; do
echo $i | grep -q $dev
if [ $? -eq 0 ]; then
/usr/sbin/usbip detach --port=$port
fi
echo $i | grep -q Port
if [ $? -eq 0 ]; then
port=$(echo $i | cut '-d ' -f2 | cut '-d:' -f1 | tr -d '[:space:]')
fi
done
Tags: usb
usbip
tcp
teleport
gateway
ip
network
systemd
service
remote
deploy
export
In the "[email protected]" both ExecStart and ExecStop look like cut of at the end.
I recreated it from the explanation part of you port:
[email protected]
PS: Never copy from nano always use cat xD