-
Notifications
You must be signed in to change notification settings - Fork 8
/
tlerActiveation.tool
executable file
·65 lines (47 loc) · 1.38 KB
/
tlerActiveation.tool
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
#!/bin/bash
# shellcheck disable=SC1004,SC2236
function tler_activation() {
local tlerStatus
tlerStatus="$(smartctl -jl scterc "/dev/${drive}" | jq -Mre '.ata_sct_erc | values')"
if [ ! -z "${tlerStatus}" ]; then
if [ ! "$(echo "${tlerStatus}" | jq -Mre '.read.enabled | values')" = "true" ] || [ ! "$(echo "${tlerStatus}" | jq -Mre '.write.enabled | values')" = "true" ]; then
smartctl -l scterc,70,70 "/dev/${drive}"
fi
fi
echo "${drive}:"
smartctl -l scterc "/dev/${drive}" | tail -n +4
echo "+---------------+"
}
function drive_list() {
# Reorders the drives in ascending order
# FixMe: smart support flag is not yet implemented in smartctl json output.
readarray -t "drives" <<< "$(for drive in $(sysctl -n kern.disks | sed -e 's:nvd:nvme:g'); do
if smartctl --json=u -i "/dev/${drive}" | grep "SMART support is:" | grep -q "Enabled"; then
printf "%s " "${drive}"
elif echo "${drive}" | grep -q "nvme"; then
printf "%s " "${drive}"
fi
done | tr ' ' '\n' | sort -V | sed '/^nvme/!H;//p;$!d;g;s:\n::')"
}
# Check if needed software is installed.
PATH="${PATH}:/usr/local/sbin:/usr/local/bin"
commands=(
sysctl
sed
grep
tr
smartctl
jq
sort
tail
)
for command in "${commands[@]}"; do
if ! type "${command}" &> /dev/null; then
echo "${command} is missing, please install" >&2
exit 100
fi
done
drive_list
for drive in "${drives[@]}"; do
tler_activation
done