Score:1

Is a .deb package's postinst script guaranteed to run when upgrading to a new version of Ubuntu?

bd flag

My .deb package contains a postinst script that modifies the package depending on the user's operating system.

I would like to make sure that this postinst script is re-run when the user upgrades their version of Ubuntu. Is this guaranteed to happen, or do I need to configure the script to ensure that it is run again?

us flag
It is a good idea to remove all PPAs/foreign packages before upgrading, and add/install them once again afterwards
Harry Williams avatar
bd flag
That makes sense from the user's perspective, but I want this package to work even if the user doesn't uninstall it before upgrading.
Score:4
cn flag

A postinst script runs when that particular package is installed or upgraded.

It does not run at any other time.

The usual method to ensure that the script runs during a release-upgrade is to upgrade the package by bumping the version number.

So...

 Release A = Version 1.1a
 Release B = Version 1.1b (still version 1.1, but different to apt)
 Release C = Version 1.2a (new upstream release version 1.2)

Yes, this means that you are maintaining multiple versions. But in a Debian-based system, that's the simplest solution. There are alternatives using other packaging systems, each with their own advantages and disadvantages.

Harry Williams avatar
bd flag
Thank you for the background. I'm a little confused about how I would update the version number on release-upgrade though. Could you please point me to a resource for that?
user535733 avatar
cn flag
Changing the version number that apt sees is just a change to your deb's control file.
Harry Williams avatar
bd flag
I meant how would I automatically increment the version number when the user upgrades their OS. To be clear, I'm hoping that the user will *not* have to reinstall the application when they update their OS.
user535733 avatar
cn flag
Let's take a step back. Your original question asked specifically about a `postinst` script. But now you're trying to follow up with basic questions about how repositories and control files work. I'm smelling a possible [XY Problem](https://en.wikipedia.org/wiki/XY_problem). Why not ask a new question about the best way to achieve the system customizations that you want to happen? There might be a better way than using postinst.
Score:0
br flag

In best case you can put a trigger on "/etc/os-release" in your package, which triggers your package whenever this file is changed by another package.

This does not work if a package changes "/etc/os-release" in a pre/post-script or via mechanisms like "ucf" or "config-package".

As "/etc/os-release" is part of the package "base-files" the trigger usually works as expected.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.