6.4. Best practices for maintainer scripts
Maintainer scripts include the files debian/postinst
, debian/preinst
, debian/prerm
and debian/postrm
. These scripts take care of any package installation or deinstallation setup that isn’t handled merely by the creation or removal of files and directories. The following instructions supplement the Debian Policy.
Maintainer scripts must be idempotent. That means that you need to make sure nothing bad will happen if the script is called twice where it would usually be called once.
Standard input and output may be redirected (e.g. into pipes) for logging purposes, so don’t rely on them being a tty.
All prompting or interactive configuration should be kept to a minimum. When it is necessary, you should use the debconf
package for the interface. Remember that prompting in any case can only be in the configure
stage of the postinst
script.
Keep the maintainer scripts as simple as possible. We suggest you use pure POSIX shell scripts. Remember, if you do need any bash features, the maintainer script must have a bash shebang line. POSIX shell or Bash are preferred to Perl, since they enable debhelper
to easily add bits to the scripts.
If you change your maintainer scripts, be sure to test package removal, double installation, and purging. Be sure that a purged package is completely gone, that is, it must remove any files created, directly or indirectly, in any maintainer script.
If you need to check for the existence of a command, you should use something like
if command -v install-docs > /dev/null; then ...
You can use this function to search $PATH
for a command name, passed as an argument. It returns true (zero) if the command was found, and false if not. This is really the best way, since command -v
is a shell-builtin for many shells and is defined in POSIX.
Using which
is an acceptable alternative, since it is from the required debianutils
package.