diff --git a/debian/pve-mod.postinst b/debian/pve-mod.postinst index 8ca2ddf..9eee8de 100644 --- a/debian/pve-mod.postinst +++ b/debian/pve-mod.postinst @@ -2,6 +2,48 @@ 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) @@ -20,6 +62,9 @@ case "$1" in 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 ;; diff --git a/debian/pve-mod.prerm b/debian/pve-mod.prerm index d241b23..ec0b213 100644 --- a/debian/pve-mod.prerm +++ b/debian/pve-mod.prerm @@ -1,11 +1,26 @@ #!/bin/bash set -e +_revert_patches() { + if [ -x /usr/lib/pve-mod/revert-patches.sh ]; then + /usr/lib/pve-mod/revert-patches.sh 2>&1 || true + fi +} + case "$1" in remove|deconfigure) - # Revert PVE file patches before files are removed. - if [ -x /usr/lib/pve-mod/revert-patches.sh ]; then - /usr/lib/pve-mod/revert-patches.sh 2>&1 || true + # 1. Revert patches before files are removed. + _revert_patches + + # 2. Ask whether to keep the config (only in interactive sessions). + if [ -t 0 ] && [ -f /etc/pve-mod/pve-mod.conf ]; then + printf '\npve-mod: Keep /etc/pve-mod/pve-mod.conf for re-use after reinstall? [Y/n] ' + read -r _keep + case "$_keep" in + [nN]*) rm -f /etc/pve-mod/pve-mod.conf + echo "pve-mod: Configuration removed." ;; + *) echo "pve-mod: Configuration kept at /etc/pve-mod/pve-mod.conf" ;; + esac fi ;; diff --git a/debian/rules b/debian/rules index 7f088f4..f816056 100644 --- a/debian/rules +++ b/debian/rules @@ -39,6 +39,9 @@ override_dh_install: # Configure tool install -Dm755 src/Scripts/pve-mod-configure \ debian/pve-mod/usr/sbin/pve-mod-configure - # Default config + # Default config (conffile for user edits) install -Dm644 src/pve-mod.conf \ debian/pve-mod/etc/pve-mod/pve-mod.conf + # Reference copy for upgrade key-diff (not a conffile — always updated) + install -Dm644 src/pve-mod.conf \ + debian/pve-mod/usr/share/pve-mod/pve-mod.conf.default