[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Skeleton maintainer scripts



Hi all,

I seem to remember someone asking what all the cases were that the
maintainer scripts ({pre,post}{inst,rm}) should handle.  Since I wanted
to know about this, too, I researched it in the packaging manual and put
together the following skeleton scripts, which might help.  Let me know if
they are of any use, and if you have ideas as to how I could improve them!

------------------------------------------------------------------------------
#! /bin/sh
# preinst.skeleton
# Skeleton maintainer script showing all the possible cases.
# Written by Charles Briscoe-Smith, March 1998.  Public Domain.
#
# I've attempted to document all the cases as best I can.  What's more,
# I even have reason to believe this script works!  It does nothing,
# but if you replace the lines with a `:' at the left margin with your
# code, it'll be called at the correct places.
#
# Some general points relevant to preinst scripts (gleaned from the
# Debian policy manual version 2.4.0.0, and the packaging manual):
#
# - Trap all errors
# - Don't generate any unnecessary output
# - Do not prompt the user in this script; do prompting in postinst
# - Vitally important messages to the system administrator (NOT the end
#   user) should be displayed by the postinst, then wait for return to
#   be pressed.
# - Be idempotent: make sure nothing bad will happen if the script is
#   called twice where it would usually be called once.
# - Return an exit status of zero if you succeed, non-zero if you fail
# - Remember stdout may be redirected (e.g. to a pipe) for logging
#   purposes.

# Abort if any command returns an error value
set -e

# This script is called before this version of this package is installed.
# When this script is called, the package's files have not been unpacked
# yet.

case "$1" in
  install)
    # About to install this package.  There are two sub-cases.
:
    if test "${2+set}" = set; then
      # The configuration files from version $2 of this package are
      # still on the system.
:
    else
      # There is no existing configuration; install from scratch.
:
    fi ;;
  upgrade)
    # About to upgrade this package from version $2 TO THIS VERSION.
    # Note that an 'upgrade' may be to any version of the same package,
    # even the same version or a previous version.  "prerm upgrade"
    # has already been called for the old version of this package.
:
    ;;
  abort-upgrade)
    # Back out of an attempt to upgrade this package FROM THIS VERSION to
    # version $2.  Undo the effects of "postrm upgrade $2".
:
    ;;
  *) echo "$0: didn't understand being called with \`$1'" 1>&2
     exit 1;;
esac

exit 0
------------------------------------------------------------------------------

------------------------------------------------------------------------------
#! /bin/sh
# postinst.skeleton
# Skeleton maintainer script showing all the possible cases.
# Written by Charles Briscoe-Smith, March 1998.  Public Domain.
#
# I've attempted to document all the cases as best I can.  What's more,
# I even have reason to believe this script works!  It does nothing,
# but if you replace the lines with a `:' at the left margin with your
# code, it'll be called at the correct places.
#
# Some general points relevant to postinst scripts (gleaned from the
# Debian policy manual version 2.4.0.0, and the packaging manual):
#
# - Trap all errors
# - Don't generate any unnecessary output
# - Prompt the user only in the "postinst configure" case if possible.
# - Prompt the user only for the minimum possible information
# - Never prompt for the same information twice, unless the information
#   has been purged since last collected
# - Vitally important messages to the system administrator (NOT the end
#   user) should be displayed by the postinst, then wait for return to
#   be pressed.
# - Be idempotent: make sure nothing bad will happen if the script is
#   called twice where it would usually be called once.
# - Return an exit status of zero if you succeed, non-zero if you fail
# - If you prompt for a password, do full-screen interaction, or the like,
#   use /dev/tty for these things, not standard input/output.  Stdout may
#   be redirected (e.g. to a pipe) for logging purposes.

# Abort if any command returns an error value
set -e

# This script is called as the last step of the installation of the
# package.  All the package's files are in place, dpkg has already done
# its automatic conffile handling, and all the packages we depend of
# are already fully installed and configured.

