[pmg-devel] [PATCH pmg-api 1/2] Use ucf to handle template overrides.
Stoiko Ivanov
s.ivanov at proxmox.com
Wed Mar 25 19:42:54 CET 2020
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 changes in the maintainer scripts are based on the generated ones from
dh_ucf (1), with the replacement of `which ucf` by the (more portable)
`command -v ucf` in the postrm script.
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
debian/postinst | 20 +++++++++++++++++++-
debian/postrm | 26 ++++++++++++++++++++++++++
src/Makefile | 1 +
3 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 debian/postrm
diff --git a/debian/postinst b/debian/postinst
index 5e4db3a..9118dff 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -3,6 +3,17 @@
set -e
+ucf_register_templates() {
+ PMG_TEMPLATES=""
+
+ for template in ${PMG_TEMPLATES}; do
+ if [ -e "/etc/pmg/templates/${template}" ]; then
+ ucf "/var/lib/pmg/templates/${template}" "/etc/pmg/templates/${template}"
+ ucfr pmg-api "/etc/pmg/templates/${template}"
+ fi
+ done
+}
+
case "$1" in
triggered)
@@ -24,6 +35,8 @@ case "$1" in
pmgconfig init
pmgdb init
+
+ ucf_register_templates
pmgconfig sync --restart
if [ -z "$2" ]; then
@@ -36,13 +49,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
index 0000000..1c14ce7
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" = "purge" ]; then
+ PMG_TEMPLATES=""
+
+ for template in ${PMG_TEMPLATES}; do
+ for ext in .ucf-new .ucf-old .ucf-dist ""; do
+ rm -f "/etc/pmg/templates/${template}${ext}"
+ done
+ if command -v ucf >/dev/null 2>&1; then
+ ucf --purge "/etc/pmg/templates/${template}"
+ fi
+ if command -v ucfr >/dev/null 2>&1; then
+ ucfr --purge pmg-api "/etc/pmg/templates/${template}"
+ fi
+ done
+fi
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+
diff --git a/src/Makefile b/src/Makefile
index b5e4c9f..3617f05 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -192,6 +192,7 @@ install: ${SOURCES} $(addsuffix .service-bash-completion, ${SERVICES}) $(addsuff
install -d -m 0755 ${DESTDIR}/lib/systemd/system
for i in ${TIMER_UNITS}; do install -m 0644 $$i ${DESTDIR}/lib/systemd/system/; done
install -D -m 0644 pmg-initramfs.conf ${DESTDIR}/etc/initramfs-tools/conf.d/pmg-initramfs.conf
+ sed -ri 's/^ PMG_TEMPLATES=.*$$/PMG_TEMPLATES="${TEMPLATES}"/' debian/postinst debian/postrm
.PHONY: check
check:
--
2.20.1
More information about the pmg-devel
mailing list