PVE-mods/debian/pve-mod.postinst

94 lines
3.4 KiB
Bash

#!/bin/bash
set -e
NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm"
DEFAULT_CONF="/usr/share/pve-mod/pve-mod.conf.default"
USER_CONF="/etc/pve-mod/pve-mod.conf"
# Extracts "section.key" pairs from an INI file, one per line.
_extract_conf_keys() {
local file="$1" section="" line key
while IFS= read -r line; do
case "$line" in
'#'*|'') continue ;;
'['*']') section="${line#[}"; section="${section%]}"; continue ;;
*'='*) key="${line%%=*}"; echo "${section}.${key}" ;;
esac
done < "$file"
}
# Warns about keys present in the default config but missing from the user's config.
_check_new_config_keys() {
[ -f "$DEFAULT_CONF" ] || return 0
[ -f "$USER_CONF" ] || return 0
local new_keys="" section="" key default_val
while IFS= read -r line; do
case "$line" in
'#'*|'') continue ;;
'['*']') section="${line#[}"; section="${section%]}"; continue ;;
*'='*)
key="${line%%=*}"
if ! _extract_conf_keys "$USER_CONF" | grep -qF "${section}.${key}"; then
new_keys="${new_keys} [${section}] ${line}\n"
fi
;;
esac
done < "$DEFAULT_CONF"
if [ -n "$new_keys" ]; then
echo ""
echo "pve-mod: New configuration options are available since your last install:"
printf "%b" "$new_keys"
echo "pve-mod: Run 'pve-mod-configure' to configure them, or add them manually to $USER_CONF"
echo ""
fi
}
case "$1" in
configure)
# 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 "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."
echo "Run 'pve-mod-configure' to enable and configure modules."
echo ""
else
# Upgrading from a previous version — warn about any new config keys.
_check_new_config_keys
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
#DEBHELPER#
exit 0