Package: dash Version: 0.5.11+git20210120+802ebd4-1 Tags: patch At present, /bin/sh is always diverted. The diversion takes one of three forms:
A. diverted by package dash, pointing to dash B. diverted by package bash (but performed by dash.postinst), pointing to bash C. local diversion The local diversion gives freedom to administrators to manually point their /bin/sh at bash and seems to be still in use. dash.postinst takes care not to mess with such diversions and that should continue to work. Unless there is a local diversion, dash.postinst sets up either A or B depending on a debconf question defaulting to A. Since /bin/sh normally points to dash when not diverted, the diversion A seems unnecessary. B will have to continue to exist for as long as dash supports changing /bin/sh via debconf. Diversion A was not always unnecessary. It was added with reason. /bin/sh was formerly owned by bash and this path was transferred from bash to dash. Now if bash was upgraded before dash, /bin/sh could go missing. To prevent that situation, both packages added a diversion. This upgrade sequence has long since been completed in some ancient stable release. Therefore, the need for diversion A no longer exists. It can be removed now. I'm attaching a patch to implement that. It removes any existing diversion of dash on upgrade and only creates diversions when retargeting /bin/sh at bash. The vast majority of default installations will go without a diversion and without /bin/sh.distrib. Please consider applying it. Helmut
diff --minimal -Nru dash-0.5.11+git20210120+802ebd4/debian/changelog dash-0.5.11+git20210120+802ebd4/debian/changelog --- dash-0.5.11+git20210120+802ebd4/debian/changelog 2021-03-04 10:22:32.000000000 +0100 +++ dash-0.5.11+git20210120+802ebd4/debian/changelog 2021-06-03 20:19:40.000000000 +0200 @@ -1,3 +1,10 @@ +dash (0.5.11+git20210120+802ebd4-1.1) UNRELEASED; urgency=medium + + * Non-maintainer upload. + * Remove unnecessary diversion in case /bin/sh points to dash. (Closes: #-1) + + -- Helmut Grohne <hel...@subdivi.de> Thu, 03 Jun 2021 20:19:40 +0200 + dash (0.5.11+git20210120+802ebd4-1) unstable; urgency=medium * New upstream snapshot. diff --minimal -Nru dash-0.5.11+git20210120+802ebd4/debian/dash.postinst dash-0.5.11+git20210120+802ebd4/debian/dash.postinst --- dash-0.5.11+git20210120+802ebd4/debian/dash.postinst 2021-03-04 10:22:32.000000000 +0100 +++ dash-0.5.11+git20210120+802ebd4/debian/dash.postinst 2021-06-03 20:19:40.000000000 +0200 @@ -25,7 +25,7 @@ diverter=$(dpkg-divert --listpackage $dfile) truename=$(dpkg-divert --truename $dfile) - if [ "$diverter" = dash ]; then + if [ -z "$diverter" ]; then # good. return fi @@ -35,7 +35,7 @@ return fi - if [ -n "$diverter" ] && [ "$diverter" != bash ]; then + if [ "$diverter" != bash ]; then # Let dpkg-divert error out; we are not taking # over the diversion, unless we added it # ourselves on behalf of bash. @@ -45,7 +45,6 @@ fi dpkg-divert --package bash --no-rename --remove $dfile - dpkg-divert --package dash --no-rename --divert $distrib --add $dfile # remove the old equivalent of $distrib, if it existed. if [ -n "$truename" ]; then rm -f "$truename" @@ -58,18 +57,20 @@ diverter=$(dpkg-divert --listpackage $dfile) truename=$(dpkg-divert --truename $dfile) - if [ "$diverter" != dash ]; then + if [ "$diverter" = dash ]; then + # Should not happen. Handle anyway. + dpkg-divert --package dash --no-rename --remove "$dfile" + if [ -n "$truename" ]; then + rm -f "$truename" + fi + elif [ -n "$diverter" ]; then # good. return fi # Donate the diversion and sh symlink to the bash package. ltarget=$(echo $ltarget | sed s/dash/bash/) - dpkg-divert --package dash --no-rename --remove $dfile dpkg-divert --package bash --no-rename --divert $distrib --add $dfile - if [ -n "$truename" ]; then - rm -f "$truename" - fi replace_with_link $dfile $ltarget $distrib } @@ -85,7 +86,6 @@ if [ "$diverter" = ash ]; then dpkg-divert --package ash --no-rename --remove $dfile - dpkg-divert --package dash --no-rename --divert $distrib --add $dfile if [ "$truename" != "$distrib" ] && [ -e "$truename" ]; then mv "$truename" "$distrib" @@ -104,6 +104,20 @@ fi } +drop_obsolete_diversion() { + dfile=$1 ltarget=$2 distrib=${3:-$dfile.distrib} + diverter=$(dpkg-divert --listpackage "$dfile") + truename=$(dpkg-divert --truename "$dfile") + actualtarget=$(readlink "$dfile") + + if [ "$diverter" != dash ] || [ "$truename" != "$distrib" ] || [ "$actualtarget" != "$ltarget" ]; then + # Not our diversion or a non-trivial one. + return + fi + dpkg-divert --package dash --no-rename --remove "$dfile" + rm -f "$truename" +} + add_shell() { if ! type add-shell > /dev/null 2>&1; then return @@ -124,6 +138,10 @@ /usr/share/man/man1/sh.distrib.1.gz \ /usr/share/man/man1/ash.1.gz add_shell +elif [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.5.11+git20210120+802ebd4-1.1~; then + drop_obsolete_diversion /bin/sh dash + drop_obsolete_diversion /usr/share/man/man1/sh.1.gz dash.1.gz /usr/share/man/man1/sh.distrib.1.gz + add_shell elif [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.4.18; then add_shell fi