Q:

How to avoid "trying to overwrite X which is also in package Y"

I'm setting up a large number of Ubuntu 12.04 devices.  I have a custom .deb I wrote and which will be installed on each device.  As part of that .deb, there are several system files I need to overwrite, such as:
/etc/update-manager/release-upgrades
/etc/apt/apt.conf.d/10periodic
/etc/apt/apt.conf.d/50unattended-upgrades

But of course Ubuntu complains that those files are owned by other packages.  When I try to run dpkg -i testing.deb I get errors such as these:
dpkg: error processing testing.deb (--install):
 trying to overwrite '/etc/update-manager/release-upgrades', which is also in package update-manager-core 1:0.156.14
 trying to overwrite '/etc/apt/apt.conf.d/50unattended-upgrades', which is also in package unattended-upgrades 0.76

I know about the dpkg options like --force-overwrite which I can use to force it to install, but I was hoping to keep the .deb file really easy to install without additional command-line options, and I cannot help but feel like there is probably another solution somewhere in the Debian framework.
What is the "right" way to fix it so my .deb can install with these updated/newer files?

A:

Divert the other packages' files as part of your preinst. This is exactly what dpkg-divert is for. Don't forget to remove the diversion in your postrm. See the man page and the Debian wiki for examples.

