Compare commits

...

2 Commits

Author SHA1 Message Date
Raphaël Numbus 55c51c7205 Improved disks part of hardware detection. 2026-05-25 22:02:34 +02:00
Raphaël Numbus 297df7bb2e Debugging. 2026-05-25 21:37:16 +02:00
+53 -60
View File
@@ -117,37 +117,38 @@ append_to_report() {
# --- 1. Detect Graphics ---
detect_graphics() {
local gpus="[]"
local obj
local brand
local renderer
local product
local integrated
local pci_addr
while read -r gpu; do
echo \$gpu >> "${REMOTE_STDERR}"
echo "test" >> "${REMOTE_STDERR}"
# Process each GPU found by lspci
while read -r line; do
[[ -z "\$line" ]] && continue
local brand="unknown"
local renderer="none"
local product="unknown"
local integrated="false"
local pci_addr="none"
pci_addr="\$(lspci | grep VGA | head -c 7)"
# Extract PCI address
pci_addr="\$(echo "\$line" | cut -d' ' -f1)"
# Brand
for b in Intel AMD NVIDIA; do
if echo "\${gpu}" | grep -i "\${b}" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}"; then
if echo "\$line" | grep -iq "\$b"; then
brand="\${b}"
break
fi
done
# Renderer
renderer="\$(ls -lh /dev/dri/by-path | grep "\$pci_addr" | grep "render")"
if [[ -n "\${renderer}" ]]; then
renderer="\${renderer##*render}"
renderer="render\${renderer}"
else
renderer="none"
if [[ -d "/dev/dri/by-path" ]]; then
local render_node
render_node=\$(ls /dev/dri/by-path | grep "\$pci_addr" | grep "render" | head -n1 || true)
if [[ -n "\$render_node" ]]; then
renderer=\$(basename "\$(readlink -f "/dev/dri/by-path/\$render_node")")
fi
fi
# Product name
product="\${gpu#*:}"
product="\${line#*:}"
product="\${product#*: }"
# Form factor
@@ -155,32 +156,31 @@ 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 "\${gpu}" | grep "Mobile"; then
if echo "\$line" | grep -i "Mobile"; then
integrated="true"
else
integrated="false"
fi
fi
obj=\$(jq -n \
local obj=\$(jq -n \
--arg b "\${brand}" \
--arg r "\${renderer}" \
--arg p "\${product}" \
--argjson i "\${integrated}" \
'{brand: \${b}, renderer: \${r}, product: \${p}, integrated: \${i}}')
'{brand: \$b, renderer: \$r, product: \$p, integrated: \$i}')
gpus=\$(echo "\$gpus" | jq --argjson obj "\$obj" '. += [\$obj]')
done < <(lspci | grep -e "VGA" -e "3D" >> "${REMOTE_STDOUT}" 2>> "${REMOTE_STDERR}")
done < <(lspci | grep -Ei "VGA|3D")
echo "\$gpus" >> "${REMOTE_STDERR}"
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"
}