dpkg-maintscript-helper(1)

๐Ÿ’– dpkg-maintscript-helper(1) โ€” the dpkg suite's little fixer-upper ๐Ÿ’–

okay so bestie, we need to talk about dpkg-maintscript-helper, which lives in the dpkg suite and is basically the friend who shows up with a mop when dpkg makes a mess it cannot legally clean up itself. she's a maintainer-script girlie through and through ๐Ÿงš


โœจ NAME โœจ

dpkg-maintscript-helper โ€” works around known dpkg limitations in maintainer scripts

like, she patches the gaps, no cap ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

dpkg-maintscript-helper command [parameter...] --
maint-script-parameter...

so it's command, then the parameters, then a --, then you dump all the maintainer-script parameters after it. the -- is lowkey the most important part, we'll get to that ๐Ÿ‘€


๐ŸŽ€ COMMANDS AND PARAMETERS ๐ŸŽ€

here's the whole menu, bestie โ€” memorize the vibes:

  • supports command
  • rm_conffile conffile [prior-version [package]]
  • mv_conffile old-conffile new-conffile [prior-version [package]]
  • symlink_to_dir pathname old-target [prior-version [package]]
  • dir_to_symlink pathname new-target [prior-version [package]]

square brackets mean optional, prior-version and package are the optional besties. ๐Ÿ’…


๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

so this program is designed to be run within maintainer scripts to achieve some tasks that dpkg can't (yet) handle natively โ€” either because of design decisions or due to current limitations. like, it's not a bug, it's a whole philosophy thing ๐Ÿ˜ญ

and here's the thing: many of those tasks require coordinated actions from several maintainer scripts โ€” <pink>preinst</pink>, <pink>postinst</pink>, <pink>prerm</pink>, <pink>postrm</pink>. so to avoid mistakes, the same call needs to be put in all scripts and the program will automatically adapt its behavior based on the environment variable DPKG_MAINTSCRIPT_NAME and on the maintainer scripts arguments that you have to forward after a double hyphen. one call, four scripts, zero regrets โœจ

this program was introduced in dpkg 1.15.7 โ€” vintage, but make it iconic ๐Ÿ‘‘

๐Ÿฆ‹ COMMON PARAMETERS ๐Ÿฆ‹

๐ŸŒˆ prior-version

defines the latest version of the package whose upgrade should trigger the operation. and the way it is important to calculate prior-version correctly so that the operations are correctly performed even if the user rebuilt the package with a local version. yeah. read that again. ๐Ÿซ 

if prior-version is empty or omitted, then the operation is tried on every upgrade โ€” and note: it's safer to give the version and have the operation tried only once. fr fr, give her the version.

also: if the conffile has not been shipped for several versions, and you are now modifying the maintainer scripts to clean up the obsolete file, prior-version should be based on the version of the package that you are now preparing, not the first version of the package that lacked the conffile. and this applies to all other actions in the same way. iykyk ๐Ÿ’…

for example: for a conffile removed in version 2.0-1 of a package, prior-version should be set to 2.0-1~. this will cause the conffile to be removed even if the user rebuilt the previous version 1.0-1 as 1.0-1local1. iconic behavior tbh.

or โ€” a package switching a path from a symlink (shipped in version 1.0-1) to a directory (shipped in version 2.0-1), but only performing the actual switch in the maintainer scripts in version 3.0-1 โ€” should set prior-version to 3.0-1~. see how she did that? ๐Ÿ˜Œ

๐Ÿš package

the package name owning the pathname(s). okay so when the package is โ€œMulti-Arch: sameโ€ this parameter must include the architecture qualifier, otherwise it should not usually include the architecture qualifier โ€” because that would disallow cross-grades, or switching from being architecture specific to architecture all or vice versa. messy. ๐Ÿ™ˆ

if the parameter is empty or omitted, the DPKG_MAINTSCRIPT_PACKAGE and DPKG_MAINTSCRIPT_ARCH environment variables (as set by dpkg when running the maintainer scripts) will be used to generate an arch-qualified package name. auto-magic, slay โœจ

