]> git.proxmox.com Git - pmg-api.git/commitdiff
Use ucf to handle template overrides
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 8 Apr 2020 17:40:51 +0000 (19:40 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 14 Apr 2020 07:35:07 +0000 (09:35 +0200)
ucf(1) is a utility to track changes in config files which are not shipped in
the debian package (but e.g. get generated through the postinst script)

While the template overriding mechanism of PMG does not directly write those
config files - users who override a config-file currently need to manually
compare the templates shipped in '/var/lib/pmg/templates' on every upgrade.

By selectively registering the existing template overrides with ucf, users get
asked once upon the next upgrade regarding their changes, and then will
always get prompted when the shipped default template changes.

The alternative of unconditionally registering all templates with ucf, as done
by dh_ucf (1), would copy all templates to /etc/pmg/templates, which I deemed
less elegant.

The postrm script's check for the existance of 'ucf' only should be sufficient,
since the other ucf executables used ('ucfq' and 'ucfr' are all shipped with
the 'ucf' package)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
[ dropped some extra lines left over from v1 ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
debian/postinst
debian/postrm [new file with mode: 0644]

index 5e4db3a84315826a719ad6b3b0cff31728745cf1..d3b17cf770c7de3cfd3c902b6e37343c06a5e5ac 100644 (file)
@@ -3,6 +3,21 @@
 set -e
 
 
+ucf_register_templates() {
+    for template in /etc/pmg/templates/*; do
+       template_base=$(basename "${template}")
+       if echo "${template_base}" | grep -q '\.ucf-'; then
+               continue
+       fi
+       if [ -e "/var/lib/pmg/templates/${template_base}" ]; then
+           ucf "/var/lib/pmg/templates/${template_base}" "${template}"
+           ucfr pmg-api "${template}"
+       else
+           echo "template '${template}' not shipped by pmg-api."
+       fi
+    done
+}
+
 case "$1" in
     triggered)
 
@@ -24,6 +39,8 @@ case "$1" in
 
            pmgconfig init
            pmgdb init
+
+           ucf_register_templates
            pmgconfig sync --restart
 
            if [ -z "$2" ]; then
@@ -36,13 +53,18 @@ case "$1" in
            pmgdb update  >/dev/null 2>&1 &
 
            update-mime-database /usr/share/mime
+
        else
            # rewrite banner
            pmgbanner || true
        fi
     ;;
 
-    abort-upgrade|abort-remove|abort-deconfigure)
+    abort-upgrade)
+       ucf_register_templates
+    ;;
+
+    abort-remove|abort-deconfigure)
     ;;
 
     *)
diff --git a/debian/postrm b/debian/postrm
new file mode 100644 (file)
index 0000000..db7d80d
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" = "purge" ] && command -v ucf >/dev/null 2>&1; then
+
+       ucfq -w pmg-api | cut -d : -f 1 | while read -r cfile ; do
+               ucfr pmg-api --purge "$cfile"
+               ucf --purge "$cfile"
+               for ext in .ucf-new .ucf-old .ucf-dist ""; do
+                       rm -f "${cfile}${ext}"
+               done
+       done
+fi
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#