From 2f3fb9b5b63827e2294c4e62791b40b788927f0a Mon Sep 17 00:00:00 2001 From: rmm Date: Sun, 16 Jun 2024 12:58:51 +0200 Subject: [PATCH] Adjust & unify prompts --- pve-mod-gui-sensors.sh | 49 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index ba01218..3bc41f1 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -194,42 +194,41 @@ function configure { fi if [ $sensorsDetected = true ]; then - msg "\nSelect a unit for temperature readings..." - read -p "Type C for Celsius or F for Fahrenheit and press Enter: " TEMP_UNIT + echo + read -p "Do you wish to display temperature readings in degrees Celsius [C] or Fahrenheit [f]? (C/f): " TEMP_UNIT case "$TEMP_UNIT" in - [cC]) + [cC] | "") TEMP_UNIT="C" + info "Temperatures will be presented in degrees Celsius." ;; [fF]) TEMP_UNIT="F" - ;; - "") - info "No unit selected. Temperatures will be presented in degrees Celsius." - TEMP_UNIT="C" + info "Temperatures will be presented in degrees Fahrenheit." ;; *) - warn "Invalid unit selected. Temperatures will be presented in degrees Celsius." + warn "Invalid unit selected. Temperatures will be displayed in degrees Celsius." TEMP_UNIT="C" ;; esac fi - echo "" - read -p "Do you wish to enable System Information. [Yn]: " ENABLE_SYS_INFO + + echo + read -p "Do you wish to enable system information? (Y/n): " ENABLE_SYS_INFO case "$ENABLE_SYS_INFO" in - [yY]|"") + [yY] | "") enableSystemInfo=true - msg "Displaying System Information... yes" + info "System information will be displayed..." ;; [nN]) enableSystemInfo=false - msg "Displaying System Information... no" + info "System information will NOT be displayed..." ;; *) warn "Invalid selection. System information will be displayed." enableSystemInfo=true ;; - esac + esac echo # add a new line } @@ -253,7 +252,7 @@ function install_mod { # Create backup of original file cp "$pvemanagerlibjs" "$BACKUP_DIR/pvemanagerlib.js.$timestamp" - msg "Backup of \"$pvemanagerlibjs\" saved to \"$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 @@ -266,7 +265,7 @@ function install_mod { sensorsCmd="cat \"$JSON_FILE\"" else # 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") sensorsCmd="sensors -j" fi 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" @@ -276,7 +275,7 @@ function install_mod { 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\"." + msg "System information output added to \"$nodespm\"." fi # Add new item to the items array in PVE.node.StatusView @@ -800,17 +799,17 @@ function save_sensors_data { 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" - + msg "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" + case "$choice" in + y | Y) + sensors -j >"$filepath" msgb "Sensors data saved in $filepath" ;; - * ) - echo "Operation cancelled by user." + *) + warn "Operation cancelled by user." ;; esac else @@ -840,7 +839,7 @@ while [[ $# -gt 0 ]]; do msgb "\nSaving current sensor readings in a file for debugging..." save_sensors_data echo # add a new line - ;; + ;; esac shift done