Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the standard way to share code between the dpkg scripts (preinst, postinst, prerm, postrm)?

I can see how to share code between just postinst and prerm (by installing it as part of the package), but can't see any way to share with preinst and postrm.

share|improve this question
up vote 1 down vote accepted

I'm pretty sure there's nothing to be done. You can rely on a Pre-Depend:, but these are to be avoided unless absolutely necessary, as they're a heavy burden on the dependency chain.

You can pre-process the scripts, if there's code to be shared. The debhelper tools already do this, inserting boilerplate into the various maintainer scripts.

It's rare to need to do complicated things in preinst or postinst. The main adhockery tends to be handling tricky upgrades, and that's usually custom code in a preinst.

share|improve this answer
Pre-processing the scripts sounds like a reasonable option. Thanks. – Ben Butler-Cole Feb 22 '12 at 20:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.