Is there a way for the postinst, pre, etc. scriptlets to access the information in the Debian control file when installing?
e.g.
Package: name
Version: 0.1-1
Depends: ...
Apparently, the postinst, pre, etc. scriptlets are run in an environment created by dpkg. The control information are environment variables that the scriptlets can access.
e.g.
DPKG_MAINTSCRIPT_ARCH=all
DPKG_RUNNING_VERSION=1.16.10
DPKG_MAINTSCRIPT_NAME=postinst
DPKG_MAINTSCRIPT_PACKAGE=zip
DPKG_NO_TSTP=yes
DPKG_ADMINDIR=/var/lib/dpkg
There's a few ways to do it, but the way I like to do it is by using dpkg
.
Try this:
mkdir /tmp/pkg-tmp
dpkg -e ./path/to/file.deb /tmp/pkg-tmp
cat /tmp/pkg-tmp/control
rm -rf /tmp/pkg-tmp
The postinst, preinst, and prerm scripts will be in there too. If there are no files named preinst
, postinst
, postrm
, or prerm
, then that means none of those scripts are part of the Debian packaging.
Some packages might have all of them, only 1 or 2, or none -- just depends on the package.
If the package is in an APT repository, you can run apt-get download package-name
to first download the Debian package in the current directory, then run the commands listed above.
I wrote a blog post about extracting Debian packages and examining the control file, preinstall, postinstall, prerm files that has more information.