[pmg-devel] [PATCH pmg-api v2] Use ucf to handle template overrides.

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Apr 14 14:36:24 CEST 2020


On 4/8/20 7:40 PM, Stoiko Ivanov wrote:
> 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 at proxmox.com>
> ---
> v1 -> v2
> * incorporated Fabian's feedback (much thanks! it looks quite a bit tidier now)
> * tested with putting an unrelated file in /etc/pmg/templates

applied, but squashed in a small followup (see below), which else would
had "uglify" the git log :)

> 
>  debian/postinst | 24 +++++++++++++++++++++++-
>  debian/postrm   | 21 +++++++++++++++++++++
>  src/Makefile    |  1 +
>  3 files changed, 45 insertions(+), 1 deletion(-)
>  create mode 100644 debian/postrm
> 
> diff --git a/debian/postinst b/debian/postinst
> index 5e4db3a..d3b17cf 100644
> --- a/debian/postinst
> +++ b/debian/postinst
> @@ -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
> index 0000000..9d95ae7
> --- /dev/null
> +++ b/debian/postrm
> @@ -0,0 +1,21 @@
> +#!/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#
> +
> +
> 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

Above line is not necessary anymore, I dropped it.

>  
>  .PHONY: check
>  check:
> 




More information about the pmg-devel mailing list