-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathusbip-export@.service
20 lines (16 loc) · 995 Bytes
/
usbip-export@.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Export devices by calling this service with:
# systemctl start usbip-export@[idVendor]:[idProduct].service
# refer dmesg or lsusb to catch your preferred device
# https://gist.github.com/peedy2495/e9ed5938bf0c2e3983185d0c9622e97d
[Unit]
Description=exporting device via usbip host daemon
After=network-online.target
[Service]
Type=forking
ExecStart=/bin/sh -c "modprobe usbip_core && modprobe usbip_host && modprobe vhci-hcd && usbipd -D"
ExecStartPost=/bin/sh -c "dev=%i; statePrev=1; state=$(/usr/bin/lsusb|grep -q $dev; echo $?); while true; do if [ $state -ne $statePrev ]; then usbip bind --busid=$(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 &"
ExecStop=/bin/sh -c "usbip unbind --busid=$(usbip list -p -l | grep "%i" | cut '-d#' -f1 | cut '-d=' -f2 | tr -d '[:space:]'); killall usbipd"
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target