Implement selection and display of temperature unit
This commit is contained in:
parent
1f363944b9
commit
65f2b0610b
@ -61,12 +61,12 @@ function install_packages {
|
|||||||
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
||||||
read -p "lm-sensors is not installed. Would you like to install it? (y/n) " choice
|
read -p "lm-sensors is not installed. Would you like to install it? (y/n) " choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
y | Y)
|
[yY])
|
||||||
# If the user chooses to install lm-sensors, update the package list and install the package
|
# If the user chooses to install lm-sensors, update the package list and install the package
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install lm-sensors
|
apt-get install lm-sensors
|
||||||
;;
|
;;
|
||||||
n | N)
|
[nN])
|
||||||
# If the user chooses not to install lm-sensors, exit the script with a zero status code
|
# If the user chooses not to install lm-sensors, exit the script with a zero status code
|
||||||
msg "Decided to not install lm-sensors. The mod cannot run without it. Exiting..."
|
msg "Decided to not install lm-sensors. The mod cannot run without it. Exiting..."
|
||||||
exit 0
|
exit 0
|
||||||
@ -80,6 +80,7 @@ function install_packages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configure {
|
function configure {
|
||||||
|
sensorsDetected=false
|
||||||
local sensorsOutput=$(sensors -j)
|
local sensorsOutput=$(sensors -j)
|
||||||
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"
|
||||||
@ -111,10 +112,8 @@ function configure {
|
|||||||
|
|
||||||
if [ -n "$CPU_ADDRESS_PREFIX" ]; then
|
if [ -n "$CPU_ADDRESS_PREFIX" ]; then
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o "\"${CPU_ADDRESS_PREFIX}[^\"]*\"" | sed 's/"//g')"
|
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o "\"${CPU_ADDRESS_PREFIX}[^\"]*\"" | sed 's/"//g')"
|
||||||
fi
|
else
|
||||||
|
|
||||||
# If cpu is not known, ask the user for input
|
# If cpu is not known, ask the user for input
|
||||||
if [ -z "$CPU_ADDRESS_PREFIX" ]; then
|
|
||||||
warn "Could not automatically detect the CPU temperature sensor. Please configure it manually."
|
warn "Could not automatically detect the CPU temperature sensor. Please configure it manually."
|
||||||
# Ask user for CPU information
|
# Ask user for CPU information
|
||||||
# Inform the user and prompt them to press any key to continue
|
# Inform the user and prompt them to press any key to continue
|
||||||
@ -131,6 +130,8 @@ function configure {
|
|||||||
|
|
||||||
if [[ -z "$CPU_ADDRESS_PREFIX" || -z "$CPU_ITEM_PREFIX" ]]; then
|
if [[ -z "$CPU_ADDRESS_PREFIX" || -z "$CPU_ITEM_PREFIX" ]]; then
|
||||||
warn "The CPU configuration is not complete. Temperatures will not be available."
|
warn "The CPU configuration is not complete. Temperatures will not be available."
|
||||||
|
else
|
||||||
|
sensorsDetected=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if HDD/SSD data is installed
|
# Check if HDD/SSD data is installed
|
||||||
@ -140,6 +141,7 @@ function configure {
|
|||||||
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-"); then
|
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-"); then
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
||||||
enableHddTemp=true
|
enableHddTemp=true
|
||||||
|
sensorsDetected=true
|
||||||
else
|
else
|
||||||
warn "Kernel module \"drivetemp\" is not installed. HDD/SDD temperatures will not be available."
|
warn "Kernel module \"drivetemp\" is not installed. HDD/SDD temperatures will not be available."
|
||||||
enableHddTemp=false
|
enableHddTemp=false
|
||||||
@ -153,6 +155,7 @@ function configure {
|
|||||||
if (echo "$sensorsOutput" | grep -q "nvme-"); then
|
if (echo "$sensorsOutput" | grep -q "nvme-"); then
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g')"
|
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g')"
|
||||||
enableNvmeTemp=true
|
enableNvmeTemp=true
|
||||||
|
sensorsDetected=true
|
||||||
else
|
else
|
||||||
warn "No NVMe temperature sensors found."
|
warn "No NVMe temperature sensors found."
|
||||||
enableNvmeTemp=false
|
enableNvmeTemp=false
|
||||||
@ -163,11 +166,29 @@ function configure {
|
|||||||
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then
|
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then
|
||||||
msg "Detected fan speed sensors:\n$(echo "$sensorsOutput" | grep -o 'fan[0-9]*_input[^"]*')"
|
msg "Detected fan speed sensors:\n$(echo "$sensorsOutput" | grep -o 'fan[0-9]*_input[^"]*')"
|
||||||
enableFanSpeed=true
|
enableFanSpeed=true
|
||||||
|
sensorsDetected=true
|
||||||
else
|
else
|
||||||
warn "No fan speed sensors found."
|
warn "No fan speed sensors found."
|
||||||
enableFanSpeed=false
|
enableFanSpeed=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $sensorsDetected = true ]; then
|
||||||
|
msg "\nSelect a unit for temperature readings..."
|
||||||
|
read -p "Type C for Celsius or F for Fahrenheit and press Enter: " TEMP_UNIT
|
||||||
|
|
||||||
|
case "$TEMP_UNIT" in
|
||||||
|
[cC])
|
||||||
|
TEMP_UNIT="C"
|
||||||
|
;;
|
||||||
|
[fF])
|
||||||
|
TEMP_UNIT="F"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
warn "Invalid selection. Temperatures will be presented in degrees Celsius."
|
||||||
|
TEMP_UNIT="C"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
echo # add a new line
|
echo # add a new line
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +210,9 @@ function install_mod {
|
|||||||
cp "$nodespm" "$BACKUP_DIR/Nodes.pm.$timestamp"
|
cp "$nodespm" "$BACKUP_DIR/Nodes.pm.$timestamp"
|
||||||
msg "Backup of \"$nodespm\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
|
msg "Backup of \"$nodespm\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
|
||||||
|
|
||||||
sed -i '/my $dinfo = df('\''\/'\'', 1);/i\'$'\t''$res->{sensorsOutput} = `sensors -j`;\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"
|
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
|
||||||
|
local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j")
|
||||||
|
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\"."
|
||||||
else
|
else
|
||||||
warn "Sensors' output already integrated in in \"$nodespm\"."
|
warn "Sensors' output already integrated in in \"$nodespm\"."
|
||||||
@ -201,6 +224,7 @@ function install_mod {
|
|||||||
cp "$pvemanagerlibjs" "$BACKUP_DIR/pvemanagerlib.js.$timestamp"
|
cp "$pvemanagerlibjs" "$BACKUP_DIR/pvemanagerlib.js.$timestamp"
|
||||||
msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"."
|
msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"."
|
||||||
|
|
||||||
|
local tempUnitSuffix=$([[ "$TEMP_UNIT" = "F" ]] && echo "°F" || echo "°C")
|
||||||
# Expand space in StatusView
|
# Expand space in StatusView
|
||||||
sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ {
|
sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ {
|
||||||
s/\(bodyPadding:\) '[^']*'/\1 '20 15 20 15'/
|
s/\(bodyPadding:\) '[^']*'/\1 '20 15 20 15'/
|
||||||
@ -268,9 +292,9 @@ function install_mod {
|
|||||||
let tempIndex = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\
|
let tempIndex = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\
|
||||||
if (tempIndex !== null && tempIndex.length > 1) {\n\
|
if (tempIndex !== null && tempIndex.length > 1) {\n\
|
||||||
tempIndex = tempIndex[1];\n\
|
tempIndex = tempIndex[1];\n\
|
||||||
tempStr = \`\${cpuTempCaption} \${tempIndex}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
tempStr = \`\${cpuTempCaption} \${tempIndex}: <span style=\"\${tempStyle}\">\${tempVal}$tempUnitSuffix</span>\`;\n\
|
||||||
} else {\n\
|
} else {\n\
|
||||||
tempStr = \`\${cpuTempCaption}: \${tempVal}°C\`;\n\
|
tempStr = \`\${cpuTempCaption}: \${tempVal}$tempUnitSuffix\`;\n\
|
||||||
}\n\
|
}\n\
|
||||||
cpuTemps.push(tempStr);\n\
|
cpuTemps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
@ -345,7 +369,7 @@ function install_mod {
|
|||||||
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
|
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
|
||||||
tempStyle = 'color: red; font-weight: bold;';\n\
|
tempStyle = 'color: red; font-weight: bold;';\n\
|
||||||
}\n\
|
}\n\
|
||||||
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}$tempUnitSuffix</span>\`;\n\
|
||||||
temps.push(tempStr);\n\
|
temps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
} catch(e) { /*_*/ }\n\
|
} catch(e) { /*_*/ }\n\
|
||||||
@ -407,7 +431,7 @@ function install_mod {
|
|||||||
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
|
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
|
||||||
tempStyle = 'color: red; font-weight: bold;';\n\
|
tempStyle = 'color: red; font-weight: bold;';\n\
|
||||||
}\n\
|
}\n\
|
||||||
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}°C</span>\`;\n\
|
const tempStr = \`Drive \${index + 1}: <span style=\"\${tempStyle}\">\${tempVal}$tempUnitSuffix</span>\`;\n\
|
||||||
temps.push(tempStr);\n\
|
temps.push(tempStr);\n\
|
||||||
}\n\
|
}\n\
|
||||||
} catch(e) { /*_*/ }\n\
|
} catch(e) { /*_*/ }\n\
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user