LinuxCommandLibrary

dpkg-maintscript-helper

Help maintainer scripts during package installation/removal

SYNOPSIS

dpkg-maintscript-helper COMMAND [ARGS...]

PARAMETERS

symlink symlink target
    Creates symlink to target if absent; removes empty target dir if present

dir_to_symlink directory symlink
    Converts directory to symlink by moving contents and updating packages

rename oldpath newpath
    Renames oldpath to newpath, handling diversions and multiarch

remove_dir directory [directory...]
    Removes listed directories if empty and unowned by other packages

--debug
    Enable verbose debugging output

--help
    Display usage summary

--version
    Print version information

DESCRIPTION

The dpkg-maintscript-helper is a utility designed to assist Debian package maintainers in writing robust maintainer scripts (preinst, postinst, prerm, postrm). It performs common operations like creating symlinks, converting directories to symlinks, renaming files/directories, and removing empty directories in a safe, atomic manner.

It is aware of multiarch setups, conffiles, and other packages potentially using the same paths, preventing breakage during upgrades or removals. For example, it ensures symlinks are created only if absent and target directories are emptied safely.

Usage is integrated into package scripts via dpkg-maintscript-helper calls, often generated by debhelper tools like dh_installdeb. This abstracts complex logic, reducing errors in package maintenance. It logs actions verbosely under --debug and integrates with dpkg's database for precise handling.

Key benefits include idempotency (safe to run multiple times) and coordination across packages, making it essential for modern Debian packaging.

CAVEATS

Must be called from maintainer scripts with correct priority (e.g., upgrade handling); not for general user use. Fails if paths are conffiles or in use.

EXAMPLE USAGE

In postinst:
dpkg-maintscript-helper symlink /usr/lib/foo /usr/lib/foo-1.2 upgrade 1.2
Ensures symlink during upgrades from version 1.2.

EXIT CODES

0 on success; non-zero on failure (e.g., path conflicts). Integrates with debhelper for automatic script generation.

HISTORY

Introduced in dpkg 1.17.14 (2014) to standardize maintainer operations; evolved with multiarch support in later versions, now core to Debian packaging workflows.

SEE ALSO

dpkg(1), debhelper(7), dh_installdeb(1), dpkg-divert(1)

Copied to clipboard