From d13d02ab36a199643eb9cdce2feccd40b42d01ac Mon Sep 17 00:00:00 2001 From: Meliox <5264368+Meliox@users.noreply.github.com> Date: Sun, 16 Jun 2024 00:02:54 +0200 Subject: [PATCH] save-sensors-data argument (#52) --- pve-mod-gui-sensors.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index 856c8c0..21d504f 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -26,6 +26,10 @@ BACKUP_DIR="$SCRIPT_CWD/backup" pvemanagerlibjs="/usr/share/pve-manager/js/pvemanagerlib.js" nodespm="/usr/share/perl5/PVE/API2/Nodes.pm" +# Debug location +DEBUG_SAVE_PATH="$SCRIPT_CWD" +DEBUG_SAVE_FILENAME="sensorsdata.json" + ############################################### # Helper functions @@ -54,7 +58,7 @@ function err { # Function to display usage information function usage { - msgb "\nUsage:\n$0 [install | uninstall]\n" + msgb "\nUsage:\n$0 [install | uninstall | save-sensors-data]\n" exit 1 } @@ -768,6 +772,35 @@ function restart_proxy { systemctl restart pveproxy } +function save_sensors_data { + # Check if DEBUG_SAVE_PATH exists and is writable + if [[ ! -d "$DEBUG_SAVE_PATH" || ! -w "$DEBUG_SAVE_PATH" ]]; then + err "Directory $DEBUG_SAVE_PATH does not exist or is not writable. No file could be saved" + return + fi + + # Check if command exists + if (command -v sensors &>/dev/null); then + # Save sensors output + local filepath="${DEBUG_SAVE_PATH}/${DEBUG_SAVE_FILENAME}" + echo "Sensors data will be saved in $filepath" + + # Prompt user for confirmation + read -p "Do you wish to continue? (y/n): " choice + case "$choice" in + y|Y ) + sensors -j > "$filepath" + msgb "Sensors data saved in $filepath" + ;; + * ) + echo "Operation cancelled by user." + ;; + esac + else + err "Sensors is not installed. No file could be saved" + fi +} + # Process the arguments using a while loop and a case statement executed=0 while [[ $# -gt 0 ]]; do @@ -785,6 +818,12 @@ while [[ $# -gt 0 ]]; do uninstall_mod echo # add a new line ;; + save-sensors-data) + executed=$(($executed + 1)) + msgb "\nSaving current sensor readings in a file for debugging..." + save_sensors_data + echo # add a new line + ;; esac shift done