#1002038 noninteractive upgrade with UCF_FORCE_CONFFNEW=1 fail with ucf conflict

Package:
grub-pc
Source:
grub2
Description:
GRand Unified Bootloader, version 2 (PC/BIOS version)
Submitter:
lvlolotov
Date:
2021-12-20 19:51:03 UTC
Severity:
normal
#1002038#5
Date:
2021-12-20 19:49:32 UTC
From:
To:
noninteractive upgrade with UCF_FORCE_CONFFNEW=1 fail with ucf conflict.
Error: Only one of force_conffold and force_conffnew should be set

Reproduce:
   - Modify sources.list for a new release.

   - Set ucf options
   export DEBIAN_FRONTEND=noninteractive
   unset UCF_FORCE_CONFFOLD
   export UCF_FORCE_CONFFNEW=1

   - noninteractive upgrade
   apt-get dist-upgrade
   ...
   Paramétrage de grub-pc (2.04-20) ...
   Error: Only one of force_conffold and force_conffnew should be set
   dpkg: erreur de traitement du paquet grub-pc (--configure) :
   installed grub-pc package post-installation script subprocess
returned error exit status 1
   ...

 From ucf source :
   if [ "X$force_conffold" != "X" -a "X$force_conffnew" != "X" ]; then
     echo >&2 "Error: Only one of force_conffold and force_conffnew should";
     echo >&2 "       be set";
     exit 1;
   fi

 From /etc/ucf.conf :
   # Please note that only one of conf_force_conffold and
   # conf_force_conffnew should be set.

 From grub-pc postinst script :
     # If the template configuration file hasn't changed, then no
conflict is
     # possible.  ucf can't figure this out for itself since we apply
     # debconf-based customisations on top of the template configuration
     # file.
     if [ -e /var/lib/grub/ucf/grub.previous ] && \
        cmp -s /usr/share/grub/default/grub
/var/lib/grub/ucf/grub.previous && \
        [ -e /etc/default/grub ]; then
       ucf_env=UCF_FORCE_CONFFOLD=1
     else
       ucf_env=
     fi

     env $ucf_env ucf --three-way --debconf-ok
--sum-file=/usr/share/grub/default/grub.md5sum "$tmp_default_grub" 
/etc/default/grub
     cp -aZ /usr/share/grub/default/grub /var/lib/grub/ucf/grub.previous

I suggest that grub postinst script should honor ucf options specified
by commandline or in /etc/ucf.conf file.
If UCF_FORCE_CONFFNEW is true or conf_force_conffnew=YES is set in
/etc/ucf.conf then we should not try to define UCF_FORCE_CONFFOLD in
postinst.
grub-efi packages have the same behaviour :
   grub-efi-amd64
   grub-efi-amd64-signed
   shim-signed

I'm using Debian GNU/Linux 11 (bullseye) Kernel 5.10.70-1 (2021-09-30)
x86_64 GNU/Linux.