Merge branch 'main' of https://github.com/Meliox/PVE-mods into Multiple_amd_cpu_types
This commit is contained in:
commit
5185b03d49
@ -26,7 +26,15 @@ BACKUP_DIR="$SCRIPT_CWD/backup"
|
||||
pvemanagerlibjs="/usr/share/pve-manager/js/pvemanagerlib.js"
|
||||
nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
|
||||
|
||||
###############################################
|
||||
# Debug location
|
||||
DEBUG_SAVE_PATH="$SCRIPT_CWD"
|
||||
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
|
||||
function msg {
|
||||
@ -54,7 +62,7 @@ function err {
|
||||
|
||||
# Function to display usage information
|
||||
function usage {
|
||||
msgb "\nUsage:\n$0 [install | uninstall]\n"
|
||||
msgb "\nUsage:\n$0 [install | uninstall | save-sensors-data]\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -85,7 +93,14 @@ function install_packages {
|
||||
|
||||
function configure {
|
||||
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
|
||||
err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n"
|
||||
@ -215,6 +230,22 @@ function configure {
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo ""
|
||||
read -p "Do you wish to enable System Information. [Yn]: " ENABLE_SYS_INFO
|
||||
case "$ENABLE_SYS_INFO" in
|
||||
[yY]|"")
|
||||
enableSystemInfo=true
|
||||
msg "Displaying System Information... yes"
|
||||
;;
|
||||
[nN])
|
||||
enableSystemInfo=false
|
||||
msg "Displaying System Information... no"
|
||||
;;
|
||||
*)
|
||||
warn "Invalid selection. System information will be displayed."
|
||||
enableSystemInfo=true
|
||||
;;
|
||||
esac
|
||||
echo # add a new line
|
||||
}
|
||||
|
||||
@ -230,27 +261,42 @@ function install_mod {
|
||||
|
||||
local timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
|
||||
|
||||
# Add new line to Nodes.pm file
|
||||
if [[ -z $(cat $nodespm | grep -e "$res->{sensorsOutput}") ]]; then
|
||||
# Perform backup
|
||||
if [[ -z $(cat $nodespm | grep -e "$res->{sensorsOutput}") ]] || [[ -z $(cat $nodespm | grep -e "$res->{systemInfo}") ]]; then
|
||||
# Create backup of original file
|
||||
cp "$nodespm" "$BACKUP_DIR/Nodes.pm.$timestamp"
|
||||
msg "Backup of \"$nodespm\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
|
||||
|
||||
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
|
||||
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j")
|
||||
local sensorsCmd="sensors -j"
|
||||
# Create backup of original file
|
||||
cp "$pvemanagerlibjs" "$BACKUP_DIR/pvemanagerlib.js.$timestamp"
|
||||
msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"."
|
||||
else
|
||||
err "Mod is already installed. Uninstall existing before installing."
|
||||
exit
|
||||
fi
|
||||
|
||||
enableSensors=true
|
||||
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 :|
|
||||
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "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"
|
||||
msg "Sensors' output added to \"$nodespm\"."
|
||||
else
|
||||
warn "Sensors' output already integrated in in \"$nodespm\"."
|
||||
fi
|
||||
|
||||
if [[ "$enableSystemInfo" == true ]]; then
|
||||
local systemInfoCmd=$(dmidecode -t 1 | awk -F': ' '/Manufacturer|Product Name|Serial Number/ {print $1": "$2}' | awk '{$1=$1};1' | sed 's/$/ |/' | paste -sd " " - | sed 's/ |$//')
|
||||
sed -i "/my \$dinfo = df('\/', 1);/i\\\t\$res->{systemInfo} = \"$(echo "$systemInfoCmd")\";\n" "$nodespm"
|
||||
msg "System Information output added to \"$nodespm\"."
|
||||
fi
|
||||
|
||||
# Add new item to the items array in PVE.node.StatusView
|
||||
if [[ -z $(cat "$pvemanagerlibjs" | grep -e "itemId: 'thermal[[:alnum:]]*'") ]]; then
|
||||
# Create backup of original file
|
||||
cp "$pvemanagerlibjs" "$BACKUP_DIR/pvemanagerlib.js.$timestamp"
|
||||
msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"."
|
||||
|
||||
local tempHelperCtorParams=$([[ "$TEMP_UNIT" = "F" ]] && echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.FAHRENHEIT}' || echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS}')
|
||||
# Expand space in StatusView
|
||||
sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ {
|
||||
@ -348,6 +394,27 @@ Ext.define('PVE.mod.TempHelper', {\n\
|
||||
},\n\
|
||||
});\n" "$pvemanagerlibjs"
|
||||
|
||||
if [[ $enableSystemInfo == "true" ]]; then
|
||||
sed -i "/^Ext.define('PVE.node.StatusView',/ {
|
||||
:a;
|
||||
/items:/!{N;ba;}
|
||||
:b;
|
||||
/cpus.*},/!{N;bb;}
|
||||
a\
|
||||
\\
|
||||
{\n\
|
||||
itemId: 'sysinfo',\n\
|
||||
colspan: 2,\n\
|
||||
printBar: false,\n\
|
||||
title: gettext('System Information'),\n\
|
||||
textField: 'systemInfo',\n\
|
||||
renderer: function(value){\n\
|
||||
return value;\n\
|
||||
}\n\
|
||||
},
|
||||
}" "$pvemanagerlibjs"
|
||||
fi
|
||||
|
||||
sed -i "/^Ext.define('PVE.node.StatusView',/ {
|
||||
:a;
|
||||
/items:/!{N;ba;}
|
||||
@ -738,6 +805,35 @@ function restart_proxy {
|
||||
systemctl restart pveproxy
|
||||
}
|
||||
|
||||
function save_sensors_data {
|
||||
# Check if DEBUG_SAVE_PATH exists and is writable
|
||||
if [[ ! -d "$DEBUG_SAVE_PATH" || ! -w "$DEBUG_SAVE_PATH" ]]; then
|
||||
err "Directory $DEBUG_SAVE_PATH does not exist or is not writable. No file could be saved"
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if command exists
|
||||
if (command -v sensors &>/dev/null); then
|
||||
# Save sensors output
|
||||
local filepath="${DEBUG_SAVE_PATH}/${DEBUG_SAVE_FILENAME}"
|
||||
echo "Sensors data will be saved in $filepath"
|
||||
|
||||
# Prompt user for confirmation
|
||||
read -p "Do you wish to continue? (y/n): " choice
|
||||
case "$choice" in
|
||||
y|Y )
|
||||
sensors -j > "$filepath"
|
||||
msgb "Sensors data saved in $filepath"
|
||||
;;
|
||||
* )
|
||||
echo "Operation cancelled by user."
|
||||
;;
|
||||
esac
|
||||
else
|
||||
err "Sensors is not installed. No file could be saved"
|
||||
fi
|
||||
}
|
||||
|
||||
# Process the arguments using a while loop and a case statement
|
||||
executed=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
@ -755,6 +851,12 @@ while [[ $# -gt 0 ]]; do
|
||||
uninstall_mod
|
||||
echo # add a new line
|
||||
;;
|
||||
save-sensors-data)
|
||||
executed=$(($executed + 1))
|
||||
msgb "\nSaving current sensor readings in a file for debugging..."
|
||||
save_sensors_data
|
||||
echo # add a new line
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user