Skip to content

Commit

Permalink
fix(temperatures): Handle sensors output for AMD CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
bcyran committed Jan 6, 2024
1 parent 19b515c commit e3d3dff
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions modules/31-temperatures
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ set -euo pipefail
# shellcheck source=./framework.sh
source "${BASE_DIR}/framework.sh"

cores="$(sensors | grep Core | awk '{printf "%s ", $3} {printf "%s %s %s\n", $6, $9, $12}' | tr -d '+°C,)')"
temp_intel() {
local cores out

text=""
while IFS= read -r line; do
IFS=" " read -r current high critical <<< "${line}"
cores="$(echo "${sensors_output}" | grep Core | awk '{printf "%s ", $3} {printf "%s %s %s\n", $6, $9, $12}' | tr -d '+°C,)')"
out=""

if [[ "${high}" == "${critical}" ]]; then
high=$(bc -l <<< "${high} - 20")
fi
while IFS= read -r line; do
IFS=" " read -r current high critical <<< "${line}"

text+="$(print_color "${current}°C" "${current}" "${high}" "${critical}"), "
done <<< "${cores}"
if [[ "${high}" == "${critical}" ]]; then
high=$(bc -l <<< "${high} - 20")
fi

print_columns "Temperatures" "${text::-2}"
out+="$(print_color "${current}°C" "${current}" "${high}" "${critical}"), "
done <<< "${cores}"

echo "${out::-2}"
}

temp_amd() {
echo "${sensors_output}" | awk '/Tdie/ {print $2}' | tr -d '+'
}

sensors_output="$(sensors)"

if grep -q 'Tdie' <<< "${sensors_output}"; then
temps=$(temp_amd)
else
temps=$(temp_intel)
fi

print_columns "Temperatures" "${temps}"

0 comments on commit e3d3dff

Please sign in to comment.