Skip to content

Commit

Permalink
Merge pull request #17 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad committed Jul 21, 2024
2 parents d2fbdc3 + 7f66cec commit c5569fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v2.3.8
- Fixed support for Realtek CPUs.

v2.3.7
- Added DSM shutdown temperature.
- Added Fahrenheit for those who don't use Celsius.
Expand Down
57 changes: 52 additions & 5 deletions syno_cpu_temp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Script verified at https://www.shellcheck.net/
#----------------------------------------------------------

scriptver="v2.3.7"
scriptver="v2.3.8"
script=Synology_CPU_temp
repo="007revad/Synology_CPU_temp"
scriptname=syno_cpu_temp
Expand All @@ -29,6 +29,9 @@ if [[ $buildphase == GM ]]; then buildphase=""; fi
if [[ $smallfixnumber -gt "0" ]]; then smallfix="-$smallfixnumber"; fi
echo -e "${model} DSM $productversion-$buildnumber$smallfix $buildphase"

# Show CPU arch
synogetkeyvalue /etc.defaults/synoinfo.conf unique

# Get DSM major version
dsm=$(get_key_value /etc.defaults/VERSION majorversion)

Expand Down Expand Up @@ -94,6 +97,7 @@ pad_len(){
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
pad_len_amd(){
#echo ${1} # debug
#echo ${#1} # debug
Expand Down Expand Up @@ -148,6 +152,7 @@ c2f(){
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
f2c(){
# Fahrenheit to Celsius - not used
# C = (F – 32) x 5/9
Expand All @@ -160,6 +165,16 @@ cpu_model=$(grep -E '^model name' /proc/cpuinfo | uniq | cut -d":" -f2 | xargs)
if [[ -z $cpu_model ]]; then
cpu_model=$(grep -E '^Processor' /proc/cpuinfo | uniq | cut -d":" -f2 | xargs)
fi
if [[ -z $cpu_model ]]; then
cpu_model=$(synogetkeyvalue /etc.defaults/synoinfo.conf unique | cut -d"_" -f2)
fi

# Failed to get CPU model
if [[ -z $cpu_model ]]; then
echo "Your CPU is not supported yet." |& tee -a "$Log_File"
echo "Create a Github issue to get your CPU added." |& tee -a "$Log_File"
exit
fi

# Get CPU max temp (high threshold)
max=$(grep . /sys/class/hwmon/hwmon*/temp*_max 2>/dev/null | cut -d":" -f2 | uniq)
Expand Down Expand Up @@ -243,7 +258,10 @@ elif grep AMD /proc/cpuinfo >/dev/null; then
style="amd"
elif grep Realtek /proc/cpuinfo >/dev/null; then
vendor="Realtek"
style="intel"
style="realtek"
elif [[ $cpu_model == "rtd1619b" ]]; then
vendor="Realtek"
style="realtek"
elif grep Marvell /proc/cpuinfo >/dev/null; then
vendor="Marvell"
style="marvell"
Expand All @@ -263,9 +281,9 @@ else
vendor="$(grep 'vendor_id' /proc/cpuinfo | uniq | cut -d":" -f2 | xargs)"
fi

supported_vendors=("intel" "amd" "realtek" "marvell""annapurna" "stm" "mindspeed" "freescale")
supported_vendors=("intel" "amd" "realtek" "marvell" "annapurna" "stm" "mindspeed" "freescale")

if [[ ! ${supported_vendors[*]} =~ "${vendor,,}" ]]; then
if [[ ! ${supported_vendors[*]} =~ ${vendor,,} ]]; then
echo "$vendor not supported yet." |& tee -a "$Log_File"
echo "Create a Github issue to get $vendor CPUs added." |& tee -a "$Log_File"
exit
Expand All @@ -287,6 +305,7 @@ cpu_qty=$(grep 'physical id' /proc/cpuinfo | uniq | awk '{printf $4}')
#cpu_qty=$((cpu_qty +1)) # test multiple CPUs

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
show_cpu_number(){
# echo [CPU 0] or [CPU 1] etc if more than 1 CPU
if [[ $cpu_qty -gt "0" ]]; then
Expand All @@ -303,6 +322,7 @@ show_cpu_number(){
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
show_intel_temps(){
# $1 for DSM 7 is "/sys/class/hwmon/hwmon"
# $1 for DSM 6 is "/sys/bus/platform/devices/coretemp."
Expand Down Expand Up @@ -332,6 +352,7 @@ show_intel_temps(){
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
show_amd_temps(){
# $1 for DSM 7 is "/sys/class/hwmon/hwmon"
# $1 for DSM 6 is "/sys/bus/platform/devices/coretemp."
Expand Down Expand Up @@ -362,6 +383,7 @@ show_amd_temps(){
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
show_marvell_temps(){
# $1 for DSM 7 is "/sys/class/hwmon/hwmon0/device"
# $1 for DSM 6 is "/sys/bus/platform/devices/coretemp." ???
Expand All @@ -376,8 +398,33 @@ show_marvell_temps(){
fi
}

# shellcheck disable=SC2329 # Don't warn This function is never invoked
# shellcheck disable=SC2317 # Don't warn Command appears unreachable
show_realtek_temps(){
# $1 for DSM 7 is "/sys/class/hwmon/hwmon0/device"
# $1 for DSM 6 is "/sys/bus/platform/devices/coretemp." ???

# Show cpu_thermal temp
if [[ -f "${1}/type" ]]; then
echo -n "${now}" >> "$Log_File"
printf %s "$(cat "${1}/type"): " |& tee -a "$Log_File"
ctmp1="$(awk '{printf $1/1000}' "${1}/temp")"
pad_len_amd "$ctmp1"
ctmp="${ctmp1}°C"
ftmp="$(c2f "$ctmp")°F"
# Show k10 temp
echo "$ctmp $ftmp"
# Log k10 temp
echo "$ctmp $pad $ftmp" >> "$Log_File"

fi
}


if [[ $dsm -gt "6" ]]; then
if [[ $style == "marvell" ]]; then
if [[ $style == "realtek" ]]; then
show_"${style}"_temps "/sys/class/thermal/thermal_zone0"
elif [[ $style == "marvell" ]]; then
show_"${style}"_temps "/sys/class/hwmon/hwmon0/device"
else
show_"${style}"_temps "/sys/class/hwmon/hwmon"
Expand Down

0 comments on commit c5569fc

Please sign in to comment.