Initial release
This commit is contained in:
commit
39397c1a05
17 files changed
+411
No files matched your search
+121
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG="/etc/pve-gui-sensors-auto/config"
|
||||
STATE_DIR="/var/lib/pve-gui-sensors-auto"
|
||||
WORK_DIR="$STATE_DIR/upstream"
|
||||
LOG="/var/log/pve-gui-sensors-auto.log"
|
||||
PVE_JS="/usr/share/pve-manager/js/pvemanagerlib.js"
|
||||
NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm"
|
||||
QUIET=0
|
||||
FORCE=0
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
Usage: pve-gui-sensors-refresh [--quiet] [--force] [--status]
|
||||
--quiet Log to file without normal terminal output
|
||||
--force Re-run installer after confirming files are unpatched
|
||||
--status Report patch state and exit
|
||||
USAGE
|
||||
}
|
||||
|
||||
MODE="refresh"
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--quiet) QUIET=1 ;;
|
||||
--force) FORCE=1 ;;
|
||||
--status) MODE="status" ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "Unknown option: $1" >&2; usage >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
mkdir -p "$STATE_DIR" "$WORK_DIR"
|
||||
touch "$LOG"
|
||||
chmod 700 "$STATE_DIR"
|
||||
|
||||
log() {
|
||||
printf '%s\n' "$*" >>"$LOG"
|
||||
if [[ "$QUIET" -eq 0 ]]; then printf '%s\n' "$*"; fi
|
||||
}
|
||||
|
||||
if [[ ! -r "$CONFIG" ]]; then
|
||||
log "ERROR: missing configuration: $CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
# shellcheck disable=SC1090
|
||||
source "$CONFIG"
|
||||
|
||||
for required in CPU_DISPLAY SHOW_ZERO_FANS TEMPERATURE_UNIT ENABLE_UPS SYSTEM_INFORMATION INSTALLER_URL; do
|
||||
if [[ -z "${!required:-}" ]]; then
|
||||
log "ERROR: missing setting $required in $CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ! -f "$PVE_JS" || ! -f "$NODES_PM" ]]; then
|
||||
log "INFO: Proxmox GUI files are not installed; nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
js=0; perl=0
|
||||
grep -q 'sensorsOutput' "$PVE_JS" && js=1 || true
|
||||
grep -q 'sensorsOutput' "$NODES_PM" && perl=1 || true
|
||||
|
||||
if [[ "$MODE" == "status" ]]; then
|
||||
case "$js:$perl" in
|
||||
1:1) echo "installed" ;;
|
||||
0:0) echo "not-installed" ;;
|
||||
*) echo "partial" ;;
|
||||
esac
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log ""
|
||||
log "=================================================="
|
||||
log "PVE GUI sensors check: $(date -Is)"
|
||||
log "=================================================="
|
||||
|
||||
if [[ "$js" -eq 1 && "$perl" -eq 1 && "$FORCE" -eq 0 ]]; then
|
||||
log "Sensor modification is already fully installed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$js" -ne "$perl" ]]; then
|
||||
log "ERROR: partial sensor modification detected."
|
||||
log "Refusing to patch automatically; repair or restore the Proxmox files first."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ "$FORCE" -eq 1 && "$js" -eq 1 ]]; then
|
||||
log "ERROR: --force cannot overwrite an installed modification."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
INSTALLER="$WORK_DIR/pve-mod-gui-sensors.sh"
|
||||
TMP="$INSTALLER.tmp"
|
||||
log "Downloading official Meliox installer..."
|
||||
curl --fail --silent --show-error --location "$INSTALLER_URL" -o "$TMP"
|
||||
|
||||
if ! grep -q 'pve-mod-gui-sensors' "$TMP" && ! grep -q 'sensors display mod' "$TMP"; then
|
||||
log "ERROR: downloaded file does not look like the expected installer."
|
||||
rm -f "$TMP"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
mv "$TMP" "$INSTALLER"
|
||||
chmod 700 "$INSTALLER"
|
||||
|
||||
# Remove only the installer's old backup directory after confirming both target
|
||||
# files are unpatched. This lets each Proxmox update create fresh compatible backups.
|
||||
rm -rf "$WORK_DIR/backup" "$WORK_DIR/PVE-MODS"
|
||||
|
||||
log "Applying saved choices: average CPU, zero-RPM fans shown, Celsius, UPS off, system information 1."
|
||||
cd "$WORK_DIR"
|
||||
printf '%s\n%s\n%s\n%s\n%s\n\n' \
|
||||
"$CPU_DISPLAY" "$SHOW_ZERO_FANS" "$TEMPERATURE_UNIT" "$ENABLE_UPS" "$SYSTEM_INFORMATION" \
|
||||
| bash "$INSTALLER" install
|
||||
|
||||
systemctl restart pveproxy
|
||||
log "Sensor modification successfully installed."
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
WORK_DIR="/var/lib/pve-gui-sensors-auto/upstream"
|
||||
INSTALLER="$WORK_DIR/pve-mod-gui-sensors.sh"
|
||||
if [[ ! -x "$INSTALLER" ]]; then
|
||||
echo "No saved upstream installer exists. Run a refresh first." >&2
|
||||
exit 1
|
||||
fi
|
||||
cd "$WORK_DIR"
|
||||
bash "$INSTALLER" uninstall
|
||||
systemctl restart pveproxy
|
||||
Reference in new issue
Block a user