1
0
Fork 0

Applying patch from Helmut Grohne <helmut@subdivi.de> to fix broken upgrade from bookworm due to /usr-move mitigations (Closes: #1104306).

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-02 04:31:57 +02:00
parent 20d1a35eff
commit aeb3e10b75
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
2 changed files with 51 additions and 11 deletions

57
debian/zutils.preinst vendored
View file

@ -4,14 +4,45 @@ set -e
# DEP17 M18: Duplicate diversion in aliased location /bin.
die() {
printf '%s, cannot proceed\n' "$*" 1>&2
exit 1
}
case "${1}" in
install)
# Situations considered:
# * bookworm or earlier gzip is fully installed.
# -> No diversions, /bin/${FILE}
# * trixie or later gzip is unpacked.
# -> No diversions, /usr/bin/${FILE}
# * trixie or later gzip has been unpacked while bookworm's
# zutils was installed, but zutils has since been removed.
# -> /usr/bin/FILE -> /usr/bin/FILE.usr-is-merged
# * trixie or later gzip is fully installed.
# -> No diversions, /usr/bin/${FILE}
#
# We cannot run between gzip.preinst and gzip unpack.
GZIP_VERSION=$(dpkg-query -f '${Version}' -W gzip)
GZIP_PREFIX=/usr
dpkg --compare-versions "$GZIP_VERSION" lt 1.12-1.1~ && GZIP_PREFIX=
for FILE in zcat zcmp zdiff zegrep zfgrep zgrep
do
# We may move $FILE to $FILE.gzip when we expected $FILE.gzip.usr-is-merged here.
# This is ok, because gzip will be upgraded and overwrite $FILE.gzip.
dpkg-divert --package zutils --quiet --add --rename --divert "/usr/bin/${FILE}.gzip" "/usr/bin/${FILE}"
dpkg-divert --package zutils --quiet --add --rename --divert "/bin/${FILE}.gzip.usr-is-merged" "/bin/${FILE}"
TRUENAME=$(dpkg-divert --truename "/usr/bin/${FILE}")
if [ "${TRUENAME}" = "/usr/bin/${FILE}.usr-is-merged" ]
then
dpkg-divert --package zutils --quiet --remove --no-rename --divert "${TRUENAME}" "/usr/bin/${FILE}"
elif [ "${TRUENAME}" != "/usr/bin/${FILE}" ]
then
die "unexpected diversion of /usr/bin/${FILE} to ${TRUENAME}"
fi
# We cannot --rename, because it'll rename any existing
# file without checking whether the file is owned or
# not. Correctly compute the required rename depending
# on the gzip version.
dpkg-divert --package zutils --quiet --add --no-rename --divert "/usr/bin/${FILE}.gzip" "/usr/bin/${FILE}"
dpkg-divert --package zutils --quiet --add --no-rename --divert "/bin/${FILE}.gzip.usr-is-merged" "/bin/${FILE}"
mv "${DPKG_ROOT:-}${TRUENAME}" "${DPKG_ROOT:-}${GZIP_PREFIX}/bin/${FILE}.gzip${GZIP_PREFIX:+.usr-is-merged}"
dpkg-divert --package zutils --quiet --add --rename --divert /usr/share/man/man1/${FILE}.gzip.1.gz /usr/share/man/man1/${FILE}.1.gz
done
;;
@ -23,12 +54,23 @@ case "${1}" in
if [ "${TRUENAME}" = "/usr/bin/${FILE}.usr-is-merged" ]
then
# gzip.preinst duplicated the diversion for us
# This branch should be dead code. The
# diversion indicates that trixie's gzip has
# been unpacked, but trixie's gzip also
# conflicts with zutils (<< trixie), so either
# we're not installing or we are upgrading from
# trixie.
if ! [ -e "${DPKG_ROOT}${TRUENAME}" ]
then
die "diverted file ${TRUENAME} does not exist"
fi
dpkg-divert --package zutils --quiet --remove --no-rename --divert "/usr/bin/${FILE}.usr-is-merged" "/usr/bin/${FILE}"
dpkg-divert --package zutils --quiet --remove --no-rename "/bin/${FILE}"
dpkg-divert --package zutils --quiet --add --no-rename --divert "/usr/bin/${FILE}.gzip" "/usr/bin/${FILE}"
dpkg-divert --package zutils --quiet --add --no-rename --divert "/bin/${FILE}.gzip.usr-is-merged" "/bin/${FILE}"
elif [ "${TRUENAME}" != "/usr/bin/${FILE}.gzip" ]
mv "${DPKG_ROOT}${TRUENAME}" "${DPKG_ROOT}/usr/bin/${FILE}.gzip"
elif [ "${TRUENAME}" = "/usr/bin/${FILE}" ]
then
dpkg-divert --package zutils --quiet --add --no-rename --divert "/usr/bin/${FILE}.gzip" "/usr/bin/${FILE}"
@ -43,6 +85,9 @@ case "${1}" in
mv "${DPKG_ROOT}${TRUENAME}" "${DPKG_ROOT}/bin/${FILE}.gzip.usr-is-merged"
fi
fi
elif [ "${TRUENAME}" != "/usr/bin/${FILE}.gzip" ]
then
die "unexpected diversion of /usr/bin/${FILE} to ${TRUENAME}"
fi
done
;;