#! /bin/sh
#
# initscripts preinst
#


# Remove a no-longer used conffile
#
# $1: conffile
#
# If the argument was not listed as a conffile, silently do nothing.
# Adapted from code obtained from www.dpkg.org/ConffileHandling
eliminate_conffile() {
	CONFFILE="$1"
	if [ -f "$CONFFILE" ]; then
		CURRENT_MD5SUM="$(md5sum "$CONFFILE" 2>/dev/null | sed -e "s/ .*//")"
		FACTORY_MD5SUM="$(sed -n -e "/^Conffiles:/,/^[^ ]/{\\' $CONFFILE'{s/.* //;p}}" /var/lib/dpkg/status)"
		if [ "$CURRENT_MD5SUM" != "$FACTORY_MD5SUM" ]; then
			echo -n "Renaming obsolete modified conffile "
			mv -vf "$CONFFILE" "$CONFFILE".dpkg-old
		else
			echo -n "Unmodified conffile '${CONFFILE}' obsolete; "
			rm -vf "$CONFFILE"
		fi
	fi
}

case "$1" in
  install|upgrade)
	#
	# /etc/init.d/stop-bootlogd used to be a symlink to bootlogd;
	# now it is a separate script.  We need to remove the symlink here,
	# before dpkg installs the /etc/init.d/stop-bootlogd file.
	#
	[ -L /etc/init.d/stop-bootlogd ] && rm -f /etc/init.d/stop-bootlogd
	#
	# Remove obsolete conffiles
	#
	if [ "$2" ] && dpkg --compare-versions "$2" lt "2.86.ds1-10" ; then
		eliminate_conffile "/etc/init.d/bootclean.sh"
	fi
	#
	# Move conflicting log _file_ if present
	#
	[ -f /var/log/fsck ] && mv -f /var/log/fsck /var/log/fsck.dpkg-old
	;;
  abort-upgrade)
	exit 0
	;;
esac

:
