diff --git a/debian/control b/debian/control index 0020d21..31a2a1a 100644 --- a/debian/control +++ b/debian/control @@ -18,11 +18,6 @@ Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, -Breaks: -# We must ensure that gzip is upgraded before zutils.postinst runs. As it is -# essential, Breaks is sufficient here and the janitor may propose dropping -# this relation eventually. - gzip (<< 1.12-1.1~), Suggests: bzip2, lzip, diff --git a/debian/zutils.preinst b/debian/zutils.preinst index 0b242e6..3512868 100755 --- a/debian/zutils.preinst +++ b/debian/zutils.preinst @@ -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 ;;