case "$1" in
  configure)
    # Configure this package.  If the package must prompt the user for
    # information, do it here.  There are three sub-cases.
:
    if test "${2+set}" != set; then
      # We're being installed by an ancient dpkg which doesn't remember
      # which version was most recently configured, or even whether
      # there is a most recently configured version.
:
    elif test -z "$2" -o "$2" = "<unknown>"; then
      # The package has not ever been configured on this system, or was
      # purged since then.
:
    else
      # Version $2 is the most recently configured version of this
      # package.
:
    fi ;;
  abort-upgrade)
    # Back out of an attempt to upgrade this package FROM THIS VERSION
    # to version $2.  Undo the effects of "prerm upgrade $2".
:
    ;;
  abort-remove)
    if test "$2" != in-favour; then
      echo "$0: undocumented call to \`postinst $*'" 1>&2
      exit 1
    fi
    # Back out of an attempt to remove this package, which was due to
    # a conflict with package $3 (version $4).  Undo the effects of
    # "prerm remove in-favour $3 $4".
:
    ;;
  abort-deconfigure)
    if test "$2" != in-favour -o "$5" != removing; then
      echo "$0: undocumented call to \`postinst $*'" 1>&2
      exit 1
    fi
    # Back out of an attempt to deconfigure this package, which was
    # due to package $6 (version $7) which we depend on being removed
    # to make way for package $3 (version $4).  Undo the effects of
    # "prerm deconfigure in-favour $3 $4 removing $6 $7".
:
    ;;
  *) echo "$0: didn't understand being called with \`$1'" 1>&2
     exit 1;;
esac

exit 0
------------------------------------------------------------------------------

------------------------------------------------------------------------------
#! /bin/sh
# prerm.skeleton
# Skeleton maintainer script showing all the possible cases.
# Written by Charles Briscoe-Smith, March 1998.  Public Domain.
#
# I've attempted to document all the cases as best I can.  What's more,
# I even have reason to believe this script works!  It does nothing,
# but if you replace the lines with a `:' at the left margin with your
# code, it'll be called at the correct places.
#
# Some general points relevant to prerm scripts (gleaned from the
# Debian policy manual version 2.4.0.0, and the packaging manual):
#
# - Trap all errors
# - Don't generate any unnecessary output
# - Do not prompt the user in this script; do prompting in postinst
# - Vitally important messages to the system administrator (NOT the end
#   user) should be displayed by the postinst, then wait for return to
#   be pressed.
# - Be idempotent: make sure nothing bad will happen if the script is
#   called twice where it would usually be called once.
# - Return an exit status of zero if you succeed, non-zero if you fail
# - Remember stdout may be redirected (e.g. to a pipe) for logging
#   purposes.

# Abort if any command returns an error value
set -e

# This script is called as the first step in removing the package from
# the system.  This includes cases where the user explicitly asked for
# the package to be removed, upgrade, automatic removal due to conflicts,
# and deconfiguration due to temporary removal of a depended-on package.

case "$1" in
  remove)
    # This package about to be removed.  There are two sub-cases.
:
    if test "${2+set}" = set; then
      if test "$2" != in-favour; then
        echo "$0: undocumented call to \`prerm $*'" 1>&2
        exit 1
      fi
      # We are being removed because of a conflict with package $3
      # (version $4), which is now being installed.
:
    else
      # The package is being removed in its own right.
:
    fi ;;
  deconfigure)
    if test "$2" != in-favour -o "$5" != removing; then
      echo "$0: undocumented call to \`prerm $*'" 1>&2
      exit 1
    fi
    # Package $6 (version $7) which we depend on is being removed due
    # to a conflict with package $3 (version $4), and this package is
    # being deconfigured until $6 can be reinstalled.
:
    ;;
  upgrade)
    # Prepare to upgrade FROM THIS VERSION of this package to version $2.
    # Note that an 'upgrade' may be to any version of the same package,
    # even the same version or a previous version.
