From a7cef62574963638f4c38623703dcd3942930c38 Mon Sep 17 00:00:00 2001 From: Meliox Date: Sun, 7 Jun 2026 13:14:09 +0200 Subject: [PATCH] rework hook implementation to work on dpkg triggered --- .github/workflows/release.yml | 2 +- .github/workflows/version-bump.yml | 4 +++ debian/pve-mod.postinst | 34 ++++++++++++++------- debian/pve-mod.triggers | 1 + debian/rules | 2 -- src/Scripts/pve-mod-configure | 48 ++++++++---------------------- src/pve-mod-apt-hook.sh | 8 ----- src/pve-mod.conf | 2 +- 8 files changed, 43 insertions(+), 58 deletions(-) create mode 100644 debian/pve-mod.triggers delete mode 100644 src/pve-mod-apt-hook.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 515b1b3..652865b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -80,4 +80,4 @@ jobs: --title "pve-mod $TAG" \ --notes "$NOTES" \ "$DEB" \ - "src/Scripts/install.sh" + "src/install.sh" diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index ec6e0be..c71cab5 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -5,6 +5,10 @@ name: Version Bump # and opens (or updates) a "Release vX.Y.Z" PR to main. # The changelog commit touches only debian/changelog (not src/), # so it does not re-trigger this workflow. +# +# NOTE: GITHUB_TOKEN cannot push to forks, so this workflow only works for +# branches on the upstream repo (Meliox/PVE-mods). External contributors +# opening PRs from forks will not get an automatic version bump. on: push: diff --git a/debian/pve-mod.postinst b/debian/pve-mod.postinst index d238a32..8ca2ddf 100644 --- a/debian/pve-mod.postinst +++ b/debian/pve-mod.postinst @@ -5,21 +5,16 @@ NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm" case "$1" in configure) - # Check for legacy bash-script install markers and warn the user. + # If a legacy bash-script installation is present, revert it cleanly first. if grep -qF '$res->{sensorsJSONOutput}' "$NODES_PM" 2>/dev/null || \ grep -qF '$res->{systemInfo}' "$NODES_PM" 2>/dev/null; then - echo "" - echo "WARNING: A legacy pve-mod bash-script installation was detected in Nodes.pm." - echo "The old installation should be removed first to avoid conflicts:" - echo " bash /path/to/pve-mod-gui-sensors.sh uninstall" - echo "" - echo "Skipping patch application. Run 'pve-mod-configure' after removing the old install." - echo "" - else - # Apply patches for any enabled modules (idempotent, safe on upgrades). - /usr/lib/pve-mod/apply-patches.sh 2>&1 || true + echo "pve-mod: Legacy bash-script installation detected — reverting before upgrade." + /usr/lib/pve-mod/revert-patches.sh || true fi + # Apply patches for any enabled modules. Fails loudly on error. + /usr/lib/pve-mod/apply-patches.sh + if [ -z "$2" ]; then echo "" echo "pve-mod installed successfully." @@ -28,6 +23,23 @@ case "$1" in fi ;; + triggered) + # Fired by dpkg when pve-manager is upgraded. Only re-apply patches + # if the user has opted in via 'pve-mod-configure'. + TRIGGER_ENABLED=$(awk -F= '/^\[pve_trigger\]/{s=1} s && /^enabled=/{print $2; exit}' \ + /etc/pve-mod/pve-mod.conf 2>/dev/null || echo 0) + if [ "${TRIGGER_ENABLED}" = "1" ]; then + echo "pve-mod: pve-manager upgrade detected — re-applying patches." + if ! /usr/lib/pve-mod/apply-patches.sh; then + echo "pve-mod: WARNING: Failed to re-apply patches. Run 'pve-mod-configure' to fix." >&2 + fi + else + echo "pve-mod: WARNING: pve-manager was upgraded but auto re-patching is disabled." >&2 + echo "pve-mod: The Proxmox UI modifications may no longer be active." >&2 + echo "pve-mod: Run 'pve-mod-configure' to re-apply patches." >&2 + fi + ;; + abort-upgrade|abort-remove|abort-deconfigure) ;; esac diff --git a/debian/pve-mod.triggers b/debian/pve-mod.triggers new file mode 100644 index 0000000..036d144 --- /dev/null +++ b/debian/pve-mod.triggers @@ -0,0 +1 @@ +interest pve-manager diff --git a/debian/rules b/debian/rules index f4ed5d8..7f088f4 100644 --- a/debian/rules +++ b/debian/rules @@ -36,8 +36,6 @@ override_dh_install: debian/pve-mod/usr/lib/pve-mod/apply-patches.sh install -Dm755 src/PVENodeInfo/revert-patches.sh \ debian/pve-mod/usr/lib/pve-mod/revert-patches.sh - install -Dm755 src/pve-mod-apt-hook.sh \ - debian/pve-mod/usr/lib/pve-mod/apt-hook.sh # Configure tool install -Dm755 src/Scripts/pve-mod-configure \ debian/pve-mod/usr/sbin/pve-mod-configure diff --git a/src/Scripts/pve-mod-configure b/src/Scripts/pve-mod-configure index 9ccbfbd..296555f 100644 --- a/src/Scripts/pve-mod-configure +++ b/src/Scripts/pve-mod-configure @@ -7,7 +7,6 @@ set -euo pipefail CONF_FILE="/etc/pve-mod/pve-mod.conf" -APT_HOOK_FILE="/etc/apt/apt.conf.d/99-pve-mod" APPLY_PATCHES="/usr/lib/pve-mod/apply-patches.sh" NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm" @@ -317,8 +316,8 @@ device_name=${UPS_DEVICE_NAME} enabled=${ENABLE_SYSTEM_INFO} type=${SYSTEM_INFO_TYPE} -[apt_hook] -enabled=${APT_HOOK_ENABLED} +[pve_trigger] +enabled=${PVE_TRIGGER_ENABLED} [service] mode=embedded @@ -327,35 +326,6 @@ EOF } #endregion write config -#region apt hook -configure_apt_hook() { - msgb "\n=== Automatic Re-patching (apt hook) ===" - echo "After a Proxmox upgrade, patched files (Nodes.pm, pvemanagerlib.js) may be" - echo "overwritten. An apt hook can re-apply patches automatically after every apt run." - echo "Enabling may pose the risk should something go wrong during the re-patching process (e.g. Proxmox changes)." - local choice - choice=$(ask "Enable automatic re-patching after apt/dpkg operations? (y/N)") - case "$choice" in - [yY]) - APT_HOOK_ENABLED=1 - cat > "$APT_HOOK_FILE" <<'HOOKEOF' -DPkg::Post-Invoke { "/usr/lib/pve-mod/apt-hook.sh || true"; }; -HOOKEOF - info "Apt hook installed: $APT_HOOK_FILE" - ;; - *) - APT_HOOK_ENABLED=0 - if [[ -f "$APT_HOOK_FILE" ]]; then - rm -f "$APT_HOOK_FILE" - info "Apt hook removed." - else - info "Apt hook not enabled." - fi - ;; - esac -} -#endregion apt hook - main() { # ── Root check ──────────────────────────────────────────────────────────── [[ $EUID -eq 0 ]] || err "This script must be run as root." @@ -391,7 +361,7 @@ main() { ENABLE_GPU_HISTORY=0 ENABLE_UPS=0; UPS_DEVICE_NAME="ups@localhost" ENABLE_SYSTEM_INFO=0; SYSTEM_INFO_TYPE=1 - APT_HOOK_ENABLED=0 + PVE_TRIGGER_ENABLED=0 # ── Module selection ────────────────────────────────────────────────────── msgb "\n=== pve-mod Module Selection ===" @@ -421,8 +391,16 @@ main() { info "Subscription nag screen removal will be applied." fi - # ── Apt hook ────────────────────────────────────────────────────────────── - configure_apt_hook + # ── Re-patch on PVE upgrade ─────────────────────────────────────────────── + msgb "\n=== Auto Re-patching on PVE Upgrade ===" + echo "pve-mod registers a dpkg trigger on pve-manager. When pve-manager is" + echo "upgraded, the trigger fires and can automatically re-apply patches." + local triggerChoice + triggerChoice=$(ask "Re-apply patches automatically when pve-manager upgrades? (y/N)") + case "$triggerChoice" in + [yY]) PVE_TRIGGER_ENABLED=1; info "Auto re-patching enabled." ;; + *) PVE_TRIGGER_ENABLED=0; info "Auto re-patching disabled. Run 'pve-mod-configure' after a PVE upgrade." ;; + esac # ── Write config and apply ──────────────────────────────────────────────── write_config diff --git a/src/pve-mod-apt-hook.sh b/src/pve-mod-apt-hook.sh deleted file mode 100644 index b47cca7..0000000 --- a/src/pve-mod-apt-hook.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# /usr/lib/pve-mod/apt-hook.sh -# -# Installed to /etc/apt/apt.conf.d/99-pve-mod by pve-mod-configure when the -# user enables the apt hook. Re-applies PVE file patches after any dpkg run -# (e.g. after a pve-manager upgrade overwrites patched files). - -/usr/lib/pve-mod/apply-patches.sh || true diff --git a/src/pve-mod.conf b/src/pve-mod.conf index 96a8c0a..0e2a81d 100644 --- a/src/pve-mod.conf +++ b/src/pve-mod.conf @@ -31,7 +31,7 @@ device_name=ups@localhost enabled=0 type=1 -[apt_hook] +[pve_trigger] enabled=0 [service]