Merge branch 'main' of https://github.com/Meliox/PVE-mods into intel_package_temp

This commit is contained in:
Meliox 2024-06-16 13:13:58 +02:00
commit 3a6eba076b

View File

@ -30,7 +30,11 @@ nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
DEBUG_SAVE_PATH="$SCRIPT_CWD" DEBUG_SAVE_PATH="$SCRIPT_CWD"
DEBUG_SAVE_FILENAME="sensorsdata.json" DEBUG_SAVE_FILENAME="sensorsdata.json"
############################################### ##################### DO NOT EDIT BELOW #######################
# Only to be used to debug on other systems. Save the "sensor -j" output into a json file.
# Information will be loaded for script configuration and presented in Proxmox.
DEBUG_REMOTE=false
JSON_FILE="/tmp/sensordata.json"
# Helper functions # Helper functions
function msg { function msg {
@ -89,7 +93,15 @@ function install_packages {
function configure { function configure {
sensorsDetected=false sensorsDetected=false
local sensorsOutput=$(sensors -j) local sensorsOutput
if [ $DEBUG_REMOTE = true ]; then
warn "Remote debugging is used. Sensor readings from dump file $JSON_FILE will be used."
sensorsOutput=$(cat $JSON_FILE)
else
sensorsOutput=$(sensors -j)
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n" err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n"
fi fi
@ -131,8 +143,16 @@ function configure {
esac esac
elif (echo "$sensorsOutput" | grep -q "k10temp-"); then elif (echo "$sensorsOutput" | grep -q "k10temp-"); then
# AMD CPU # AMD CPU
# Find and set temperature search criteria
if (echo "$sensorsOutput" | grep -A 4 "$item" | grep -q -e "Tctl" -e "Tccd"); then
CPU_ADDRESS_PREFIX=$item
CPU_ITEM_PREFIX="Tccd" CPU_ITEM_PREFIX="Tccd"
CPU_TEMP_CAPTION="Temp" CPU_TEMP_CAPTION="Temp"
elif (echo "$sensorsOutput" | grep -A 4 "$item" | grep -q "temp"); then
CPU_ADDRESS_PREFIX=$item
CPU_ITEM_PREFIX="temp"
CPU_TEMP_CAPTION="Temp"
fi
fi fi
else else
# If cpu is not known, ask the user for input # If cpu is not known, ask the user for input
@ -263,9 +283,14 @@ function install_mod {
enableSensors=true enableSensors=true
if [[ "$enableSensors" == true ]]; then if [[ "$enableSensors" == true ]]; then
local sensorsCmd
if [ $DEBUG_REMOTE = true ]; then
sensorsCmd="cat \"$JSON_FILE\""
else
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :| # WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j") #local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j")
local sensorsCmd="sensors -j" sensorsCmd="sensors -j"
fi
sed -i '/my \$dinfo = df('\''\/'\'', 1);/i\'$'\t''$res->{sensorsOutput} = `'"$sensorsCmd"'`;\n\t# sanitize JSON output\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+):\\s(.+)/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+)!/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/,(.*[.\\n]*.+})/$1/g;\n' "$nodespm" sed -i '/my \$dinfo = df('\''\/'\'', 1);/i\'$'\t''$res->{sensorsOutput} = `'"$sensorsCmd"'`;\n\t# sanitize JSON output\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+):\\s(.+)/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+)!/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/,(.*[.\\n]*.+})/$1/g;\n' "$nodespm"
msg "Sensors' output added to \"$nodespm\"." msg "Sensors' output added to \"$nodespm\"."
fi fi