I have created a .deb package using equivs-build command and providing necessary control, preinst, postinst, etc. I noticed that version can also be mentioned in control file. Now I want to create a .deb package with updated source code and I want to enable user to upgrade the package if it is already installed (and is of previous version, of course), as I won't be changing conf related files, etc. One way I can think of is to write a script which will first check for installed version, and will take actions accordingly (i.e. if installed, just update the source-code, database-migrations, etc. and if not, install the package using dpkg -i <package-name>). I was wondering if there was a way to achieve using dpkg only (something like dpkg upgrade <package-name>) which will handle installation or up-gradation as required.
Asked
Active
Viewed 1,189 times
1
exAres
- 243
- 1
- 3
- 6
-
On a side note, the `version` of the package usually isn't mentioned in `control` (unless you're declaring dependencies); it's only mentioned in `changelog`. – saiarcot895 Aug 08 '14 at 14:18
-
@saiarcot895 could you please elaborate a bit in details? As far as I know, mentioning `version` in `control` file is working. I tried mentioning different version in control file and tested installations. The package gets upgraded according to the `version` mentioned in `control` file. Am I missing out on something important here? Thanks. – exAres Aug 08 '14 at 14:50
-
See the [policy](https://www.debian.org/doc/debian-policy/ch-controlfields.html) here. Note that there is no `Version` field mentioned in the specifications for the source package control fields, which applies to source packages and the debian archive file; however, the `Version` field *is* required for binary package control fields (`DEBIAN/control`), which is the compiled package and the final deb. Instead, the version should be in `debian/changelog` (policy [here](https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog)). – saiarcot895 Aug 08 '14 at 14:58
-
However, from what I can tell, you are directly changing the compiled debs, and so you might be fine. – saiarcot895 Aug 08 '14 at 14:59
-
I just looked at the `equivs-build` [manpage](http://manpages.ubuntu.com/manpages/trusty/man1/equivs-build.1.html), and based on what it does there, you are fine by using `Version` in the `control` file. – saiarcot895 Aug 08 '14 at 15:03
1 Answers
1
The command you are looking for is indeed dpkg -i. This will install if not installed and upgrade if already installed. dpkg doesn't change user-modified configuration files. It will ask you what to do about such cases (keep the modifications, discard the modifications, etc.) and it will always keep a backup of whatever you discard (the new config file provided by the package, or the old user-modified file ). Any file installed by the package in /etc/ is considered by dpkg as a configuration file.
muru
- 193,181
- 53
- 473
- 722
-
I went through this link: https://wiki.debian.org/MaintainerScripts and what I understood is I need to make changes to `prerm`, `postrm`, `preinst` and `postinst` scripts. But there are several cases shown (like `prerm upgrade` and `prerm remove` for `prerm`). How do I handle such cases? I mean, how can I separate the code for `upgrade` and `remove` in `prerm` itself? – exAres Aug 07 '14 at 08:59
-
1@user2745266 Since `prerm` is a script, and usually a bash script, you can use [cases in bash](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_03.html). But you don't need to handle all the cases unless your install scripts (`postinst` and `preinst`) are doing complex stuff. – muru Aug 07 '14 at 09:01