add config comparison and save config on uninstall
This commit is contained in:
parent
5ffbaf7b07
commit
add8e38c47
45
debian/pve-mod.postinst
vendored
45
debian/pve-mod.postinst
vendored
@ -2,6 +2,48 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
NODES_PM="/usr/share/perl5/PVE/API2/Nodes.pm"
|
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
|
case "$1" in
|
||||||
configure)
|
configure)
|
||||||
@ -20,6 +62,9 @@ case "$1" in
|
|||||||
echo "pve-mod installed successfully."
|
echo "pve-mod installed successfully."
|
||||||
echo "Run 'pve-mod-configure' to enable and configure modules."
|
echo "Run 'pve-mod-configure' to enable and configure modules."
|
||||||
echo ""
|
echo ""
|
||||||
|
else
|
||||||
|
# Upgrading from a previous version — warn about any new config keys.
|
||||||
|
_check_new_config_keys
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
21
debian/pve-mod.prerm
vendored
21
debian/pve-mod.prerm
vendored
@ -1,12 +1,27 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
case "$1" in
|
_revert_patches() {
|
||||||
remove|deconfigure)
|
|
||||||
# Revert PVE file patches before files are removed.
|
|
||||||
if [ -x /usr/lib/pve-mod/revert-patches.sh ]; then
|
if [ -x /usr/lib/pve-mod/revert-patches.sh ]; then
|
||||||
/usr/lib/pve-mod/revert-patches.sh 2>&1 || true
|
/usr/lib/pve-mod/revert-patches.sh 2>&1 || true
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
remove|deconfigure)
|
||||||
|
# 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
|
||||||
;;
|
;;
|
||||||
|
|
||||||
upgrade)
|
upgrade)
|
||||||
|
|||||||
5
debian/rules
vendored
5
debian/rules
vendored
@ -39,6 +39,9 @@ override_dh_install:
|
|||||||
# Configure tool
|
# Configure tool
|
||||||
install -Dm755 src/Scripts/pve-mod-configure \
|
install -Dm755 src/Scripts/pve-mod-configure \
|
||||||
debian/pve-mod/usr/sbin/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 \
|
install -Dm644 src/pve-mod.conf \
|
||||||
debian/pve-mod/etc/pve-mod/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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user