#!/bin/sh
#
# This is to allow downgrades to version 0.5.11+git20210903+057cd650a4ed-3 and
# earlier which do not use the update-shells trigger of debianutils to manage
# /etc/shells.
#
# update-shells will be called at the end of the downgrade because a trigger of
# debianutils on the removal of /usr/share/debianutils/shells.d/dash will be
# activated when downgrading to a version of dash that doesn't ship that file.
# But a non-existing /usr/share/debianutils/shells.d/dash tells update-shells
# to remove dash from /etc/shells.
#
# To prevent this from happening, remove /usr/share/debianutils/shells.d/dash
# which will be removed by the downgrade anyways, then run update-shells which
# will remove dash from /etc/shells and then add it again by running add-shell.
# Subsequent calls to update-shells in the debianutils trigger will now not
# remove dash from /etc/shells anymore because the update-shells call in this
# script updated /var/lib/shells.state with the information that it doesn't
# manage dash via update-shells anymore.

set -e

if [ "$1" = upgrade ] \
	&& dpkg --compare-versions "$2" le 0.5.11+git20210903+057cd650a4ed-3 \
	&& [ -e /usr/share/debianutils/shells.d/dash ] \
	&& [ -x "$(command -v update-shells 2>/dev/null)" ] \
	&& [ -x "$(command -v add-shell 2>/dev/null)" ]; then
	rm /usr/share/debianutils/shells.d/dash
	update-shells
	add-shell /bin/dash
fi

# Automatically added by dh_installmenu/13.11.4
if [ -x "`command -v update-menus`" ] && [ -x "$DPKG_ROOT`command -v update-menus`" ]; then update-menus ; fi
# End automatically added section

