How do you access control file information?

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: ...

2 Answers

There's a few ways to do it, but the way I like to do it is by using dpkg.

Try this:

  1. Create a temporary directory ex: mkdir /tmp/pkg-tmp
  2. Extract control info with dpkg: dpkg -e ./path/to/file.deb /tmp/pkg-tmp
  3. Check out the control file, it should be in the top level directory: cat /tmp/pkg-tmp/control
  4. You may want to clean up the temp directory when you are done examining: 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.

1

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like