Merge c1773dd0c4 into 6246669adc
This commit is contained in:
commit
0c8ca7d9cd
33
pve-mod-gui-sensors.settings
Normal file
33
pve-mod-gui-sensors.settings
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Action when lm_sensors not installed
|
||||||
|
# y - install required packages
|
||||||
|
# n - skip installation
|
||||||
|
CONFIG_INSTALL_LM_SENSORS=""
|
||||||
|
|
||||||
|
# CPU temperature(s)
|
||||||
|
# c - show temperatures for every cores
|
||||||
|
# a - show average temperature per CPU
|
||||||
|
CONFIG_CPU_TEMP_MODE=""
|
||||||
|
|
||||||
|
# Fan speed(s)
|
||||||
|
# y - show active and inactive fans
|
||||||
|
# n - show only active fans
|
||||||
|
CONFIG_FAN_ZERO_SPEED_DISPLAY=""
|
||||||
|
|
||||||
|
# Temperature unit
|
||||||
|
# c - Celsius
|
||||||
|
# f - Fahrenheit
|
||||||
|
CONFIG_TEMP_UNIT=""
|
||||||
|
|
||||||
|
# UPS information
|
||||||
|
# y - show UPS information
|
||||||
|
# n - ignore UPS information
|
||||||
|
CONFIG_UPS_SHOW_INFO=""
|
||||||
|
|
||||||
|
# UPS connection, e.g.: upsname[@hostname[:port]]
|
||||||
|
CONFIG_UPS_CONNECTION=""
|
||||||
|
|
||||||
|
# System information
|
||||||
|
# n - ignore system information
|
||||||
|
# 1 - show system information
|
||||||
|
# 2 - show motherboard information
|
||||||
|
CONFIG_SYSINFO_DISPLAY_MODE=""
|
||||||
@ -40,6 +40,8 @@ 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"
|
||||||
|
|
||||||
|
UNATTENDED_MODE=false
|
||||||
|
|
||||||
#region message tools
|
#region message tools
|
||||||
# Section header (bold)
|
# Section header (bold)
|
||||||
function msgb() {
|
function msgb() {
|
||||||
@ -69,8 +71,13 @@ function err() {
|
|||||||
# Prompts (cyan or bold)
|
# Prompts (cyan or bold)
|
||||||
function ask() {
|
function ask() {
|
||||||
local prompt="$1"
|
local prompt="$1"
|
||||||
|
local configVarName="$2"
|
||||||
local response
|
local response
|
||||||
read -p $'\n\e[1;36m'"${prompt}:"$'\e[0m ' response
|
if [[ -n configVarName && -n "${!configVarName}" ]]; then
|
||||||
|
response="${!configVarName}"
|
||||||
|
else
|
||||||
|
read -p $'\n\e[1;36m'"${prompt}:"$'\e[0m ' response
|
||||||
|
fi
|
||||||
echo "$response"
|
echo "$response"
|
||||||
}
|
}
|
||||||
#endregion message tools
|
#endregion message tools
|
||||||
@ -81,19 +88,40 @@ function usage {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function show_clear_browser_cache_msg() {
|
||||||
|
local clearCacheMsg="Clear the browser cache to ensure that all changes are visible."
|
||||||
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
|
echo -e "\n\e[1;42;97m${clearCacheMsg}\e[0m\n"
|
||||||
|
else
|
||||||
|
ask "$clearCacheMsg (press any key to continue)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# System checks
|
# System checks
|
||||||
function check_root_privileges() {
|
function check_root_privileges {
|
||||||
[[ $EUID -eq 0 ]] || err "This script must be run as root. Please run it with 'sudo $0'."
|
[[ $EUID -eq 0 ]] || err "This script must be run as root. Please run it with 'sudo $0'."
|
||||||
info "Root privileges verified."
|
info "Root privileges verified."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load_settings {
|
||||||
|
if [ -r "$SCRIPT_CWD/pve-mod-gui-sensors.settings" ]; then
|
||||||
|
msgb "\n=== Configuration file detected ==="
|
||||||
|
. "$SCRIPT_CWD/pve-mod-gui-sensors.settings"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
info "Settings for unattended installation loaded."
|
||||||
|
UNATTENDED_MODE=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Define a function to install packages
|
# Define a function to install packages
|
||||||
function install_packages {
|
function install_packages {
|
||||||
# Check if the 'sensors' command is available on the system
|
# Check if the 'sensors' command is available on the system
|
||||||
if (! command -v sensors &>/dev/null); then
|
if (! command -v sensors &>/dev/null); then
|
||||||
|
|
||||||
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
||||||
local choiceInstallLmSensors=$(ask "lm-sensors is not installed. Would you like to install it? (y/n)")
|
local choice=$(ask "lm-sensors is not installed. Would you like to install it? (y/n)" CONFIG_INSTALL_LM_SENSORS)
|
||||||
case "$choiceInstallLmSensors" in
|
case "$choice" in
|
||||||
[yY])
|
[yY])
|
||||||
# If the user chooses to install lm-sensors, update the package list and install the package
|
# If the user chooses to install lm-sensors, update the package list and install the package
|
||||||
apt-get update
|
apt-get update
|
||||||
@ -172,8 +200,9 @@ function configure {
|
|||||||
if [ "$ENABLE_CPU" = true ]; then
|
if [ "$ENABLE_CPU" = true ]; then
|
||||||
info "Detected CPU sensors ($cpuCount): $cpuList"
|
info "Detected CPU sensors ($cpuCount): $cpuList"
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (some newer AMD variants support per die)? (C/a)")
|
local choice=$(ask "Display temperatures for all cores [C] or average per CPU [a] (some newer AMD variants support per die)? (C/a)" CONFIG_CPU_TEMP_MODE)
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
[cC]|"")
|
[cC]|"")
|
||||||
CPU_TEMP_TARGET="Core"
|
CPU_TEMP_TARGET="Core"
|
||||||
@ -186,7 +215,11 @@ function configure {
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid input, please choose C or a."
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
|
err "Invalid configuration value. Exiting."
|
||||||
|
else
|
||||||
|
warn "Invalid input, please choose C or a."
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -255,8 +288,7 @@ function configure {
|
|||||||
ENABLE_FAN_SPEED=true
|
ENABLE_FAN_SPEED=true
|
||||||
SENSORS_DETECTED=true
|
SENSORS_DETECTED=true
|
||||||
|
|
||||||
local choice
|
local choice=$(ask "Display fans reporting zero speed? (Y/n)" CONFIG_FAN_ZERO_SPEED_DISPLAY)
|
||||||
choice=$(ask "Display fans reporting zero speed? (Y/n)")
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
[yY]|"")
|
[yY]|"")
|
||||||
DISPLAY_ZERO_SPEED_FANS=true
|
DISPLAY_ZERO_SPEED_FANS=true
|
||||||
@ -267,8 +299,12 @@ function configure {
|
|||||||
info "Only active fans will be displayed."
|
info "Only active fans will be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid input. Defaulting to show zero-speed fans."
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
DISPLAY_ZERO_SPEED_FANS=true
|
err "Invalid configuration value. Exiting."
|
||||||
|
else
|
||||||
|
warn "Invalid input. Defaulting to show zero-speed fans."
|
||||||
|
DISPLAY_ZERO_SPEED_FANS=true
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
@ -281,7 +317,7 @@ function configure {
|
|||||||
#region temp unit setup
|
#region temp unit setup
|
||||||
msgb "\n=== Display temperature ==="
|
msgb "\n=== Display temperature ==="
|
||||||
if [ "$SENSORS_DETECTED" = true ]; then
|
if [ "$SENSORS_DETECTED" = true ]; then
|
||||||
local unit=$(ask "Display temperatures in Celsius [C] or Fahrenheit [f]? (C/f)")
|
local unit=$(ask "Display temperatures in Celsius [C] or Fahrenheit [f]? (C/f)" CONFIG_TEMP_UNIT)
|
||||||
case "$unit" in
|
case "$unit" in
|
||||||
[cC]|"")
|
[cC]|"")
|
||||||
TEMP_UNIT="C"
|
TEMP_UNIT="C"
|
||||||
@ -292,8 +328,12 @@ function configure {
|
|||||||
info "Using Fahrenheit."
|
info "Using Fahrenheit."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid selection. Defaulting to Celsius."
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
TEMP_UNIT="C"
|
err "Invalid configuration value. Exiting."
|
||||||
|
else
|
||||||
|
warn "Invalid selection. Defaulting to Celsius."
|
||||||
|
TEMP_UNIT="C"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@ -301,15 +341,17 @@ function configure {
|
|||||||
|
|
||||||
#### UPS ####
|
#### UPS ####
|
||||||
#region ups setup
|
#region ups setup
|
||||||
local choiceUPS=$(ask "Enable UPS information? (y/N)")
|
msgb "\n=== UPS setup ==="
|
||||||
case "$choiceUPS" in
|
local choice=$(ask "Enable UPS information? (y/N)" CONFIG_UPS_SHOW_INFO)
|
||||||
|
case "$choice" in
|
||||||
[yY])
|
[yY])
|
||||||
|
local upsConnection=
|
||||||
if [ "$DEBUG_REMOTE" = true ]; then
|
if [ "$DEBUG_REMOTE" = true ]; then
|
||||||
upsOutput=$(cat "$DEBUG_UPS_FILE")
|
upsOutput=$(cat "$DEBUG_UPS_FILE")
|
||||||
info "Remote debugging: UPS readings from $DEBUG_UPS_FILE"
|
info "Remote debugging: UPS readings from $DEBUG_UPS_FILE"
|
||||||
upsConnection="DEBUG_UPS"
|
upsConnection="DEBUG_UPS"
|
||||||
else
|
else
|
||||||
upsConnection=$(ask "Enter UPS connection (e.g., upsname[@hostname[:port]])")
|
upsConnection=$(ask "Enter UPS connection (e.g., upsname[@hostname[:port]])" CONFIG_UPS_CONNECTION)
|
||||||
if ! command -v upsc &>/dev/null; then
|
if ! command -v upsc &>/dev/null; then
|
||||||
err "The 'upsc' command is not available. Install 'nut-client'."
|
err "The 'upsc' command is not available. Install 'nut-client'."
|
||||||
fi
|
fi
|
||||||
@ -330,8 +372,12 @@ function configure {
|
|||||||
info "UPS information will not be displayed."
|
info "UPS information will not be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid selection. UPS info will not be displayed."
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
ENABLE_UPS=false
|
err "Invalid configuration value. Exiting."
|
||||||
|
else
|
||||||
|
warn "Invalid selection. UPS info will not be displayed."
|
||||||
|
ENABLE_UPS=false
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
#endregion ups setup
|
#endregion ups setup
|
||||||
@ -343,7 +389,7 @@ function configure {
|
|||||||
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 choiceSysInfo=$(ask "Enable system information? (1/2/n)")
|
local choiceSysInfo=$(ask "Enable system information? (1/2/n)" CONFIG_SYSINFO_DISPLAY_MODE)
|
||||||
case "$choiceSysInfo" in
|
case "$choiceSysInfo" in
|
||||||
[1]|"")
|
[1]|"")
|
||||||
ENABLE_SYSTEM_INFO=true
|
ENABLE_SYSTEM_INFO=true
|
||||||
@ -360,9 +406,13 @@ function configure {
|
|||||||
info "System information will NOT be displayed."
|
info "System information will NOT be displayed."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "Invalid selection. Defaulting to system information."
|
if [[ $UNATTENDED_MODE == true ]]; then
|
||||||
ENABLE_SYSTEM_INFO=true
|
err "Invalid configuration value. Exiting."
|
||||||
SYSTEM_INFO_TYPE=1
|
else
|
||||||
|
warn "Invalid selection. Defaulting to system information."
|
||||||
|
ENABLE_SYSTEM_INFO=true
|
||||||
|
SYSTEM_INFO_TYPE=1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
#endregion system info setup
|
#endregion system info setup
|
||||||
@ -431,7 +481,7 @@ function install_mod {
|
|||||||
|
|
||||||
restart_proxy
|
restart_proxy
|
||||||
info "Installation completed."
|
info "Installation completed."
|
||||||
ask "Clear the browser cache to ensure all changes are visualized. (any key to continue)"
|
show_clear_browser_cache_msg
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sanitize sensors output to handle common lm-sensors parsing issues
|
# Sanitize sensors output to handle common lm-sensors parsing issues
|
||||||
@ -1601,7 +1651,7 @@ function uninstall_mod {
|
|||||||
restart_proxy
|
restart_proxy
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ask "Clear the browser cache to ensure all changes are visualized. (any key to continue)"
|
show_clear_browser_cache_msg
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to check if the modification is installed
|
# Function to check if the modification is installed
|
||||||
@ -1727,12 +1777,14 @@ while [[ $# -gt 0 ]]; do
|
|||||||
install)
|
install)
|
||||||
executed=$(($executed + 1))
|
executed=$(($executed + 1))
|
||||||
msgb "\nInstalling the Proxmox VE sensors display mod..."
|
msgb "\nInstalling the Proxmox VE sensors display mod..."
|
||||||
|
load_settings
|
||||||
install_packages
|
install_packages
|
||||||
install_mod
|
install_mod
|
||||||
;;
|
;;
|
||||||
uninstall)
|
uninstall)
|
||||||
executed=$(($executed + 1))
|
executed=$(($executed + 1))
|
||||||
msgb "\nUninstalling the Proxmox VE sensors display mod..."
|
msgb "\nUninstalling the Proxmox VE sensors display mod..."
|
||||||
|
load_settings
|
||||||
uninstall_mod
|
uninstall_mod
|
||||||
;;
|
;;
|
||||||
save-sensors-data)
|
save-sensors-data)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user