Add custom steps to source package's debian/package.postinst?

15,398

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:

#!/bin/sh
# 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 http://www.debian.org/doc/debian-policy/ 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
fi

case "$1" in

  configure)
    # 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_pgsql_createdb_encoding="UTF8"
    dbc_generate_include=template:/usr/share/webpy-example/lib/credentials.py
    dbc_generate_include_args="-U -o template_infile='/usr/share/doc/webpy-example/credentials_template.py'"
    dbc_generate_include_owner="root:www-data"
    dbc_generate_include_perms="0660"
    dbc_go webpy-example $@ || true
  ;;

  abort-upgrade|abort-remove|abort-deconfigure)
    exit 0
  ;;

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

esac

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

#DEBHELPER#

db_stop

exit 0
Share:
15,398

Related videos on Youtube

Matt Joiner
Author by

Matt Joiner

About Me I like parsimonious code, with simple interfaces and excellent documentation. I'm not interested in enterprise, boiler-plate, or cookie-cutter nonsense. I oppose cruft and obfuscation. My favourite languages are Go, Python and C. I wish I was better at Haskell. Google+ GitHub Bitbucket Google code My favourite posts http://stackoverflow.com/questions/3609469/what-are-the-thread-limitations-when-working-on-linux-compared-to-processes-for/3705919#3705919 http://stackoverflow.com/questions/4352425/what-should-i-learn-first-before-heading-to-c/4352469#4352469 http://stackoverflow.com/questions/6167809/how-much-bad-can-be-done-using-register-variables-in-c/6168852#6168852 http://stackoverflow.com/questions/4141307/c-and-c-source-code-profiling-tools/4141345#4141345 http://stackoverflow.com/questions/3463207/how-big-can-a-malloc-be-in-c/3486163#3486163 http://stackoverflow.com/questions/4095637/memory-use-of-stl-data-structures-windows-vs-linux/4183178#4183178

Updated on September 18, 2022

Comments

  • Matt Joiner
    Matt Joiner over 1 year

    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?