-
Notifications
You must be signed in to change notification settings - Fork 2
/
usb_manager.v1.plg
359 lines (256 loc) · 9.21 KB
/
usb_manager.v1.plg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "usb_manager">
<!ENTITY author "SimonFair">
<!ENTITY version "2022.05.20">
<!ENTITY launch "USBManagerSettings">
<!ENTITY gitURL "https://raw.githubusercontent.com/SimonFair/USB_Manager/master">
<!ENTITY pluginURL "&gitURL;/usb_manager.v1.plg">
<!ENTITY supportURL "https://forums.unraid.net/topic/100511-plugin-usbip-commands/">
<!ENTITY packages "/boot/config/plugins/&name;/packages">
<!ENTITY md5 "ed84dcedb3a8fabd407e56545c22cc52">
]>
<PLUGIN name="&name;"
author="&author;"
launch="&launch;"
version="&version;"
pluginURL="&pluginURL;"
support="&supportURL;"
icon="fa-usb"
min="6.8.0">
<CHANGES>
##USB_Manager
###&version;
- Fix Possible race condition via PR from KnF thankyou.
2022.03.26
- Fix error trying to attach to VM that no longer exists.
- Add Eject symbol next to VM if it does not exists.
2022.03.13
- Fix RC3 issues
2022.01.21
- Reapply Changes of 2022.01.15
2022.01.21
- Revert to 2021.12.30 Version.
2022.01.15
- Chg Combine VM Name and Status. Status is now replaced with an icon.
- Add Slider for Serial Number to Hide Serial.
- Add Hover over on the Vendor:Product to show serial.
2022.01.09
- Add HUB processing. Enable via the configuration page. Allow you to define a port mapping on a hub.
When a device is connected to a hub it will be connected at plugin or VM start as defined on the port connection.
Cascaded hubs will need their own mapping.
- Add Inuse Processing. Plugin will report if a device is being used outside of USB Manager.
It will show Mounted devices on UD, devices in use within Unraid and devices used in a ZPool.
- Add Bluetooth controllers Identify with an icon.
- Chg Status is set to Green if connected and Red if used outside of USB Manager.
- Chg Show ProductID from Database if available.
- Chg Dashboard updated to show in use devices.
2021.12.30
- Fix to parent processing.
2021.12.28
- Chg Disable device mapping for Root Hubs and Hubs. Disable port mapping for Root Hub.
- Chg Detach button show next to connected port or device on the main line.
- Fix Buttons if Hotplug mapping used.
- Upd Status file to include new fields for future hub processing.
2021.12.12a
Revert Changes for 2021.12.12
2021.12.12
- Add Hub processing.You can define a port mapping for a hub. If connected or vm starts all devices on that hub will be connected to the VM. Will not process next level down hubs.
- Chg Disable device mapping for Root Hubs and Hubs. Disable port mapping for Root Hub.
- Chg Detach button show next to connected port or device on the main line.
- Fix Buttons if Hotplug mapping used.
- Note reboot or disconnect/reconnect of Hub may be required.
2021.09.18
- Code review and update.
2021.09.01
- Fix start of usbipd and load of modules on array start.
2021.08.01
- Code clean up
- Change to udev rules for 6.10+ support.
- Enable zebra strips on tables.
2021.07.27
- Fix Change Unraid Flash to Unraid in use on the hub lines on dashboard page.
- Chg Use Port as standard rather than Physical BUSI/Port.
2021.07.23
- Fix Disable roothub and hubs used for Unraid Flash device.
2021.07.10
- Add volume to device list in USBHotplug page.
2021.07.09a
- Add display of Hotplug Devices on main USB page and allow detach.
2021.07.09
- Fix Virsh error if both port and device mapping exist for a device a connection time.
- Add USB Manager Hotplug page on VM page, to enable change options in settings. Base code from DLandons Hot plug plugin. Addition support to show on USB page if mapping doesn't exist in next release.
2021.06.02a
- Fix table formatting if both port and device mappings for new volume column
- Add Log virsh calls.
2021.06.26
- Enhancement Show Volume for USB Storage Devices.
2021.06.20
- Enhancement enable port processing for mapping ports to VM at start.
- Update text on edit settings page to describe entry being changed.
2021.06.19
- Install QEMU hooks file code, thanks to ljm42 for code.
2021.06.08
- Fix USBIP command check.
2021.06.06
- Initial beta release.
If you are using USBIP-GUI continue to do so at this time. This plugin will supercede USBIP-GUI in the future and will migrate configurations.
USBIP-GUI and USB_Manager cannot co-exist. If you want to replace USBIP-GUI then uninstall first, Config files will remain on the flash drive you can copy them to usb_manager directory.
USBIP and USBIP-HOST module are not loaded by default. If you want to use them enable USBIP in the Settings and click the install button to install the additional plug.
</CHANGES>
<!--
The 'pre-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
# Check to see if new install.
if [ ! -d "/boot/config/plugins/&name;" ]
then
mkdir "/boot/config/plugins/&name;"
#Check to see if USBIP GUI exists
if [ -d "/boot/config/plugins/unraid.usbip-gui" ]
then
cp /boot/config/plugins/unraid.usbip-gui/*.cfg /boot/config/plugins/&name;/
mv /boot/config/plugins/&name;/unraid.usbip-gui.cfg /boot/config/plugins/&name;/&name;.cfg
plugin remove "usbip-gui.plg"
fi
fi
</INLINE>
</FILE>
<!--
Get the plugin bundle.
-->
<FILE Name="&packages;/&name;-&version;.txz" Run="upgradepkg --install-new &packages;/&name;*%&packages;/&name;-&version;.txz">
<URL>"&gitURL;/&name;-&version;.txz"</URL>
<MD5>&md5;</MD5>
</FILE>
<!--
The 'post-updgrade' script.
-->
<FILE Run="/bin/bash">
<INLINE>
echo "Removing previous versons now upgrade has completed."
echo
# Remove old 'bundle' files.
rm -f $(ls &packages;/*.txz 2>/dev/null | grep -v '&version;')
</INLINE>
</FILE>
<!--
USB_Manager background start script.
-->
<FILE Name="/tmp/start_usb_manager" Mode="0770">
<INLINE>
#!/bin/bash
# Copy configuration files to tmp file system.
/usr/local/emhttp/plugins/&name;/scripts/copy_config.sh 2>/dev/null
#Start USBIPD if required.
if [ ! -z "$(pidof emhttpd)" ]; then
/usr/local/emhttp/plugins/&name;/scripts/rc.&name; check_config 2>/dev/null
/usr/local/emhttp/plugins/&name;/scripts/rc.&name; USBMgrUpgradeConnectedStatus 2>/dev/null
fi
# Remove the background start script.
rm -f /tmp/start_usb_manager 2>/dev/null
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/&name;/&name;.cfg">
<INLINE>
<![CDATA[
]]>
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/&name;/remote_usbip.cfg">
<INLINE>
<![CDATA[
]]>
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/&name;/vm_mappings.cfg">
<INLINE>
<![CDATA[
]]>
</INLINE>
</FILE>
<!--
The 'post-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
# Define Functions
#Define Variables
KERNEL_V="$(uname -r)"
PACKAGE="usbip"
DL_URL="https://github.com/ich777/unraid-plugins-repo/releases/download/$KERNEL_V"
# Install the plugin bundle.
# Create plugin directory
mkdir /boot/config/plugins/&name; 2>/dev/null
mkdir /usr/local/emhttp/plugins/&name; 2>/dev/null
mkdir -p /tmp/&name;/config 2>/dev/null
#if [ ! -d "&packages;/${KERNEL_V%%-*}" ]; then
# mkdir -p "&packages;/${KERNEL_V%%-*}"
#fi
# move the rules file
#cp /usr/local/emhttp/plugins/&name;/99_persistent_usb_manager.rules /etc/udev/rules.d/
#chmod 644 -R /etc/udev/rules.d/99_persistent_usb_manager.rules 2>/dev/null
# copy the syslog rules config file
#cp /usr/local/emhttp/plugins/&name;/99_usb_manager_syslog.conf /etc/rsyslog.d/
#chmod 644 -R /etc/udev/rules.d/99_persistent_usb.rules 2>/dev/null
# Adjust plugin permissions.
chmod 755 -R /usr/local/emhttp/plugins/&name; 2>/dev/null
# Fix permissions of executable files
chmod +x /usr/local/emhttp/plugins/&name;/scripts/* /usr/local/emhttp/plugins/&name;/event/*
# Create a symlink to USB_Manager scripts.
ln -sf /usr/local/emhttp/plugins/&name;/scripts/rc.usb_manager /usr/local/sbin
# Copy Config to tmp and load modules.
at -M -f /tmp/start_usb_manager now 2>/dev/null
# Update QEMU Hooks file and udev rules.
/usr/local/emhttp/plugins/&name;/scripts/install.sh 2>/dev/null
# reload udev rules
udevadm control --reload-rules
# restart rsyslogd
/etc/rc.d/rc.rsyslogd restart
echo
echo "-----------------------------------------------------------"
echo " &name; has been installed."
echo " "
echo " Copyright 2016-2020, &author;"
echo " Version: &version;"
echo ""
echo "-----------------------------------------------------------"
echo
</INLINE>
</FILE>
<!--
The 'remove' script.
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
#Define Variables
KERNEL_V="$(uname -r)"
PACKAGE="usbip"
# Remove installed packages
find "&packages;/" -type f -iname "*.txz" -delete
rm -f /tmp/plugins/&name;.plg
rm -r /tmp/&name;
rm -f /etc/udev/rules.d/99_persistent_usb_manager.rules
rm -f /etc/rsyslog.d/99_usb_manager_syslog.conf
#modprobe -r usbip_host
#modprobe -r vhci_hcd
#killall usbipd
# reload udev rules
udevadm control --reload-rules
# restart rsyslogd
/etc/rc.d/rc.rsyslogd restart
# Remove QEMU Hooks entries
/usr/local/emhttp/plugins/&name;/scripts/uninstall.sh 2>/dev/null
# Remove all plugin files from emhttp.
removepkg &packages;/&name;-&version;.txz
#removepkg "&packages;/&name;/packages/${KERNEL_V%%-*}/${PACKAGE}-1.txz"
#depmod -a > /dev/null
echo
echo "-----------------------------------------------------------"
echo " &name; has been uninstalled."
echo "-----------------------------------------------------------"
echo
</INLINE>
</FILE>
</PLUGIN>