๐ŸŽฏ --

all the parameters of the maintainer scripts have to be forwarded to the program after --. that's it. that's the whole rule. do not skip it, bestie, or it's giving chaos ๐Ÿ’€


okay so when upgrading a package, dpkg will not automatically remove a conffile (a configuration file for which dpkg should preserve user changes) if it is not present in the newer version. and there are two principal reasons for this:

  1. the first is that the conffile could've been dropped by accident and the next version could restore it โ€” users wouldn't want their changes thrown away.
  2. the second is to allow packages to transition files from a dpkg-maintained conffile to a file maintained by the package's maintainer scripts, usually with a tool like debconf or ucf.

so basically dpkg is being polite and not deleting your stuff without permission. respect. ๐Ÿซถ

this means that if a package is intended to rename or remove a conffile, it must explicitly do so, and dpkg-maintscript-helper can be used to implement graceful deletion and moving of conffiles within maintainer scripts. graceful, like a queen ๐Ÿ’…

๐Ÿ’ซ Removing a conffile

Note: this can be replaced in most cases by the "remove-on-upgrade" flag in DEBIAN/conffiles (since dpkg 1.20.6), see deb-conffiles(5).

if a conffile is completely removed, it should be removed from disk โ€” unless the user has modified it. and if there are local modifications, they should be preserved. and if the package upgrade aborts, the newly obsolete conffile should not disappear. three rules, all dramatic, all true ๐Ÿ˜ค

all of this is implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts:

dpkg-maintscript-helper rm_conffile \
   conffile prior-version package -- "$@"

conffile is the filename of the conffile to remove. simple as that ๐ŸŽ€

Current implementation: in the preinst, it checks if the conffile was modified and renames it either to conffile.dpkg-remove (if not modified) or to conffile.dpkg-backup (if modified). in the postinst, the latter file is renamed to conffile.dpkg-bak and kept for reference as it contains user modifications but the former will be removed. if the package upgrade aborts, the postrm reinstalls the original conffile. during purge, the postrm will also delete the .dpkg-bak file kept up to now. the way she keeps receipts ๐Ÿ˜ญ

๐Ÿ’ซ Renaming a conffile

if a conffile is moved from one location to another, you need to make sure you move across any changes the user has made. this may seem a simple change to the preinst script at first โ€” however that will result in the user being prompted by dpkg to approve the conffile edits even though they are not responsible of them. awkward. not the vibe. ๐Ÿ™ˆ

graceful renaming can be implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts:

dpkg-maintscript-helper mv_conffile \
   old-conffile new-conffile prior-version package -- "$@"

old-conffile and new-conffile are the old and new name of the conffile to rename. she said what she said ๐Ÿ’…

Current implementation: the preinst checks if the conffile has been modified, if yes it's left on place otherwise it's renamed to old-conffile.dpkg-remove. on configuration, the postinst removes old-conffile.dpkg-remove and renames old-conffile to new-conffile if old-conffile is still available. on abort-upgrade/abort-install, the postrm renames old-conffile.dpkg-remove back to old-conffile if required. an icon, an absolute icon ๐Ÿ‘‘


when upgrading a package, dpkg will not automatically switch a symlink to a directory or vice-versa. and โ€” heads up โ€” downgrades are not supported and the path will be left as is. no take-backs, bestie ๐Ÿ’€

Note: the symlinks and directories created during these switches need to be shipped in the new packages, or dpkg will not be able to remove them on purge. like, ship them or she can't clean up after you. that's the whole deal ๐Ÿซ 

if a symlink is switched to a real directory, you need to make sure before unpacking that the symlink is removed. this may seem a simple change to the preinst script at first โ€” however that will result in some problems in case of admin local customization of the symlink or when downgrading the package. ๐Ÿ˜ญ

graceful renaming can be implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts:

dpkg-maintscript-helper symlink_to_dir \
   pathname old-target prior-version package -- "$@"

