I have also hit this bug while backporting openssh from unstable to bullseye
(ironically so I can avoid the need to use dpkg-divert)

I've redone the patch proposed above so that it applies against the
unpacked source package:

apt-mirror@aptmirror17:/mnt/mirror/local-debs (master)$ cat main/u/ucf/ucf.patch
diff -urN ucf-3.0043.orig/ucf ucf-3.0043/ucf
--- ucf-3.0043.orig/ucf 2020-06-16 05:37:53.000000000 +0000
+++ ucf-3.0043/ucf      2020-06-16 05:37:53.000000000 +0000
@@ -439,16 +439,10 @@
 fi

 # Follow dpkg-divert as though we are installed as part of $opt_package
-divert_line=$(dpkg-divert --list "$dest_file")
+divert_line=$(dpkg-divert --listpackage "$dest_file")
 if [ -n "$divert_line" ]; then
-   if [ echo "$divert_line" | grep "^local" ]; then
-       # local diversion; pick something not in the package namespace
-       divert_package="LOCAL"
-   else
-       # extract the name of the diverted package.
-       # The fact that this requires output parsing is bug #485012
-       divert_package=$(dpkg-divert --listpackage "$dest_file")
-   fi
+   # name of the package or 'LOCAL' for a local diversion
+   divert_package="$divert_line"

    if [ "$divert_package" != "$opt_package" ]; then
        dest_file=$(dpkg-divert --truename "$dest_file")
diff -urN ucf-3.0043.orig/ucfr ucf-3.0043/ucfr
--- ucf-3.0043.orig/ucfr        2020-06-16 05:37:53.000000000 +0000
+++ ucf-3.0043/ucfr     2020-06-16 05:37:53.000000000 +0000
@@ -112,10 +112,18 @@
             awk '{print $1;}' );

         if [ "$pkg" != "$old_pkg" ]; then
-            if [ "X$FORCE" = "X" ]; then
-                echo >&2 "$progname: Attempt from package $pkg  to take
                 ${real_conf_file} away from package $old_pkg";
-                echo >&2 "ucfr: Aborting.";
-                exit 4;
+            divert_package=$(dpkg-divert --listpackage "$conf_file")
+            if [ -n "$divert_package" ]; then
+                if [ "X$VERBOSE" != "X" ]; then
+                    echo >&2 "$progname: Package $pkg will not take
away diverted ${conf_file} from package $divert_package";
+                fi
+                exit 0;
+            else
+                if [ "X$FORCE" = "X" ]; then
+                    echo >&2 "$progname: Attempt from package $pkg  to
take ${real_conf_file} away from package $old_pkg";
+                    echo >&2 "ucfr: Aborting.";
+                    exit 4;
+                fi
             fi
         else
             if [ "X$VERBOSE" != "X" ]; then


And I can confirm that it fixes my issue.

root@proxy19:~# apt-get install --reinstall openssh-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded.
Need to get 432 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://aptmirror17.home.woodall.me.uk/local bullseye/main amd64 
openssh-server amd64 1:8.7p1-2+tjw11r1 [432 kB]
...
Setting up openssh-server (1:8.7p1-2+tjw11r1) ...
/usr/bin/ucf: 444: [: missing ]
grep: ]: No such file or directory
Restarting OpenBSD Secure Shell server: sshd.

root@proxy19:~# apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  ucf
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 74.1 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://aptmirror17.home.woodall.me.uk/local bullseye/main amd64 ucf all 
3.0043+tjw11r1 [74.1 kB]
Fetched 74.1 kB in 0s (359 kB/s)
(Reading database ... 22805 files and directories currently installed.)
Preparing to unpack .../ucf_3.0043+tjw11r1_all.deb ...
Unpacking ucf (3.0043+tjw11r1) over (3.0043) ...
Setting up ucf (3.0043+tjw11r1) ...


root@proxy19:~# apt-get install --reinstall openssh-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/432 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 22805 files and directories currently installed.)
Preparing to unpack .../openssh-server_1%3a8.7p1-2+tjw11r1_amd64.deb ...
Unpacking openssh-server (1:8.7p1-2+tjw11r1) over (1:8.7p1-2+tjw11r1) ...
Setting up openssh-server (1:8.7p1-2+tjw11r1) ...
Restarting OpenBSD Secure Shell server: sshd.

Reply via email to