cleanup of messages

This commit is contained in:
Meliox 2025-09-06 23:08:53 +02:00
parent c8c8a36807
commit 605499c4cd

View File

@ -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"
exit 1
} }
function err { # Prompts (cyan or bold)
echo -e "\e[0;31m[error] $1\e[0m" function ask() {
exit 1 local prompt="$1"
local response
read -p $'\n\e[1;36m'"${prompt}:"$'\e[0m ' response
echo "$response"
} }
#endregion message tools
function ask {
read -p $'\n\e[0;32m'"$1:"$'\e[0m'" " response
echo $response
}
# End of helper functions
# Function to display usage information # Function to display usage information
function usage { function usage {
@ -107,286 +112,271 @@ function install_packages {
} }
function configure { function configure {
SENSORS_DETECTED=false SENSORS_DETECTED=false
local sensorsOutput local sensorsOutput
if [ $DEBUG_REMOTE = true ]; then # Load sensor data
warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used." if [ "$DEBUG_REMOTE" = true ]; then
sensorsOutput=$(cat $DEBUG_JSON_FILE) warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used."
else sensorsOutput=$(cat "$DEBUG_JSON_FILE")
sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool) else
fi sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool)
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 ==="
for item in "${KNOWN_CPU_SENSORS[@]}"; do ENABLE_CPU=false
if (echo "$sensorsOutput" | grep -q "$item"); then local cpuList=()
echo $item for item in "${KNOWN_CPU_SENSORS[@]}"; do
ENABLE_CPU=true if echo "$sensorsOutput" | grep -q "$item"; then
fi cpuList+=("$item")
done ENABLE_CPU=true
fi
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[*]}")"
while true; do SENSORS_DETECTED=true
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)") while true; do
case "$choiceTempDisplayType" in local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (AMD only supports average)? (C/a)")
# Set temperature search criteria case "$choice" in
[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]) ;;
CPU_TEMP_TARGET="Package" [aA])
info "An average temperature will be displayed per CPU." CPU_TEMP_TARGET="Package"
;; 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." *)
continue warn "Invalid input, please choose C or a."
;; ;;
esac esac
break done
done else
SENSORS_DETECTED=true warn "No CPU temperature sensors found."
else fi
warn "No CPU temperature sensors found."
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
ENABLE_RAM_TEMP=true info "Detected RAM sensors (${#ramList[@]}): $(IFS=,; echo "${ramList[*]}")"
SENSORS_DETECTED=true ENABLE_RAM_TEMP=true
else SENSORS_DETECTED=true
warn "No RAM temperature sensors found." else
ENABLE_RAM_TEMP=false warn "No RAM temperature sensors found."
fi ENABLE_RAM_TEMP=false
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
else warn "No HDD/SSD temperature sensors found."
warn "No HDD/SSD temperature sensors found in debug data." ENABLE_HDD_TEMP=false
ENABLE_HDD_TEMP=false fi
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
warn "No HDD/SSD temperature sensors found."
ENABLE_HDD_TEMP=false
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
ENABLE_NVME_TEMP=true info "Detected NVMe sensors (${#nvmeList[@]}): $(IFS=,; echo "${nvmeList[*]}")"
SENSORS_DETECTED=true ENABLE_NVME_TEMP=true
else SENSORS_DETECTED=true
warn "No NVMe temperature sensors found." else
ENABLE_NVME_TEMP=false warn "No NVMe temperature sensors found."
fi ENABLE_NVME_TEMP=false
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"')
ENABLE_FAN_SPEED=true if [ ${#fanList[@]} -gt 0 ]; then
SENSORS_DETECTED=true info "Detected fan speed sensors ($fanCount): $fanList"
# Prompt user for display zero speed fans ENABLE_FAN_SPEED=true
local choiceDisplayZeroSpeedFans=$(ask "Do you wish to display fans reporting a speed of zero? If no, only active fans will be displayed. (Y/n)") SENSORS_DETECTED=true
case "$choiceDisplayZeroSpeedFans" in
# Set temperature search criteria
[yY]|"")
DISPLAY_ZERO_SPEED_FANS=true
info "Fans reporting a speed of zero will be displayed."
;;
[nN] )
DISPLAY_ZERO_SPEED_FANS=false
info "Fans reporting a speed of zero will NOT be displayed."
;;
*)
# If the user enters an invalid input, print an error message and exit the script with a non-zero status code
err "Invalid input. Exiting..."
;;
esac
else
warn "No fan speed sensors found."
ENABLE_FAN_SPEED=false
fi
if [ $SENSORS_DETECTED = true ]; then local choice=$(ask "Display fans reporting zero speed? (Y/n)")
local choiceTempUnit=$(ask "Do you wish to display temperatures in degrees Celsius [C] or Fahrenheit [f]? (C/f)") case "$choice" in
case "$choiceTempUnit" in [yY]|"")
[cC] | "") DISPLAY_ZERO_SPEED_FANS=true
TEMP_UNIT="C" info "Zero-speed fans will be displayed."
info "Temperatures will be presented in degrees Celsius." ;;
;; [nN])
[fF]) DISPLAY_ZERO_SPEED_FANS=false
TEMP_UNIT="F" info "Only active fans will be displayed."
info "Temperatures will be presented in degrees Fahrenheit." ;;
;; *)
*) warn "Invalid input. Defaulting to show zero-speed fans."
warn "Invalid unit selected. Temperatures will be displayed in degrees Celsius." DISPLAY_ZERO_SPEED_FANS=true
TEMP_UNIT="C" ;;
;; esac
esac else
fi warn "No fan speed sensors found."
ENABLE_FAN_SPEED=false
fi
# Prompt user for enabling UPS #### Temperature Units ####
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)") if [ "$SENSORS_DETECTED" = true ]; then
case "$choiseEnableUPS" in local unit=$(ask "Display temperatures in Celsius [C] or Fahrenheit [f]? (C/f)")
[yY] | "") case "$unit" in
# Test the connection using upsc command [cC]|"")
if [ $DEBUG_REMOTE = true ]; then TEMP_UNIT="C"
upsOutput=$(cat $DEBUG_UPS_FILE) info "Using Celsius."
echo "Remote debugging is used. UPS readings from dump file $DEBUG_UPS_FILE will be used." ;;
upsConnection="DEBUG_UPS" [fF])
else TEMP_UNIT="F"
# Prompt user for UPS connection details info "Using Fahrenheit."
upsConnection=$(ask "Enter connection details for the UPS (e.g., upsname[@hostname[:port]])") ;;
*)
warn "Invalid selection. Defaulting to Celsius."
TEMP_UNIT="C"
;;
esac
fi
if (! command -v upsc &>/dev/null); then #### UPS ####
err "The 'upsc' command is not available. Please install the 'nut-client' package and ensure it is configured correctly. Exiting..." local choiceUPS=$(ask "Enable UPS information? (Y/n)")
fi case "$choiceUPS" in
[yY]|"")
if [ "$DEBUG_REMOTE" = true ]; then
upsOutput=$(cat "$DEBUG_UPS_FILE")
echo "Remote debugging: UPS readings from $DEBUG_UPS_FILE"
upsConnection="DEBUG_UPS"
else
upsConnection=$(ask "Enter UPS connection (e.g., upsname[@hostname[:port]])")
if ! command -v upsc &>/dev/null; then
err "The 'upsc' command is not available. Install 'nut-client'."
fi
upsOutput=$(upsc "$upsConnection" 2>&1)
fi
upsOutput=$(upsc "$upsConnection" 2>&1) if echo "$upsOutput" | grep -q "device.model:"; then
fi modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d':' -f2- | xargs)
ENABLE_UPS=true
info "Connected to UPS model: $modelName at $upsConnection."
else
warn "Failed to connect to UPS at '$upsConnection'."
ENABLE_UPS=false
fi
;;
[nN])
ENABLE_UPS=false
info "UPS information will NOT be displayed."
;;
*)
warn "Invalid selection. UPS info will NOT be displayed."
ENABLE_UPS=false
;;
esac
# Check for device.model in the output to confirm successful connection #### System Info ####
if (echo "$upsOutput" | grep -q "device.model:"); then msgb "\n=== System Information ==="
# Extract the model name for i in 1 2; do
modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d':' -f2- | xargs) echo "type ${i})"
ENABLE_UPS=true dmidecode -t "$i" | awk -F': ' '/Manufacturer|Product Name|Serial Number/ {print $1": "$2}'
echo "Successfully connected to UPS model: $modelName at $upsConnection." done
info "UPS information will be displayed..." local choiceSysInfo=$(ask "Enable system information? (1/2/n)")
else case "$choiceSysInfo" in
warn "Failed to connect to UPS at '$upsConnection'. No valid UPS model found." [1]|"")
warn "Error: $upsOutput" ENABLE_SYSTEM_INFO=true
ENABLE_UPS=false SYSTEM_INFO_TYPE=1
fi info "System information will be displayed."
;;
[2])
ENABLE_SYSTEM_INFO=true
SYSTEM_INFO_TYPE=2
info "Motherboard information will be displayed."
;;
[nN])
ENABLE_SYSTEM_INFO=false
info "System information will NOT be displayed."
;;
*)
warn "Invalid selection. Defaulting to system information."
ENABLE_SYSTEM_INFO=true
SYSTEM_INFO_TYPE=1
;;
esac
;; #### Final Check ####
[nN]) if [ "$SENSORS_DETECTED" = false ] && [ "$ENABLE_UPS" = false ] && [ "$ENABLE_SYSTEM_INFO" = false ]; then
ENABLE_UPS=false err "No sensors detected, UPS or system info enabled. Exiting."
info "UPS information will NOT be displayed..." fi
;;
*)
warn "Invalid selection. UPS information will not be displayed."
ENABLE_UPS=false
;;
esac
echo ""
# DMI Type:
# 1 ... System Information
# 2 ... Base Board Information (for self-made PC)
for i in 1 2; do
echo "type ${i})"
dmidecode -t ${i} | awk -F': ' '/Manufacturer|Product Name|Serial Number/ {print $1": "$2}'
done
local choiceEnableSystemInfo=$(ask "Do you wish to enable system information? (1/2/n)")
case "$choiceEnableSystemInfo" in
[1] | "")
ENABLE_SYSTEM_INFO=true
SYSTEM_INFO_TYPE=1
info "System information will be displayed..."
;;
[2])
ENABLE_SYSTEM_INFO=true
SYSTEM_INFO_TYPE=2
info "Motherboard information will be displayed..."
;;
[nN])
ENABLE_SYSTEM_INFO=false
info "System information will NOT be displayed..."
;;
*)
warn "Invalid selection. System information will be displayed."
ENABLE_SYSTEM_INFO=true
;;
esac
if [ $SENSORS_DETECTED = false ] && [ $ENABLE_UPS = false ] && [ $ENABLE_SYSTEM_INFO = false ]; then
err "No sensors detected and neither UPS nor system information enabled. Exiting..."
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 ####
insert_node_info msgb "\n=== Inserting information retrieval code ==="
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_HDD_TEMP" "generate_hdd_widget" "hdd"
generate_and_insert_widget "$ENABLE_UPS" "generate_ups_widget" "ups" generate_and_insert_widget "$ENABLE_NVME_TEMP" "generate_nvme_widget" "nvme"
generate_and_insert_widget "$ENABLE_HDD_TEMP" "generate_hdd_widget" "hdd"
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
generate_and_insert_widget "$ENABLE_FAN_SPEED" "generate_fan_widget" "fan" info "Drive headers added."
generate_and_insert_widget "$ENABLE_RAM_TEMP" "generate_ram_widget" "ram" fi
generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu"
# Add an empty line to separate modified items as a visual group generate_and_insert_widget "$ENABLE_FAN_SPEED" "generate_fan_widget" "fan"
add_visual_separator generate_and_insert_widget "$ENABLE_RAM_TEMP" "generate_ram_widget" "ram"
generate_and_insert_widget "$ENABLE_CPU" "generate_cpu_widget" "cpu"
# Move the node summary box into its own container and deactivate the original box instance #### Visual separation ####
setup_node_summary_container add_visual_separator
info "Added visual separator for modified items."
msg "Sensor display items added to the summary panel in \"$PVE_MANAGER_LIB_JS_FILE\"." #### Node summary ####
setup_node_summary_container
info "Node summary box moved into its own container."
restart_proxy msgb "\n=== Finalizing installation ==="
msg "Sensor display items added to the summary panel in \"$PVE_MANAGER_LIB_JS_FILE\"."
msg "Installation completed." restart_proxy
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"