[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Specifying %{variable} in control file for use in postinst?



Ignacio Valdes wrote:
> So here is the use case, one that to my knowledge rpm or deb do not
> provide much guidance for and deb does not provide control fields for:
> Package is a vehicle for installing software that can create multiple
> instances. Further, those instances can be very long lived (decades)
> and almost certainly will be updated and migrated in the future to new
> hardware and software. Finally that in the case of a catastrophic
> failure, the metadata of the rpm/deb file such as name of the rpm/deb
> file and versions that created it are barcoded redundantly with the
> instance in an a instance env file that rides within the instance
> directory tree in a known location in order to facilitate recovery and
> maintenance (this last part is already worked out).
>   

Both rpm and dpkg support setting-up in chroots.

> rpm because it can access the spec file header information this is
> pretty easy to do. For deb this looks like I am going to have to parse
> the control file to get this information out. Is there any bash
> control file parsers out there?
>   
No, parsing the control file might be dangerous, there's nothing that
tells you it wont change format in the future. What's best is to generate
variable for use in your postinst. My example parses the top of the
debian/changelog, but you could do the same with debian/control

#!/bin/sh

set -e

PKG_NAME=__PKG_NAME__
PKG_VERS=__PKG_VERS__
PKG_DEB_REL=__PKG_DEB_REL__

then in your debian/rules build rule, you can do something like:

MY_VERS=`head -n 1 debian/changelog | cut -d'(' -f2 | cut -d')' -f1 |
cut -d'-' -f1`
MY_DEB_REL=`head -n 1 debian/changelog | cut -d'(' -f2 | cut -d')' -f1 |
cut -d'-' -f2`
MY_PKGNAME=`head -n 1 debian/changelog | cut -d' ' -f1`
sed "s/__PKG_NAME__/${MY_PKGNAME}/" debian/master.postinst
>debian/postinst.temp
sed -i "s/__PKG_DEB_REL__/${MY_DEB_REL}/" debian/postinst.temp
sed "s/__PKG_VERS__/${MY_PKGNAME}/" debian/postinst.temp >debian/postinst

Of course, your clean target should remove debian/postinst.temp and
debian/postinst

that way, you can get the variables you need available in your postinst
in a not too ugly way. I believe you can also do the same for debian/config
and all the other maintainer scripts in general.

If you find this very hard to do and think it could have been made more,
simple, well as many highlighted, in a normal situation you don't need
to have access to all of this.

Thomas


Reply to: