Add system information #2 (#47)

This commit is contained in:
Meliox 2024-06-15 17:01:42 +02:00 committed by GitHub
parent f00005385e
commit 76e28b9d7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -198,6 +198,22 @@ function configure {
;; ;;
esac esac
fi 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 echo # add a new line
} }
@ -213,27 +229,37 @@ function install_mod {
local timestamp=$(date '+%Y-%m-%d_%H-%M-%S') local timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
# Add new line to Nodes.pm file # Perform backup
if [[ -z $(cat $nodespm | grep -e "$res->{sensorsOutput}") ]]; then if [[ -z $(cat $nodespm | grep -e "$res->{sensorsOutput}") ]] || [[ -z $(cat $nodespm | grep -e "$res->{systemInfo}") ]]; then
# Create backup of original file # Create backup of original file
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\"."
# 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
# 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" local sensorsCmd="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" 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 fi
warn "Sensors' output already integrated in in \"$nodespm\"."
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 fi
# Add new item to the items array in PVE.node.StatusView # Add new item to the items array in PVE.node.StatusView
if [[ -z $(cat "$pvemanagerlibjs" | grep -e "itemId: 'thermal[[:alnum:]]*'") ]]; then 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}') 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 # Expand space in StatusView
sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ { sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ {
@ -331,6 +357,27 @@ Ext.define('PVE.mod.TempHelper', {\n\
},\n\ },\n\
});\n" "$pvemanagerlibjs" });\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',/ { sed -i "/^Ext.define('PVE.node.StatusView',/ {
:a; :a;
/items:/!{N;ba;} /items:/!{N;ba;}