I recently started building Ubuntu packages for my software on Launchpad. They are pretty simple; most of them just contain some files and scripts that are trigged through the .install .preinst .postinst .prerm and .postrm files. Installation and removing seems to work OK. However, upgrading from one version to the next is tricky.
What exactly happens when a package is being upgraded? Is it the same thing as uninstalling the previous version and installing the new version? Are all the files from the previous packages removed, and replaced with the files in the .install list from the new package? Are all of the .prerm, postrm, preinst, postinst scripts executed? How do I distinguish stuff that should only happen during a 'new install' and an upgrade?