This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathunassigned.devices.preclear.plg
397 lines (315 loc) · 12 KB
/
unassigned.devices.preclear.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "unassigned.devices.preclear">
<!ENTITY author "dlandon">
<!ENTITY version "2025.02.14">
<!ENTITY launch "Tools/Preclear">
<!ENTITY gitURL "https://raw.githubusercontent.com/unraid/unassigned.devices/master">
<!ENTITY pluginURL "&gitURL;/&name;.plg">
<!ENTITY supportURL "https://forums.unraid.net/topic/120567-unassigned-devices-preclear-a-utility-to-preclear-disks-before-adding-them-to-the-array/">
<!ENTITY MD5 "8a7900d869ca2d9c10dbfee750e74c77">
]>
<PLUGIN name="&name;"
author="&author;"
launch="&launch;"
version="&version;"
pluginURL="&pluginURL;"
support="&supportURL;"
icon="icon-preclear"
min="6.11.0">
<CHANGES>
###&name;
###&version;
- Add: Change to Unraid repository.
###2025.02.12
- Fix: Language translation updates.
- Fix: Update tmux to 3.5a.
###2025.01.29
- Fix: Erase disk gets stuck at "Starting".
###2025.01.20
- Fix: Reports showing a blank line when no reports are displayed.
- Fix: Rewrite Java Script code for reliability and robustness.
- Fix: Some UI cleanup.
- Fix: All running preclears not stopping when the plugin is removed.
###2024.12.29
- Fix: Revise Java Script to stop Unraid spinner properly. Seems to be browser related and shows up on Chrome.
###2024.12.24
- Fix: Nginx errors from malformed GET.
###2024.12.17
- Fix: Cannot preclear a disk with an empty partition.
###2024.12.16
- Fix: Reorder dialog buttons to be more compatible with Unraid standard with the 'Cancel' button on the right.
- Fix: Language translations not being applied in Preclear.php.
###2024.12.05
- Fix: Change some php variables to constants that don't need to be variables.
- Fix: Page layout changes.
###2024.11.12
- Fix: Remove php error logging as it's now included in Unraid core.
- Fix: Fix php warnings from removing the preclear php logging.
- Fix: Adjust short serial number for disks with a -N:N suffix to help distinguish different disks with the same serial number.
- Fix: Report GUI fixes including listing caused the disk status to shift down one line, reports removed on page update, '+'/'-' icons not toggling.
- Add: Language translations.
- Add: Style sheet change to adjust sweetalert 2 dialogs to stop over run of text in dialog.
###2024.04.23a.
- Fix: Update tmux to version 3.4 for 6.13.
- Fix: Increase dd_hang timeout even further.
###2024.02.22
- Fix: Only resume a paused preclear on a disk that is an unassigned disk.
- Fix: Change the logic to better manage the pause/resume so disks are not resumed inappropriately.
###2024.02.07
- Fix: Double quote in the smartctl report causing issues with php in rc.diskinfo.
###2023.12.15
- Fix: Style changes for GUI compatibility with 6.13.
- Fix: Put styles into .css files.
###2023.11.30
- Fix: Change Unraid minimum version to 6.11.
###2023.11.08
- Add: Information on preclear page about a disk having to be cleared of all partitions before it can be precleared.
###2023.08.14
- Fix: Remove memory verify check for checking that sectors are zeroed. It is not really necessary and causes problems.
- Fix: Show previous preclear reports in order of the latest one on top of the list.
###2023.08.09
- Add: Double the dd_hang time when reading to the disk to try to prevent dd read timeouts at the end of large disks.
###2023.08.08a
- Fix: Disks that have a file system on a disk with no partition are not candidates for preclear.
- Fix: Update utempter to 1.2.1.
- Add: Double the dd_hang time when writing to the disk to try to prevent dd write timeouts at the end of large disks.
###2023.05.20
- Fix: Divide by zero when checking for available rootfs free space.
- Add: Ignore zvol devices managed in UD. They are not candidates for preclearing.
###2023.05.06
- Fix: Preclear removes a directory it shouldn't when uninstalling that breaks connect.
###2023.04.12
- Fix: Php NAN warnings.
###2023.04.12
- Fix: Java script errors.
###2023.04.04
- Fix: Disk Log not working in Unraid 6.10 and 6.11.
###2023-02-06
- Fix: Php 8.2 deprecated warnings.
- Fix: Compatibility changes for 6.12.
###2023.01.08
- Fix: Php error when starting a preclear.
###2022.12.31
- Fix: Php error in rc.diskinfo.
- Fix: Situation where all preclear reports appear for a device.
###2022.12.12
- Fix: Php 8.1 compatibility for Unraid 6.12.
###2022.09.02
- Fix: Don't allow a preclear on a disk that Unraid does not see as Unassigned.
###2022.08.19
- Fix: Reference to GitHub repository.
###2022.08.14
- Fix: Php array error in rc.diskinfo under certain circumstances.
- Fix: Disk incorrectly shows as 'precleared' when it is not.
###2022.07.29
- Fix: Use standard Unraid disk size display format. Fixes where Preclear showed a 1.5TB disk as 2TB because of a rounding up issue in the preclear plugin.
###2022.07.24a
- Add: Install tmux 3.3a for Unraid 6.11.
- Fix: Delay when starting a preclear when a disk is spun down.
- Fix: Remove legacy code from plugin file. It was causing an error when installing the plugin.
###2022.07.11
- Fix: Revert tmux to 3.1b for Unraid 6.10.
###2022.07.10a
- Fix: Remove the SMART self-assessment text from the SMART report. It is confusing when trying to decide if a disk is failing.
- Fix: UI appears to hang when stopping a single disk preclear.
- Fix: Update tmux to 3.3a and add glibc package required by tmux.
###2022.06.10
- Fix: Preclear fix script not working.
- Fix: Remove legacy code for language translations.
###2022.05.17
- Fix: Use the device id from devs.ini and not the id from the udev ID_MODEL and ID_SERIAL_SHORT.
###2022.05.03
- Fix: Pausing preclears fails to save resume file on flash device.
###2022.04.18
- Fix: Add additional line to SMART statistics in preclear view.
###2022.03.31
- Fix: Convert POH values that show as '22h+07m+23.077s' to hours for SMART difference comparison.
###2022.03.15
- Fix: Only write resume file to flash when absolutely necessary to minimize flash writes.
###2022.03.14
- Fix: Replace the confusing csrf token error message with fail message. It's an incorrect message.
- Fix: Add 'Success' dialogs where missing on certain actions.
###2022.03.07
- Fix: '/tmp/.preclear/sdX/dd_output_complete: No such file or directory' error message.
###2022.03.06
- Add: Updated plugin check.
- Fix: Integer error in prelcear script.
###2022.03.04
- Add: Remove libevent (it's included in Unraid) and update utempter package.
- Fix: Right justify the preclear results on the status page.
###2022.02.27
- Initial release.
</CHANGES>
<!--
The 'pre-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
# Unassigned Devices must be installed.
if [ ! -f /boot/config/plugins/unassigned.devices.plg ] ; then
echo ""
echo "-----------------------------------------------------------"
echo " &name; has not been installed!"
echo " Install the Unassigned Devices plugin first."
echo "-----------------------------------------------------------"
echo ""
exit 1
fi
# The legacy preclear plug cannot be installed.
if [ -f /boot/config/plugins/preclear.disk.plg ] ; then
echo ""
echo "-----------------------------------------------------------"
echo " &name; has not been installed!"
echo ""
echo " The Preclear Disk plugin is installed."
echo ""
echo " You must uninstall the Preclear Disk plugin before"
echo " installing Unassigned Devices Preclear."
echo ""
echo "-----------------------------------------------------------"
echo ""
exit 1
fi
</INLINE>
</FILE>
<!--
Get the plugin bundle.
-->
<FILE Name="/boot/config/plugins/&name;/&name;-&version;.tgz">
<URL>"&gitURL;/&name;-&version;.tgz"</URL>
<MD5>&MD5;</MD5>
</FILE>
<!--
tmux-3.1b-x86_64-1.txz
-->
<FILE Name="/boot/config/plugins/&name;/tmux-3.1b-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>"&gitURL;/packages/tmux-3.1b-x86_64-1.txz"</URL>
<MD5>c8367090c89d26690be706c7fb3db5fc</MD5>
</FILE>
<!--
tmux-3.3a-x86_64-1.txz
-->
<FILE Min='6.11.0-rc1' Name="/boot/config/plugins/&name;/tmux-3.3a-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>"&gitURL;/packages/tmux-3.3a-x86_64-1.txz"</URL>
<MD5>6f929e52a448007bf5468ae541fda15c</MD5>
</FILE>
<!--
tmux-3.4-x86_64-1.txz
-->
<FILE Min='6.13.0-beta.1.8' Name="/boot/config/plugins/&name;/tmux-3.4-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>"&gitURL;/packages/tmux-3.4-x86_64-1.txz"</URL>
<MD5>a5f489e6b37800c4da6687e56a3f8d94</MD5>
</FILE>
<!--
tmux-3.5a-x86_64-1.txz
-->
<FILE Min='7.0.0' Name="/boot/config/plugins/&name;/tmux-3.5a-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>"&gitURL;/packages/tmux-3.5a-x86_64-1.txz"</URL>
<MD5>a697e9a8aa8d4704ea8858914f2e2d7d</MD5>
</FILE>
<!--
utempter-1.2.1-x86_64-1.txz
-->
<FILE Name="/boot/config/plugins/&name;/utempter-1.2.1-x86_64-1.txz" Run="upgradepkg --install-new">
<URL>"&gitURL;/packages/utempter-1.2.1-x86_64-1.txz"</URL>
<MD5>8843badd5e5cb333334a069fcafb233b</MD5>
</FILE>
<!--
The 'pre-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
# Remove emhttp files so we can re-install.
rm -rf /usr/local/emhttp/plugins/&name;/* 2>/dev/null
# Remove old 'bundle' files.
rm -f $(ls /boot/config/plugins/&name;/&name;*.tgz 2>/dev/null | grep -v '&version;')
</INLINE>
</FILE>
<!--
The 'post-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
unsupported="/var/state/&name;/unsupported"
# Creating some directories
mkdir -p /tmp/preclear/ /tmp/.preclear/ /usr/local/bin/ /var/state/&name;/ /var/log/preclear/
echo "Checking tmux operation..."
# Fix tmux tmp directory if needed
if [ ! -d "/tmp/tmux-0" ]; then
mkdir /tmp/tmux-0
fi
chmod 700 /tmp/tmux-0
chown -R root:root /tmp/tmux-0
# Verify if tmux is working correctly
/usr/bin/tmux new-session -d -x 140 -y 200 -s "install_test_session" &>/dev/null
sleep 0.5
/usr/bin/tmux kill-session -t "install_test_session" &>/dev/null
if [ $? -ne 0 ]; then
echo "tmux is not working properly"
echo "tmux is not working properly" | logger -t "root: plugin: &name;.plg"
touch "$unsupported"
fi
# Create plugin directory
mkdir -p /boot/config/plugins/&name;
# Install the 'bundle'.
tar -xf /boot/config/plugins/&name;/&name;-&version;.tgz -C /usr/local/emhttp/plugins 2>/dev/null
# Fix permissions of executable files
chmod +x /usr/local/emhttp/plugins/&name;/scripts/* /usr/local/emhttp/plugins/&name;/event/*
# Make sure log file exists
touch /var/log/preclear/preclear.log
# Set correct terminal type for TMUX
echo "set -g default-terminal 'linux'" > /root/.tmux.conf
# Set default terminal size for TMUX
echo "set -g default-size 100x50" >> /root/.tmux.conf
# Create a symlink to diskinfo
ln -sf /usr/local/emhttp/plugins/&name;/scripts/rc.diskinfo /etc/rc.d/rc.diskinfo
# Fix permissions of executable files
chmod +x /usr/local/emhttp/plugins/&name;/scripts/* /usr/local/emhttp/plugins/&name;/event/*
# Initiate a hot plug event for unassigned devices and preclear
echo "" > /tmp/unassigned.devices/hotplug_event
# Add ignore rule to Unraid Flash Backup
echo "*.resume" > /boot/config/plugins/&name;/.gitignore
# Run diskinfo to get the initial unassigned devices information.
/etc/rc.d/rc.diskinfo force
# Plugin version
echo "&version;" > /var/state/&name;/version
echo ""
echo "-----------------------------------------------------------"
echo " &name; has been installed."
echo " Copyright 2015-2020, gfjardim"
echo " Copyright 2022-2025, &author;"
echo " Version: &version;"
echo "-----------------------------------------------------------"
echo ""
</INLINE>
</FILE>
<!--
The 'remove' script.
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
# kill all preclear sessions
/usr/local/emhttp/plugins/&name;/scripts/clear_preclear.sh
# Remove diskinfo
rm -rf /var/local/emhttp/plugins/diskinfo/diskinfo.json /etc/rc.d/rc.diskinfo
# Remove plugin
rm -rf /boot/config/plugins/&name;/ \
/usr/local/emhttp/plugins/&name;/
# Remove plugin related files
rm -rf /usr/local/bin/preclear \
/var/run/preclear_queue.pid \
/var/log/preclear/preclear.log
# Remove plugin related directories
rm -rf /var/state/&name; \
/tmp/preclear/ \
/tmp/.preclear/
echo ""
echo "-----------------------------------------------------------"
echo " &name; has been uninstalled."
echo " Version: &version;"
echo "-----------------------------------------------------------"
echo ""
</INLINE>
</FILE>
</PLUGIN>