fix: motd: handle empty temperature values in printf

Fixes "printf: : invalid number" error when ambient temperature or board
temperature values are empty on systems without temperature sensors.

Adds error suppression and fallback to "0" for temperature formatting
to prevent script errors on systems without these sensors.
This commit is contained in:
Igor Pecovnik 2026-01-26 19:45:24 +01:00 committed by Igor
parent f5650639d9
commit a4574e824a

View File

@ -162,8 +162,8 @@ if [[ -n "${board_temp:-}" ]] && awk -v t="$board_temp" -v o="$CPU_TEMP_OFFSET"
fi
# Truncate temperature decimals (e.g. 37.6 → 37)
cpu_temp_int=$(printf '%.0f\n' "${board_temp%%.*}")
amb_temp_int=$(printf '%.0f\n' "${amb_temp%%.*}")
cpu_temp_int=$(printf '%.0f\n' "${board_temp%%.*}" 2>/dev/null || echo "0")
amb_temp_int=$(printf '%.0f\n' "${amb_temp%%.*}" 2>/dev/null || echo "0")
display " CPU temp" "$cpu_temp_int" "$CPU_TEMP_LIMIT" "0" "°C" ""
display " Ambient temp" "$amb_temp_int" "$AMB_TEMP_LIMIT" "0" "°C" ""