Improved disks part of hardware detection.
This commit is contained in:
+33
-40
@@ -127,7 +127,7 @@ detect_graphics() {
|
||||
local integrated="false"
|
||||
local pci_addr="none"
|
||||
|
||||
# Extract PCI address (e.g. 00:02.0)
|
||||
# Extract PCI address
|
||||
pci_addr="\$(echo "\$line" | cut -d' ' -f1)"
|
||||
|
||||
# Brand
|
||||
@@ -156,14 +156,14 @@ detect_graphics() {
|
||||
integrated="false"
|
||||
fi
|
||||
if [[ "\${brand}" == "Intel" ]]; then
|
||||
if echo "\${gpu}" | grep -e "HD Graphics" -e "Xe"; then
|
||||
if echo "\${gpu}" | grep -Ei "HD Graphics|Xe"; then
|
||||
integrated="true"
|
||||
else
|
||||
integrated="false"
|
||||
fi
|
||||
fi
|
||||
if [[ "\${brand}" == "AMD" ]]; then
|
||||
if echo "\$line" | grep -iq "Mobile"; then
|
||||
if echo "\$line" | grep -i "Mobile"; then
|
||||
integrated="true"
|
||||
else
|
||||
integrated="false"
|
||||
@@ -179,7 +179,7 @@ detect_graphics() {
|
||||
|
||||
gpus=\$(echo "\$gpus" | jq --argjson obj "\$obj" '. += [\$obj]')
|
||||
|
||||
done < <(lspci | grep -E "VGA|3D")
|
||||
done < <(lspci | grep -Ei "VGA|3D")
|
||||
|
||||
append_to_report "graphics" "\$gpus"
|
||||
}
|
||||
@@ -284,58 +284,51 @@ detect_tpm() {
|
||||
# --- 6. Detect Disks ---
|
||||
detect_disks() {
|
||||
local disks="[]"
|
||||
|
||||
# lsblk to loop through block devices (ignoring loops, rams, and cdroms)
|
||||
while read -r disk; do
|
||||
local dev_path="/dev/\$disk"
|
||||
|
||||
# Disk Type Mapping
|
||||
local disk_type="Other"
|
||||
local transport
|
||||
transport=\$(lsblk -d -n -o TRAN "\$dev_path" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}" || echo "")
|
||||
local rotational
|
||||
rotational=\$(lsblk -d -n -o ROTA "\$dev_path" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}" || echo "1")
|
||||
|
||||
if [[ "\$disk" == nvme* ]]; then
|
||||
disk_type="NVMe"
|
||||
elif [[ "\$transport" == "usb" ]]; then
|
||||
disk_type="USB"
|
||||
while read -r disk; do
|
||||
# Disk Type Mapping
|
||||
local disk_type="unknown"
|
||||
local disk_transport=\$(lsblk -d -n -o TRAN "\$dev_path" || echo "unknown")
|
||||
local rotational=\$(lsblk -d -n -o ROTA "\$dev_path" || echo "1")
|
||||
|
||||
if [[ "\$disk_name" == nvme* ]]; then
|
||||
disk_type="NVMe"
|
||||
elif [[ "\$rotational" == "1" ]]; then
|
||||
disk_type="HDD"
|
||||
disk_type="HDD"
|
||||
elif [[ "\$rotational" == "0" ]]; then
|
||||
disk_type="SSD"
|
||||
disk_type="SSD"
|
||||
fi
|
||||
|
||||
# Size in GB
|
||||
local size_bytes
|
||||
size_bytes=\$(lsblk -d -n -b -o SIZE "\$dev_path" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}" || echo "0")
|
||||
local size_gb=\$(awk -v size_bytes="\$size_bytes" 'BEGIN {printf "%.2f", size_bytes/1073741824}')
|
||||
local disk_size=\$(lsblk -d -n -o SIZE "\$dev_path" || echo "unknown")
|
||||
|
||||
# ID via by-id
|
||||
local disk_id="N/A"
|
||||
local disk_id="unknown"
|
||||
if [[ -d "/dev/disk/by-id" ]]; then
|
||||
local id_match
|
||||
id_match=\$(find /dev/disk/by-id/ -type l -not -name "wwn-*" -not -name "nvme-eui*" -printf "%p %l\n" | grep -m1 "/\$disk\$" | awk '{print \$1}')
|
||||
[[ -n "\$id_match" ]] && disk_id="\$id_match"
|
||||
local id_match=\$(find /dev/disk/by-id/ -type l -not -name "wwn-*" -not -name "nvme-eui*" -printf "%p %l\n" | grep -m1 "/\$disk_name\$" | awk '{print \$1}')
|
||||
[[ -n "\$id_match" ]] && disk_id="\$id_match"
|
||||
fi
|
||||
|
||||
# Health Assessment (Requires smartctl)
|
||||
local health="N/A"
|
||||
if echo "${LIVE_TARGET_PASSWORD}" | sudo -S smartctl -H "\$dev_path" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}"; then
|
||||
if smartctl -H "\$dev_path" | grep -iq -e "PASSED" -e "OK" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}"; then
|
||||
health="PASSED"
|
||||
else
|
||||
health="FAILED"
|
||||
fi
|
||||
# Health
|
||||
local health="unknown"
|
||||
if echo "${LIVE_TARGET_PASSWORD}" | sudo -S smartctl -H /dev/\$disk_name 2>/dev/null | grep -i "PASSED"; then
|
||||
disk_health="Passed"
|
||||
elif echo "${LIVE_TARGET_PASSWORD}" | sudo -S smartctl -H /dev/\$disk_name 2>/dev/null | grep -i "FAILED"; then
|
||||
disk_health="Failed"
|
||||
fi
|
||||
|
||||
local obj=\$(jq -n --arg n "\$disk" --arg dp "\$dev_path" --arg t "\$disk_type" \
|
||||
--arg h "\$health" --arg id "\$disk_id" --arg s "\$size_gb" \
|
||||
'{name: \$n, device_path: \$dp, type: \$t, health: \$h, id: \$id, size_gb: \$s}')
|
||||
local obj=\$(jq -n \
|
||||
--arg n "\${disk_name}" \
|
||||
--arg t "\${disk_type}" \
|
||||
--arg tr "\${disk_transport}" \
|
||||
--arg h "\${disk_health}" \
|
||||
--arg s "\${disk_size}" \
|
||||
--arg i "\${disk_id}" \
|
||||
'{name: \$n, type: \$t, transport: \$tr, health: \$h, size: \$s, id: \$i}')
|
||||
|
||||
disks=\$(echo "\$disks" | jq --argjson obj "\$obj" '. += [\$obj]')
|
||||
|
||||
done < <(lsblk -d -n -o NAME -e 7,11,252) # Exclude loop(7), sr(11), zram(252)
|
||||
done < <(lsblk -d -n -o NAME -e 7,11,252)
|
||||
|
||||
append_to_report "disks" "\$disks"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user