Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have a package that incorporates an auto-generated debian/package.postinst.debhelper file into the generated binary. When I put my own code into a file at debian/package.postinst, the auto-generated file is no longer incorporated into the resulting binary.

How do I add custom code to the postinst file in the generated package without blocking the use of the auto-generated code?

share|improve this question
up vote 6 down vote accepted

Your postinst script should included a #DEBHELPER# token if you are using any debhelper commands that might modify it. It will get replaced in the resulting script by the auto-generated content. See manpage for the dh_installdeb command Manpage icon

For example:

# postinst script for webpy-example
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see or
# the debian-policy package

# source debconf library
. /usr/share/debconf/confmodule

# Source dbconfig-common functions
if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql  ]; then
  . /usr/share/dbconfig-common/dpkg/postinst.pgsql

case "$1" in

    # Set up our config for apache
    /bin/cp /usr/share/webpy-example/postinstall/webpy-config /etc/apache2/conf.d/
    /usr/sbin/a2enmod wsgi
    /usr/sbin/a2enmod rewrite
    /etc/init.d/apache2 reload

    # set up database
    dbc_generate_include_args="-U -o template_infile='/usr/share/doc/webpy-example/'"
    dbc_go webpy-example $@ || true

    exit 0

    echo "postinst called with unknown argument \`$1'" >&2
    exit 1


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.



exit 0
share|improve this answer

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.