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

This commit is contained in:
Meliox 2024-06-15 19:09:34 +02:00
commit 03b191aa7a

View File

@ -210,6 +210,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
}
@ -225,12 +241,22 @@ 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\"."
# 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\""
@ -241,16 +267,16 @@ function install_mod {
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 +374,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;}