rework hook implementation to work on dpkg triggered

This commit is contained in:
Meliox 2026-06-07 13:14:09 +02:00
parent d9ff050676
commit a7cef62574
8 changed files with 43 additions and 58 deletions

View File

@ -80,4 +80,4 @@ jobs:
--title "pve-mod $TAG" \
--notes "$NOTES" \
"$DEB" \
"src/Scripts/install.sh"
"src/install.sh"

View File

@ -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:

View File

@ -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

1
debian/pve-mod.triggers vendored Normal file
View File

@ -0,0 +1 @@
interest pve-manager

2
debian/rules vendored
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -31,7 +31,7 @@ device_name=ups@localhost
enabled=0
type=1
[apt_hook]
[pve_trigger]
enabled=0
[service]