pathname is the absolute name of the old symlink (the path will be a directory at the end of the installation) and old-target is the target name of the former symlink at pathname. it can either be absolute or relative to the directory containing pathname. both valid, pick your fighter ๐Ÿ’…

Current implementation: the preinst checks if the symlink exists and points to old-target, if not then it's left in place, otherwise it's renamed to pathname.dpkg-backup. on configuration, the postinst removes pathname.dpkg-backup if pathname.dpkg-backup is still a symlink. on abort-upgrade/abort-install, the postrm renames pathname.dpkg-backup back to pathname if required. clean, tracked, reversible. she ate ๐Ÿ”ฅ

if a real directory is switched to a symlink, you need to make sure before unpacking that the directory is removed. this may seem a simple change to the preinst script at first โ€” however that will result in some problems in case the directory contains conffiles, pathnames owned by other packages, locally created pathnames, or when downgrading the package. that's a lot of problems. that's giving red flag ๐Ÿ˜ญ

graceful switching can be implemented by putting the following shell snippet in the preinst, postinst and postrm maintainer scripts:

dpkg-maintscript-helper dir_to_symlink \
   pathname new-target prior-version package -- "$@"

pathname is the absolute name of the old directory (the path will be a symlink at the end of the installation) and new-target is the target of the new symlink at pathname. it can either be absolute or relative to the directory containing pathname. same deal as before, no cap ๐ŸŽ€

Current implementation: the preinst checks if the directory exists, does not contain conffiles, pathnames owned by other packages, or locally created pathnames โ€” if not then it's left in place, otherwise it's renamed to pathname.dpkg-backup, and an empty staging directory named pathname is created, marked with a file so that dpkg can track it. on configuration, the postinst finishes the switch if pathname.dpkg-backup is still a directory and pathname is the staging directory; it removes the staging directory mark file, moves the newly created files inside the staging directory to the symlink target new-target/, replaces the now empty staging directory pathname with a symlink to new-target, and removes pathname.dpkg-backup. on abort-upgrade/abort-install, the postrm renames pathname.dpkg-backup back to pathname if required. the choreography?? impeccable. main character energy fr ๐Ÿ’œ


to be continued, bestie โ€” stay tuned ๐Ÿ’–โœจ

๐Ÿงš INTEGRATION IN PACKAGES ๐Ÿงš

Okay so if you're using a packaging helper, first check if it has native dpkg-maintscript-helper integration โ€” that might make your life easier. See dh_installdeb(1) for example.

Since dpkg-maintscript-helper is used in the preinst, using it unconditionally means you need a versioned pre-dependency so the required dpkg version is already unpacked. The exception is when we know we're upgrading from a release where the required dpkg version is going to be satisfied. The required version depends on the command: for rm_conffile and mv_conffile it's 1.15.7.2; for symlink_to_dir and dir_to_symlink it's 1.17.14. For example, if we required support for symlink_to_dir when upgrading from a release that had a dpkg version earlier than 1.17.14, we would need to add:

Pre-Depends: dpkg (>= 1.17.14)

But in many cases the operation done by the program is not critical for the package, and instead of using a pre-dependency we can call the program only if we know that the required command is supported by the currently installed dpkg:

if dpkg-maintscript-helper supports command; then
   dpkg-maintscript-helper command ...
fi

The supports command returns 0 on success, 1 otherwise. It checks if the environment variables as set by dpkg and required by the script are present, and it will consider it a failure if the environment is not sufficient. Basically it's a vibe check for your environment, bestie. ๐Ÿ’…

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

  • DPKG_ROOT โ€” if set, it will be used as the filesystem root directory.
  • DPKG_ADMINDIR โ€” if set, it will be used as the dpkg data directory.
  • DPKG_COLORS โ€” sets the color mode. The currently accepted values are: auto (default), always and never. Supported since dpkg 1.19.1.

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

dh_installdeb(1).


That's the whole page, bestie. This one's dpkg-maintscript-helper(1), version 1.23.11-dirty, dated 2026-09-09. Slay. ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from