:
    ;;
  failed-upgrade)
    # Prepare to upgrade from version $2 of this package TO THIS VERSION.
    # This is only used if the old version's prerm couldn't handle it,
    # and returned non-zero.  (Fix old prerm bugs here.)
:
    ;;
  *) echo "$0: didn't understand being called with \`$1'" 1>&2
     exit 1;;
esac

exit 0
------------------------------------------------------------------------------

------------------------------------------------------------------------------
#! /bin/sh
# postrm.skeleton
# Skeleton maintainer script showing all the possible cases.
# Written by Charles Briscoe-Smith, March 1998.  Public Domain.
#
# I've attempted to document all the cases as best I can.  What's more,
# I even have reason to believe this script works!  It does nothing,
# but if you replace the lines with a `:' at the left margin with your
# code, it'll be called at the correct places.
#
# Some general points relevant to postrm scripts (gleaned from the
# Debian policy manual version 2.4.0.0, and the packaging manual):
#
# - Trap all errors
# - Don't generate any unnecessary output
# - Do not prompt the user in this script; do prompting in postinst
# - Vitally important messages to the system administrator (NOT the end
#   user) should be displayed by the postinst, then wait for return to
#   be pressed.
# - Be idempotent: make sure nothing bad will happen if the script is
#   called twice where it would usually be called once.
# - Return an exit status of zero if you succeed, non-zero if you fail
# - Remember stdout may be redirected (e.g. to a pipe) for logging
#   purposes.

# Abort if any command returns an error value
set -e

# This script is called twice during the removal of the package; once
# after the removal of the package's files from the system, and as
# the final step in the removal of this package, after the package's
# conffiles have been removed.

case "$1" in
  remove)
    # This package has been removed, but its configuration has not yet
    # been purged.
:
    ;;
  purge)
    # This package has previously been removed and is now having
    # its configuration purged from the system.
:
    ;;
  disappear)
    if test "$2" != overwriter; then
      echo "$0: undocumented call to \`postrm $*'" 1>&2
      exit 1
    fi
    # This package has been completely overwritten by package $3
    # (version $4).  All our files are already gone from the system.
    # This is a special case: neither "prerm remove" nor "postrm remove"
    # have been called, because dpkg didn't know that this package would
    # disappear until this stage.
:
    ;;
  upgrade)
    # About to upgrade FROM THIS VERSION to version $2 of this package.
    # "prerm upgrade" has been called for this version, and "preinst
    # upgrade" has been called for the new version.  Last chance to
    # clean up.  Note that an 'upgrade' may be to any version of the
    # same package, even the same version or a previous version.
:
    ;;
  failed-upgrade)
    # About to upgrade from version $2 of this package TO THIS VERSION.
    # "prerm upgrade" has been called for the old version, and "preinst
    # upgrade" has been called for this version.  This is only used if
    # the previous version's "postrm upgrade" couldn't handle it and
    # returned non-zero. (Fix old postrm bugs here.)
:
    ;;
  abort-install)
    # Back out of an attempt to install this package.  Undo the effects of
    # "preinst install...".  There are two sub-cases.
:
    if test "${2+set}" = set; then
      # When the install was attempted, version $2's configuration
      # files were still on the system.  Undo the effects of "preinst
      # install $2".
:
    else
      # We were being installed from scratch.  Undo the effects of
      # "preinst install".
:
    fi ;;
  abort-upgrade)
    # Back out of an attempt to upgrade this package from version $2
    # TO THIS VERSION.  Undo the effects of "preinst upgrade $2".
:
    ;;
  *) echo "$0: didn't understand being called with \`$1'" 1>&2
     exit 1;;
esac

exit 0
------------------------------------------------------------------------------

-- 
Charles Briscoe-Smith
White pages entry, with PGP key: <URL:http://alethea.ukc.ac.uk/wp?95cpb4>
PGP public keyprint: 74 68 AB 2E 1C 60 22 94  B8 21 2D 01 DE 66 13 E2


--
To UNSUBSCRIBE, email to debian-mentors-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: