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

Skeleton maintainer scripts (revised)



Okay, here's a revision.  First, some text to go with the scripts, then
the scripts themselves.  Feel free to make any revisions you want.
They're probably still a bit verbose, but I don't see that that's a
problem.  I don't think there's much duplication, so trimming it would
probablby remove useful information.  In particular, there's an
important distinction between bits of code run in an upgrade to this
version vs. from this version of a package.

Cheers,

----------

Some general points relevant to writing all maintainer scripts:

- Trap all errors.
- Don't generate any unnecessary output.
- Return an exit status of zero if you succeed, non-zero if you fail.
- Be idempotent: make sure nothing bad will happen if the script is
  called twice where it would usually be called once.
- Remember the standard input and output may be redirected (e.g. into
  pipes) for logging purposes.

Prompting should whenever possible be confined to the case when the
postinst script is called with the argument "configure":

- If you have a vitally important message to show the system administrator
  (NOT the end user) the postinst should display it, then wait for return
  to be pressed.
- 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.
- If you prompt for a password, do full-screen interaction, or the like,
  use /dev/tty for these things, not standard input/output.

Lastly, note that, in dpkg-speak, an 'upgrade' may be to any version of
the same package, even the same version or a previous version.  Thus,
the 'upgrade' cases of the scripts are used even when reinstalling a
package over the top of the same version of itself, or when downgrading.

----------------------------------------------------------------------
#! /bin/sh
# preinst.skeleton
# Skeleton maintainer script showing all the possible cases.
# Written by Charles Briscoe-Smith, March 1998.  Public Domain.

# 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.
    # "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-April 1998.  Public Domain.

# 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 it was last configured.
      :
    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.

# 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.
    :
    ;;
  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-April 1998.  Public Domain.

# 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.
    :
    ;;
  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-dpkg-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: