cleanup of messages
This commit is contained in:
parent
c8c8a36807
commit
605499c4cd
@ -40,35 +40,40 @@ JSON_EXPORT_FILENAME="sensorsdata.json"
|
|||||||
PVE_MANAGER_LIB_JS_FILE="/usr/share/pve-manager/js/pvemanagerlib.js"
|
PVE_MANAGER_LIB_JS_FILE="/usr/share/pve-manager/js/pvemanagerlib.js"
|
||||||
NODES_PM_FILE="/usr/share/perl5/PVE/API2/Nodes.pm"
|
NODES_PM_FILE="/usr/share/perl5/PVE/API2/Nodes.pm"
|
||||||
|
|
||||||
# Helper functions
|
#region message tools
|
||||||
function msg {
|
# Section header (bold)
|
||||||
echo -e "\e[0m$1\e[0m"
|
function msgb() {
|
||||||
|
local message="$1"
|
||||||
|
echo -e "\e[1m${message}\e[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
#echo message in bold
|
# Info (green)
|
||||||
function msgb {
|
function info() {
|
||||||
echo -e "\e[1m$1\e[0m"
|
local message="$1"
|
||||||
|
echo -e "\e[0;32m[info] ${message}\e[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
function info {
|
# Warning (yellow)
|
||||||
echo -e "\e[0;32m[info] $1\e[0m"
|
function warn() {
|
||||||
|
local message="$1"
|
||||||
|
echo -e "\e[0;33m[warning] ${message}\e[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
function warn {
|
# Error (red)
|
||||||
echo -e "\e[0;93m[warning] $1\e[0m"
|
function err() {
|
||||||
}
|
local message="$1"
|
||||||
|
echo -e "\e[0;31m[error] ${message}\e[0m"
|
||||||
function err {
|
|
||||||
echo -e "\e[0;31m[error] $1\e[0m"
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask {
|
# Prompts (cyan or bold)
|
||||||
read -p $'\n\e[0;32m'"$1:"$'\e[0m'" " response
|
function ask() {
|
||||||
echo $response
|
local prompt="$1"
|
||||||
|
local response
|
||||||
|
read -p $'\n\e[1;36m'"${prompt}:"$'\e[0m ' response
|
||||||
|
echo "$response"
|
||||||
}
|
}
|
||||||
|
#endregion message tools
|
||||||
# End of helper functions
|
|
||||||
|
|
||||||
# Function to display usage information
|
# Function to display usage information
|
||||||
function usage {
|
function usage {
|
||||||
@ -110,57 +115,59 @@ function configure {
|
|||||||
SENSORS_DETECTED=false
|
SENSORS_DETECTED=false
|
||||||
local sensorsOutput
|
local sensorsOutput
|
||||||
|
|
||||||
if [ $DEBUG_REMOTE = true ]; then
|
# Load sensor data
|
||||||
|
if [ "$DEBUG_REMOTE" = true ]; then
|
||||||
warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used."
|
warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used."
|
||||||
sensorsOutput=$(cat $DEBUG_JSON_FILE)
|
sensorsOutput=$(cat "$DEBUG_JSON_FILE")
|
||||||
else
|
else
|
||||||
sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool)
|
sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool)
|
||||||
fi
|
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..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if CPU is part of known list for autoconfiguration
|
#### CPU ####
|
||||||
msg "\nDetecting support for CPU temperature sensors..."
|
msgb "\n=== Detecting CPU temperature sensors ==="
|
||||||
|
ENABLE_CPU=false
|
||||||
|
local cpuList=()
|
||||||
for item in "${KNOWN_CPU_SENSORS[@]}"; do
|
for item in "${KNOWN_CPU_SENSORS[@]}"; do
|
||||||
if (echo "$sensorsOutput" | grep -q "$item"); then
|
if echo "$sensorsOutput" | grep -q "$item"; then
|
||||||
echo $item
|
cpuList+=("$item")
|
||||||
ENABLE_CPU=true
|
ENABLE_CPU=true
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Prompt user for which CPU temperature to use
|
if [ "$ENABLE_CPU" = true ]; then
|
||||||
if [ $ENABLE_CPU = true ]; then
|
info "Detected CPU sensors (${#cpuList[@]}): $(IFS=,; echo "${cpuList[*]}")"
|
||||||
|
SENSORS_DETECTED=true
|
||||||
while true; do
|
while true; do
|
||||||
local choiceTempDisplayType=$(ask "Do you wish to display temperatures for all cores [C] or just an average temperature per CPU [a] (note: AMD only supports average)? (C/a)")
|
local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (AMD only supports average)? (C/a)")
|
||||||
case "$choiceTempDisplayType" in
|
case "$choice" in
|
||||||
# Set temperature search criteria
|
|
||||||
[cC]|"")
|
[cC]|"")
|
||||||
CPU_TEMP_TARGET="Core"
|
CPU_TEMP_TARGET="Core"
|
||||||
info "Temperatures will be displayed for all cores."
|
info "Temperatures will be displayed for all cores."
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
[aA])
|
[aA])
|
||||||
CPU_TEMP_TARGET="Package"
|
CPU_TEMP_TARGET="Package"
|
||||||
info "An average temperature will be displayed per CPU."
|
info "An average temperature will be displayed per CPU."
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# If the user enters an invalid input, print an warning message and retry as>
|
warn "Invalid input, please choose C or a."
|
||||||
warn "Invalid input."
|
|
||||||
continue
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
break
|
|
||||||
done
|
done
|
||||||
SENSORS_DETECTED=true
|
|
||||||
else
|
else
|
||||||
warn "No CPU temperature sensors found."
|
warn "No CPU temperature sensors found."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if RAM temperature sensors are available
|
#### RAM ####
|
||||||
msg "\nDetecting support for RAM temperature sensors..."
|
msgb "\n=== Detecting RAM temperature sensors ==="
|
||||||
if echo "$sensorsOutput" | grep -Eq '"SODIMM[0-9]{0,2}":'; then
|
local ramList=($(echo "$sensorsOutput" | grep -o '"SODIMM[^"]*"' | sed 's/"//g'))
|
||||||
msg "Detected RAM temperature sensors:\n$(echo "$sensorsOutput" | grep -o '"SODIMM[^"]*"' | sed 's/"//g')"
|
if [ ${#ramList[@]} -gt 0 ]; then
|
||||||
|
info "Detected RAM sensors (${#ramList[@]}): $(IFS=,; echo "${ramList[*]}")"
|
||||||
ENABLE_RAM_TEMP=true
|
ENABLE_RAM_TEMP=true
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
else
|
else
|
||||||
@ -168,40 +175,23 @@ function configure {
|
|||||||
ENABLE_RAM_TEMP=false
|
ENABLE_RAM_TEMP=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if HDD/SDD data is available
|
#### HDD/SSD ####
|
||||||
msg "\nDetecting support for HDD/SDD temperature sensors..."
|
msgb "\n=== Detecting HDD/SSD temperature sensors ==="
|
||||||
if [ $DEBUG_REMOTE = true ]; then
|
local hddList=($(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g'))
|
||||||
# Check if debug file contains HDD/SSD data
|
if [ ${#hddList[@]} -gt 0 ]; then
|
||||||
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-"); then
|
info "Detected HDD/SSD sensors (${#hddList[@]}): $(IFS=,; echo "${hddList[*]}")"
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
|
||||||
ENABLE_HDD_TEMP=true
|
ENABLE_HDD_TEMP=true
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
else
|
|
||||||
warn "No HDD/SSD temperature sensors found in debug data."
|
|
||||||
ENABLE_HDD_TEMP=false
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Check if kernel module is loaded
|
|
||||||
if (lsmod | grep -wq "drivetemp"); then
|
|
||||||
# Check if SDD/HDD data is available
|
|
||||||
if (echo "$sensorsOutput" | grep -q "drivetemp-scsi-"); then
|
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"drivetemp-scsi[^"]*"' | sed 's/"//g')"
|
|
||||||
ENABLE_HDD_TEMP=true
|
|
||||||
SENSORS_DETECTED=true
|
|
||||||
else
|
|
||||||
warn "Kernel module \"drivetemp\" is not installed. HDD/SDD temperatures will not be available."
|
|
||||||
ENABLE_HDD_TEMP=false
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
warn "No HDD/SSD temperature sensors found."
|
warn "No HDD/SSD temperature sensors found."
|
||||||
ENABLE_HDD_TEMP=false
|
ENABLE_HDD_TEMP=false
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if NVMe temperature sensors are available
|
#### NVMe ####
|
||||||
msg "\nDetecting support for NVMe temperature sensors..."
|
msgb "\n=== Detecting NVMe temperature sensors ==="
|
||||||
if (echo "$sensorsOutput" | grep -q "nvme-"); then
|
local nvmeList=($(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g'))
|
||||||
msg "Detected sensors:\n$(echo "$sensorsOutput" | grep -o '"nvme[^"]*"' | sed 's/"//g')"
|
if [ ${#nvmeList[@]} -gt 0 ]; then
|
||||||
|
info "Detected NVMe sensors (${#nvmeList[@]}): $(IFS=,; echo "${nvmeList[*]}")"
|
||||||
ENABLE_NVME_TEMP=true
|
ENABLE_NVME_TEMP=true
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
else
|
else
|
||||||
@ -209,27 +199,28 @@ function configure {
|
|||||||
ENABLE_NVME_TEMP=false
|
ENABLE_NVME_TEMP=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if fan speed sensors are available
|
#### Fans ####
|
||||||
msg "\nDetecting support for fan speed readings..."
|
msgb "\n=== Detecting fan speed sensors ==="
|
||||||
if (echo "$sensorsOutput" | grep -q "fan[0-9]*_input"); then
|
local fanList=$(echo "$sensorsOutput" | grep -B 1 '"fan[0-9]*_input"' | grep -Po '"[^"]*":\s*\{$' | sed 's/"//g' | sed 's/: {//' | paste -sd ',' -)
|
||||||
msg "Detected fan speed sensors:\n$(echo $sensorsOutput | grep -Po '"[^"]*":\s*\{\s*"fan[0-9]*_input[^}]*' | sed -E 's/"([^"]*)":.*/\1/')"
|
local fanCount=$(echo "$sensorsOutput" | grep -c '"fan[0-9]*_input"')
|
||||||
|
if [ ${#fanList[@]} -gt 0 ]; then
|
||||||
|
info "Detected fan speed sensors ($fanCount): $fanList"
|
||||||
ENABLE_FAN_SPEED=true
|
ENABLE_FAN_SPEED=true
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
# Prompt user for display zero speed fans
|
|
||||||
local choiceDisplayZeroSpeedFans=$(ask "Do you wish to display fans reporting a speed of zero? If no, only active fans will be displayed. (Y/n)")
|
local choice=$(ask "Display fans reporting zero speed? (Y/n)")
|
||||||
case "$choiceDisplayZeroSpeedFans" in
|
case "$choice" in
|
||||||
# Set temperature search criteria
|
|
||||||
[yY]|"")
|
[yY]|"")
|
||||||
DISPLAY_ZERO_SPEED_FANS=true
|
DISPLAY_ZERO_SPEED_FANS=true
|
||||||
info "Fans reporting a speed of zero will be displayed."
|
info "Zero-speed fans will be displayed."
|
||||||
;;
|
;;
|
||||||
[nN])
|
[nN])
|
||||||
DISPLAY_ZERO_SPEED_FANS=false
|
DISPLAY_ZERO_SPEED_FANS=false
|
||||||
info "Fans reporting a speed of zero will NOT be displayed."
|
info "Only active fans will be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# If the user enters an invalid input, print an error message and exit the script with a non-zero status code
|
warn "Invalid input. Defaulting to show zero-speed fans."
|
||||||
err "Invalid input. Exiting..."
|
DISPLAY_ZERO_SPEED_FANS=true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
@ -237,156 +228,155 @@ function configure {
|
|||||||
ENABLE_FAN_SPEED=false
|
ENABLE_FAN_SPEED=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $SENSORS_DETECTED = true ]; then
|
#### Temperature Units ####
|
||||||
local choiceTempUnit=$(ask "Do you wish to display temperatures in degrees Celsius [C] or Fahrenheit [f]? (C/f)")
|
if [ "$SENSORS_DETECTED" = true ]; then
|
||||||
case "$choiceTempUnit" in
|
local unit=$(ask "Display temperatures in Celsius [C] or Fahrenheit [f]? (C/f)")
|
||||||
|
case "$unit" in
|
||||||
[cC]|"")
|
[cC]|"")
|
||||||
TEMP_UNIT="C"
|
TEMP_UNIT="C"
|
||||||
info "Temperatures will be presented in degrees Celsius."
|
info "Using Celsius."
|
||||||
;;
|
;;
|
||||||
[fF])
|
[fF])
|
||||||
TEMP_UNIT="F"
|
TEMP_UNIT="F"
|
||||||
info "Temperatures will be presented in degrees Fahrenheit."
|
info "Using Fahrenheit."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid unit selected. Temperatures will be displayed in degrees Celsius."
|
warn "Invalid selection. Defaulting to Celsius."
|
||||||
TEMP_UNIT="C"
|
TEMP_UNIT="C"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prompt user for enabling UPS
|
#### UPS ####
|
||||||
local choiseEnableUPS=$(ask "Do you wish to enable information from an attached UPS (requires configured UPS server and installed UPS client from Network UPS Tools already configured beforehand). (Y/n)")
|
local choiceUPS=$(ask "Enable UPS information? (Y/n)")
|
||||||
case "$choiseEnableUPS" in
|
case "$choiceUPS" in
|
||||||
[yY]|"")
|
[yY]|"")
|
||||||
# Test the connection using upsc command
|
if [ "$DEBUG_REMOTE" = true ]; then
|
||||||
if [ $DEBUG_REMOTE = true ]; then
|
upsOutput=$(cat "$DEBUG_UPS_FILE")
|
||||||
upsOutput=$(cat $DEBUG_UPS_FILE)
|
echo "Remote debugging: UPS readings from $DEBUG_UPS_FILE"
|
||||||
echo "Remote debugging is used. UPS readings from dump file $DEBUG_UPS_FILE will be used."
|
|
||||||
upsConnection="DEBUG_UPS"
|
upsConnection="DEBUG_UPS"
|
||||||
else
|
else
|
||||||
# Prompt user for UPS connection details
|
upsConnection=$(ask "Enter UPS connection (e.g., upsname[@hostname[:port]])")
|
||||||
upsConnection=$(ask "Enter connection details for the UPS (e.g., upsname[@hostname[:port]])")
|
if ! command -v upsc &>/dev/null; then
|
||||||
|
err "The 'upsc' command is not available. Install 'nut-client'."
|
||||||
if (! command -v upsc &>/dev/null); then
|
|
||||||
err "The 'upsc' command is not available. Please install the 'nut-client' package and ensure it is configured correctly. Exiting..."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
upsOutput=$(upsc "$upsConnection" 2>&1)
|
upsOutput=$(upsc "$upsConnection" 2>&1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for device.model in the output to confirm successful connection
|
if echo "$upsOutput" | grep -q "device.model:"; then
|
||||||
if (echo "$upsOutput" | grep -q "device.model:"); then
|
|
||||||
# Extract the model name
|
|
||||||
modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d':' -f2- | xargs)
|
modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d':' -f2- | xargs)
|
||||||
ENABLE_UPS=true
|
ENABLE_UPS=true
|
||||||
echo "Successfully connected to UPS model: $modelName at $upsConnection."
|
info "Connected to UPS model: $modelName at $upsConnection."
|
||||||
info "UPS information will be displayed..."
|
|
||||||
else
|
else
|
||||||
warn "Failed to connect to UPS at '$upsConnection'. No valid UPS model found."
|
warn "Failed to connect to UPS at '$upsConnection'."
|
||||||
warn "Error: $upsOutput"
|
|
||||||
ENABLE_UPS=false
|
ENABLE_UPS=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
;;
|
;;
|
||||||
[nN])
|
[nN])
|
||||||
ENABLE_UPS=false
|
ENABLE_UPS=false
|
||||||
info "UPS information will NOT be displayed..."
|
info "UPS information will NOT be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid selection. UPS information will not be displayed."
|
warn "Invalid selection. UPS info will NOT be displayed."
|
||||||
ENABLE_UPS=false
|
ENABLE_UPS=false
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
echo ""
|
|
||||||
|
|
||||||
# DMI Type:
|
#### System Info ####
|
||||||
# 1 ... System Information
|
msgb "\n=== System Information ==="
|
||||||
# 2 ... Base Board Information (for self-made PC)
|
|
||||||
for i in 1 2; do
|
for i in 1 2; do
|
||||||
echo "type ${i})"
|
echo "type ${i})"
|
||||||
dmidecode -t ${i} | awk -F': ' '/Manufacturer|Product Name|Serial Number/ {print $1": "$2}'
|
dmidecode -t "$i" | awk -F': ' '/Manufacturer|Product Name|Serial Number/ {print $1": "$2}'
|
||||||
done
|
done
|
||||||
local choiceEnableSystemInfo=$(ask "Do you wish to enable system information? (1/2/n)")
|
local choiceSysInfo=$(ask "Enable system information? (1/2/n)")
|
||||||
case "$choiceEnableSystemInfo" in
|
case "$choiceSysInfo" in
|
||||||
[1]|"")
|
[1]|"")
|
||||||
ENABLE_SYSTEM_INFO=true
|
ENABLE_SYSTEM_INFO=true
|
||||||
SYSTEM_INFO_TYPE=1
|
SYSTEM_INFO_TYPE=1
|
||||||
info "System information will be displayed..."
|
info "System information will be displayed."
|
||||||
;;
|
;;
|
||||||
[2])
|
[2])
|
||||||
ENABLE_SYSTEM_INFO=true
|
ENABLE_SYSTEM_INFO=true
|
||||||
SYSTEM_INFO_TYPE=2
|
SYSTEM_INFO_TYPE=2
|
||||||
info "Motherboard information will be displayed..."
|
info "Motherboard information will be displayed."
|
||||||
;;
|
;;
|
||||||
[nN])
|
[nN])
|
||||||
ENABLE_SYSTEM_INFO=false
|
ENABLE_SYSTEM_INFO=false
|
||||||
info "System information will NOT be displayed..."
|
info "System information will NOT be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid selection. System information will be displayed."
|
warn "Invalid selection. Defaulting to system information."
|
||||||
ENABLE_SYSTEM_INFO=true
|
ENABLE_SYSTEM_INFO=true
|
||||||
|
SYSTEM_INFO_TYPE=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ $SENSORS_DETECTED = false ] && [ $ENABLE_UPS = false ] && [ $ENABLE_SYSTEM_INFO = false ]; then
|
#### Final Check ####
|
||||||
err "No sensors detected and neither UPS nor system information enabled. Exiting..."
|
if [ "$SENSORS_DETECTED" = false ] && [ "$ENABLE_UPS" = false ] && [ "$ENABLE_SYSTEM_INFO" = false ]; then
|
||||||
|
err "No sensors detected, UPS or system info enabled. Exiting."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo # add a new line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Function to install the modification
|
# Function to install the modification
|
||||||
function install_mod {
|
function install_mod {
|
||||||
msg "\nPreparing mod installation..."
|
msgb "\n== Preparing mod installation =="
|
||||||
check_root_privileges
|
check_root_privileges
|
||||||
check_mod_installation
|
check_mod_installation
|
||||||
configure
|
configure
|
||||||
perform_backup
|
perform_backup
|
||||||
|
|
||||||
# Insert information retrieval code
|
#### Insert information retrieval code ####
|
||||||
|
msgb "\n=== Inserting information retrieval code ==="
|
||||||
insert_node_info
|
insert_node_info
|
||||||
|
|
||||||
# Create temperature conversion helper parameters
|
#### Temperature helper parameters ####
|
||||||
HELPERCTORPARAMS=$([[ "$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}')
|
msgb "\n=== Creating temperature conversion helper ==="
|
||||||
|
HELPERCTORPARAMS=$([[ "$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}')
|
||||||
|
info "Temperature helper configured for $TEMP_UNIT."
|
||||||
|
|
||||||
# Expand space in StatusView
|
#### Expand StatusView space ####
|
||||||
expand_statusview_space
|
expand_statusview_space
|
||||||
|
|
||||||
# Insert temp helper
|
#### Insert temperature helper ####
|
||||||
generate_and_insert_temp_helper
|
generate_and_insert_temp_helper
|
||||||
|
|
||||||
# Generate and insert widgets using the helper function
|
#### Generate and insert widgets ####
|
||||||
generate_and_insert_widget "$ENABLE_SYSTEM_INFO" "generate_system_info" "system_info"
|
msgb "\n=== Generating and inserting widgets ==="
|
||||||
|
|
||||||
#
|
generate_and_insert_widget "$ENABLE_SYSTEM_INFO" "generate_system_info" "system_info"
|
||||||
# NOTE: The following items will be added in reverse order
|
|
||||||
#
|
|
||||||
generate_and_insert_widget "$ENABLE_UPS" "generate_ups_widget" "ups"
|
generate_and_insert_widget "$ENABLE_UPS" "generate_ups_widget" "ups"
|
||||||
generate_and_insert_widget "$ENABLE_HDD_TEMP" "generate_hdd_widget" "hdd"
|
generate_and_insert_widget "$ENABLE_HDD_TEMP" "generate_hdd_widget" "hdd"
|
||||||
generate_and_insert_widget "$ENABLE_NVME_TEMP" "generate_nvme_widget" "nvme"
|
generate_and_insert_widget "$ENABLE_NVME_TEMP" "generate_nvme_widget" "nvme"
|
||||||
|
|
||||||
# Add drive header boxes if either nvme or drive temp is enabled
|
if [[ "$ENABLE_HDD_TEMP" = true || "$ENABLE_NVME_TEMP" = true ]]; then
|
||||||
generate_drive_header
|
generate_drive_header
|
||||||
|
info "Drive headers added."
|
||||||
|
fi
|
||||||
|
|
||||||
generate_and_insert_widget "$ENABLE_FAN_SPEED" "generate_fan_widget" "fan"
|
generate_and_insert_widget "$ENABLE_FAN_SPEED" "generate_fan_widget" "fan"
|
||||||
generate_and_insert_widget "$ENABLE_RAM_TEMP" "generate_ram_widget" "ram"
|
generate_and_insert_widget "$ENABLE_RAM_TEMP" "generate_ram_widget" "ram"
|
||||||
generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu"
|
generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu"
|
||||||
|
|
||||||
# Add an empty line to separate modified items as a visual group
|
#### Visual separation ####
|
||||||
add_visual_separator
|
add_visual_separator
|
||||||
|
info "Added visual separator for modified items."
|
||||||
|
|
||||||
# Move the node summary box into its own container and deactivate the original box instance
|
#### Node summary ####
|
||||||
setup_node_summary_container
|
setup_node_summary_container
|
||||||
|
info "Node summary box moved into its own container."
|
||||||
|
|
||||||
|
msgb "\n=== Finalizing installation ==="
|
||||||
msg "Sensor display items added to the summary panel in \"$PVE_MANAGER_LIB_JS_FILE\"."
|
msg "Sensor display items added to the summary panel in \"$PVE_MANAGER_LIB_JS_FILE\"."
|
||||||
|
|
||||||
restart_proxy
|
restart_proxy
|
||||||
|
|
||||||
msg "Installation completed."
|
msg "Installation completed."
|
||||||
|
|
||||||
info "Clear the browser cache to ensure all changes are visualized."
|
info "Clear the browser cache to ensure all changes are visualized."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region node info insertion
|
#region node info insertion
|
||||||
# Main insertion routine
|
# Main insertion routine
|
||||||
insert_node_info() {
|
insert_node_info() {
|
||||||
@ -437,7 +427,7 @@ collect_sensors_output() {
|
|||||||
$res->{sensorsOutput} =~ s/\\"SODIMM\\":\\{\\"temp(\\d+)_input\\"/\\"SODIMM$1\\":\\{\\"temp$1_input\\"/g;\
|
$res->{sensorsOutput} =~ s/\\"SODIMM\\":\\{\\"temp(\\d+)_input\\"/\\"SODIMM$1\\":\\{\\"temp$1_input\\"/g;\
|
||||||
' "$NODES_PM_FILE"
|
' "$NODES_PM_FILE"
|
||||||
#endregion sensors heredoc
|
#endregion sensors heredoc
|
||||||
msg "Sensors' retriever added to \"$output_file\"."
|
info "Sensors' retriever added to \"$output_file\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Collect UPS data
|
# Collect UPS data
|
||||||
@ -457,7 +447,7 @@ collect_ups_output() {
|
|||||||
\$res->{upsc} = \\\`$ups_cmd\\\`;\\
|
\$res->{upsc} = \\\`$ups_cmd\\\`;\\
|
||||||
" "$NODES_PM_FILE"
|
" "$NODES_PM_FILE"
|
||||||
#endregion ups heredoc
|
#endregion ups heredoc
|
||||||
msg "UPS retriever added to \"$output_file\"."
|
info "UPS retriever added to \"$output_file\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Collect system information
|
# Collect system information
|
||||||
@ -474,7 +464,7 @@ collect_system_info() {
|
|||||||
#region system info heredoc
|
#region system info heredoc
|
||||||
sed -i "/my \$dinfo = df('\/', 1);/i\\\t\t\$res->{systemInfo} = \"$(echo "$systemInfoCmd")\";\n" "$NODES_PM_FILE"
|
sed -i "/my \$dinfo = df('\/', 1);/i\\\t\t\$res->{systemInfo} = \"$(echo "$systemInfoCmd")\";\n" "$NODES_PM_FILE"
|
||||||
#endregion system info heredoc
|
#endregion system info heredoc
|
||||||
msg "System information retriever added to \"$output_file\"."
|
info "System information retriever added to \"$output_file\"."
|
||||||
}
|
}
|
||||||
#endregion node info insertion
|
#endregion node info insertion
|
||||||
|
|
||||||
@ -530,6 +520,8 @@ EOF
|
|||||||
|
|
||||||
# Function to expand space and modify StatusView properties
|
# Function to expand space and modify StatusView properties
|
||||||
expand_statusview_space() {
|
expand_statusview_space() {
|
||||||
|
msgb "\n=== Expanding StatusView space ==="
|
||||||
|
|
||||||
# Apply multiple modifications to the StatusView definition
|
# Apply multiple modifications to the StatusView definition
|
||||||
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'/
|
||||||
@ -542,7 +534,7 @@ expand_statusview_space() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg "Expanded space in \"$PVE_MANAGER_LIB_JS_FILE\"."
|
info "Expanded space in \"$PVE_MANAGER_LIB_JS_FILE\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to move node summary into its own container
|
# Function to move node summary into its own container
|
||||||
@ -668,6 +660,8 @@ EOF
|
|||||||
generate_and_insert_temp_helper() {
|
generate_and_insert_temp_helper() {
|
||||||
local temp_js_file="/tmp/temp_helper.js"
|
local temp_js_file="/tmp/temp_helper.js"
|
||||||
|
|
||||||
|
msgb "\n=== Inserting temperature helper ==="
|
||||||
|
|
||||||
#region temp helper heredoc
|
#region temp helper heredoc
|
||||||
cat > "$temp_js_file" <<'EOF'
|
cat > "$temp_js_file" <<'EOF'
|
||||||
Ext.define('PVE.mod.TempHelper', {
|
Ext.define('PVE.mod.TempHelper', {
|
||||||
@ -765,6 +759,8 @@ EOF
|
|||||||
|
|
||||||
sed -i "/^Ext.define('PVE.node.StatusView'/e cat /tmp/temp_helper.js" "$PVE_MANAGER_LIB_JS_FILE"
|
sed -i "/^Ext.define('PVE.node.StatusView'/e cat /tmp/temp_helper.js" "$PVE_MANAGER_LIB_JS_FILE"
|
||||||
rm "$temp_js_file"
|
rm "$temp_js_file"
|
||||||
|
|
||||||
|
info "Temperature helper inserted successfully."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to generate CPU widget
|
# Function to generate CPU widget
|
||||||
@ -1516,13 +1512,13 @@ function set_backup_directory {
|
|||||||
if [[ -z "$BACKUP_DIR" ]]; then
|
if [[ -z "$BACKUP_DIR" ]]; then
|
||||||
# If not set, use the default backup directory, which is based on the home directory and PVE-MODS
|
# If not set, use the default backup directory, which is based on the home directory and PVE-MODS
|
||||||
BACKUP_DIR="$HOME/PVE-MODS"
|
BACKUP_DIR="$HOME/PVE-MODS"
|
||||||
msg "Using default backup directory: $BACKUP_DIR"
|
info "Using default backup directory: $BACKUP_DIR"
|
||||||
else
|
else
|
||||||
# If set, ensure it is a valid directory
|
# If set, ensure it is a valid directory
|
||||||
if [[ ! -d "$BACKUP_DIR" ]]; then
|
if [[ ! -d "$BACKUP_DIR" ]]; then
|
||||||
err "The specified backup directory does not exist: $BACKUP_DIR"
|
err "The specified backup directory does not exist: $BACKUP_DIR"
|
||||||
fi
|
fi
|
||||||
msg "Using custom backup directory: $BACKUP_DIR"
|
info "Using custom backup directory: $BACKUP_DIR"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1534,9 +1530,9 @@ function create_backup_directory {
|
|||||||
mkdir -p "$BACKUP_DIR" 2>/dev/null || {
|
mkdir -p "$BACKUP_DIR" 2>/dev/null || {
|
||||||
err "Failed to create backup directory: $BACKUP_DIR. Please check permissions."
|
err "Failed to create backup directory: $BACKUP_DIR. Please check permissions."
|
||||||
}
|
}
|
||||||
msg "Created backup directory: $BACKUP_DIR"
|
info "Created backup directory: $BACKUP_DIR"
|
||||||
else
|
else
|
||||||
msg "Backup directory already exists: $BACKUP_DIR"
|
info "Backup directory already exists: $BACKUP_DIR"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1558,13 +1554,15 @@ function create_file_backup() {
|
|||||||
err "Backup verification failed for: $backup_file"
|
err "Backup verification failed for: $backup_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg "Created backup: $backup_file"
|
info "Created backup: $backup_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
function perform_backup {
|
function perform_backup {
|
||||||
local timestamp
|
local timestamp
|
||||||
timestamp=$(date +%Y%m%d_%H%M%S)
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
||||||
|
|
||||||
|
msgb "\n===Creating backups of modified files ==="
|
||||||
|
|
||||||
create_backup_directory
|
create_backup_directory
|
||||||
create_file_backup "$NODES_PM_FILE" "$timestamp"
|
create_file_backup "$NODES_PM_FILE" "$timestamp"
|
||||||
create_file_backup "$PVE_MANAGER_LIB_JS_FILE" "$timestamp"
|
create_file_backup "$PVE_MANAGER_LIB_JS_FILE" "$timestamp"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user