{
    "content": [
        {
            "type": "text",
            "text": "# dpkg-maintscript-helper(1) (man)\n\n**Summary:** dpkg-maintscript-helper - works around known dpkg limitations in maintainer scripts\n\n**Synopsis:** dpkg-maintscript-helper command [parameter...] -- maint-script-parameter...\n\n## See Also\n\n- dhinstalldeb(1)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **COMMANDS AND PARAMETERS** (6 lines)\n- **DESCRIPTION** (9 lines)\n- **COMMON PARAMETERS** (31 lines)\n- **CONFFILE RELATED TASKS** (12 lines) — 2 subsections\n  - Removing a conffile (23 lines)\n  - Renaming a conffile (20 lines)\n- **SYMLINK AND DIRECTORY SWITCHES** (3 lines) — 2 subsections\n  - Switching a symlink to directory (22 lines)\n  - Switching a directory to symlink (27 lines)\n- **INTEGRATION IN PACKAGES** (23 lines)\n- **ENVIRONMENT** (10 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\ndpkg-maintscript-helper - works around known dpkg limitations in maintainer scripts\n\n### SYNOPSIS\n\ndpkg-maintscript-helper command [parameter...] -- maint-script-parameter...\n\n### COMMANDS AND PARAMETERS\n\nsupports command\nrmconffile conffile [prior-version [package]]\nmvconffile old-conffile new-conffile [prior-version [package]]\nsymlinktodir pathname old-target [prior-version [package]]\ndirtosymlink pathname new-target [prior-version [package]]\n\n### DESCRIPTION\n\nThis program is designed to be run within maintainer scripts to achieve some tasks that dpkg\ncan't (yet) handle natively either because of design decisions or due to current limitations.\n\nMany of those tasks require coordinated actions from several maintainer scripts (preinst,\npostinst, prerm, postrm). To avoid mistakes the same call simply needs to be put in all\nscripts and the program will automatically adapt its behaviour based on the environment\nvariable DPKGMAINTSCRIPTNAME and on the maintainer scripts arguments that you have to\nforward after a double hyphen.\n\n### COMMON PARAMETERS\n\nprior-version\nDefines the latest version of the package whose upgrade should trigger the operation. It\nis important to calculate prior-version correctly so that the operations are correctly\nperformed even if the user rebuilt the package with a local version. If prior-version is\nempty or omitted, then the operation is tried on every upgrade (note: it's safer to give\nthe version and have the operation tried only once).\n\nIf the conffile has not been shipped for several versions, and you are now modifying the\nmaintainer scripts to clean up the obsolete file, prior-version should be based on the\nversion of the package that you are now preparing, not the first version of the package\nthat lacked the conffile. This applies to all other actions in the same way.\n\nFor example, for a conffile removed in version 2.0-1 of a package, prior-version should\nbe set to 2.0-1~. This will cause the conffile to be removed even if the user rebuilt the\nprevious version 1.0-1 as 1.0-1local1. Or a package switching a path from a symlink\n(shipped in version 1.0-1) to a directory (shipped in version 2.0-1), but only performing\nthe actual switch in the maintainer scripts in version 3.0-1, should set prior-version to\n3.0-1~.\n\npackage\nThe package name owning the pathname(s).  When the package is “Multi-Arch: same” this\nparameter must include the architecture qualifier, otherwise it should not usually\ninclude the architecture qualifier (as it would disallow cross-grades, or switching from\nbeing architecture specific to architecture all or vice versa).  If the parameter is\nempty or omitted, the DPKGMAINTSCRIPTPACKAGE and DPKGMAINTSCRIPTARCH environment\nvariables (as set by dpkg when running the maintainer scripts) will be used to generate\nan arch-qualified package name.\n\n--  All the parameters of the maintainer scripts have to be forwarded to the program after\n--.\n\n### CONFFILE RELATED TASKS\n\nWhen upgrading a package, dpkg will not automatically remove a conffile (a configuration file\nfor which dpkg should preserve user changes) if it is not present in the newer version. There\nare two principal reasons for this; the first is that the conffile could've been dropped by\naccident and the next version could restore it, users wouldn't want their changes thrown\naway. The second is to allow packages to transition files from a dpkg-maintained conffile to\na file maintained by the package's maintainer scripts, usually with a tool like debconf or\nucf.\n\nThis means that if a package is intended to rename or remove a conffile, it must explicitly\ndo so and dpkg-maintscript-helper can be used to implement graceful deletion and moving of\nconffiles within maintainer scripts.\n\n#### Removing a conffile\n\nNote: This can be replaced in most cases by the \"remove-on-upgrade\" flag in DEBIAN/conffiles\n(since dpkg 1.20.6), see deb-conffiles(5).\n\nIf a conffile is completely removed, it should be removed from disk, unless the user has\nmodified it. If there are local modifications, they should be preserved. If the package\nupgrades aborts, the newly obsolete conffile should not disappear.\n\nAll of this is implemented by putting the following shell snippet in the preinst, postinst\nand postrm maintainer scripts:\n\n\ndpkg-maintscript-helper rmconffile \\\nconffile prior-version package -- \"$@\"\n\nconffile is the filename of the conffile to remove.\n\nCurrent implementation: in the preinst, it checks if the conffile was modified and renames it\neither to conffile.dpkg-remove (if not modified) or to conffile.dpkg-backup (if modified). In\nthe postinst, the latter file is renamed to conffile.dpkg-bak and kept for reference as it\ncontains user modifications but the former will be removed. If the package upgrade aborts,\nthe postrm reinstalls the original conffile. During purge, the postrm will also delete the\n.dpkg-bak file kept up to now.\n\n#### Renaming a conffile\n\nIf a conffile is moved from one location to another, you need to make sure you move across\nany changes the user has made. This may seem a simple change to the preinst script at first,\nhowever that will result in the user being prompted by dpkg to approve the conffile edits\neven though they are not responsible of them.\n\nGraceful renaming can be implemented by putting the following shell snippet in the preinst,\npostinst and postrm maintainer scripts:\n\n\ndpkg-maintscript-helper mvconffile \\\nold-conffile new-conffile prior-version package -- \"$@\"\n\nold-conffile and new-conffile are the old and new name of the conffile to rename.\n\nCurrent implementation: the preinst checks if the conffile has been modified, if yes it's\nleft on place otherwise it's renamed to old-conffile.dpkg-remove. On configuration, the\npostinst removes old-conffile.dpkg-remove and renames old-conffile to new-conffile if old-\nconffile is still available. On abort-upgrade/abort-install, the postrm renames old-\nconffile.dpkg-remove back to old-conffile if required.\n\n### SYMLINK AND DIRECTORY SWITCHES\n\nWhen upgrading a package, dpkg will not automatically switch a symlink to a directory or\nvice-versa. Downgrades are not supported and the path will be left as is.\n\n#### Switching a symlink to directory\n\nIf a symlink is switched to a real directory, you need to make sure before unpacking that the\nsymlink is removed. This may seem a simple change to the preinst script at first, however\nthat will result in some problems in case of admin local customization of the symlink or when\ndowngrading the package.\n\nGraceful renaming can be implemented by putting the following shell snippet in the preinst,\npostinst and postrm maintainer scripts:\n\n\ndpkg-maintscript-helper symlinktodir \\\npathname old-target prior-version package -- \"$@\"\n\npathname is the absolute name of the old symlink (the path will be a directory at the end of\nthe installation) and old-target is the target name of the former symlink at pathname. It can\neither be absolute or relative to the directory containing pathname.\n\nCurrent implementation: the preinst checks if the symlink exists and points to old-target, if\nnot then it's left in place, otherwise it's renamed to pathname.dpkg-backup. On\nconfiguration, the postinst removes pathname.dpkg-backup if pathname.dpkg-backup is still a\nsymlink. On abort-upgrade/abort-install, the postrm renames pathname.dpkg-backup back to\npathname if required.\n\n#### Switching a directory to symlink\n\nIf a real directory is switched to a symlink, you need to make sure before unpacking that the\ndirectory is removed. This may seem a simple change to the preinst script at first, however\nthat will result in some problems in case the directory contains conffiles, pathnames owned\nby other packages, locally created pathnames, or when downgrading the package.\n\nGraceful switching can be implemented by putting the following shell snippet in the preinst,\npostinst and postrm maintainer scripts:\n\n\ndpkg-maintscript-helper dirtosymlink \\\npathname new-target prior-version package -- \"$@\"\n\npathname is the absolute name of the old directory (the path will be a symlink at the end of\nthe installation) and new-target is the target of the new symlink at pathname. It can either\nbe absolute or relative to the directory containing pathname.\n\nCurrent implementation: the preinst checks if the directory exists, does not contain\nconffiles, pathnames owned by other packages, or locally created pathnames, if not then it's\nleft in place, otherwise it's renamed to pathname.dpkg-backup, and an empty staging directory\nnamed pathname is created, marked with a file so that dpkg can track it. On configuration,\nthe postinst finishes the switch if pathname.dpkg-backup is still a directory and pathname is\nthe staging directory; it removes the staging directory mark file, moves the newly created\nfiles inside the staging directory to the symlink target new-target/, replaces the now empty\nstaging directory pathname with a symlink to new-target, and removes pathname.dpkg-backup. On\nabort-upgrade/abort-install, the postrm renames pathname.dpkg-backup back to pathname if\nrequired.\n\n### INTEGRATION IN PACKAGES\n\nWhen using a packaging helper, please check if it has native dpkg-maintscript-helper\nintegration, which might make your life easier. See for example dhinstalldeb(1).\n\nGiven that dpkg-maintscript-helper is used in the preinst, using it unconditionally requires\na pre-dependency to ensure that the required version of dpkg has been unpacked before. The\nrequired version depends on the command used, for rmconffile and mvconffile it is 1.15.7.2,\nfor symlinktodir and dirtosymlink it is 1.17.14:\n\nPre-Depends: dpkg (>= 1.17.14)\n\nBut in many cases the operation done by the program is not critical for the package, and\ninstead of using a pre-dependency we can call the program only if we know that the required\ncommand is supported by the currently installed dpkg:\n\n\nif dpkg-maintscript-helper supports command; then\ndpkg-maintscript-helper command ...\nfi\n\nThe command supports will return 0 on success, 1 otherwise. The supports command will check\nif the environment variables as set by dpkg and required by the script are present, and will\nconsider it a failure in case the environment is not sufficient.\n\n### ENVIRONMENT\n\nDPKGROOT\nIf set, it will be used as the filesystem root directory.\n\nDPKGADMINDIR\nIf set, it will be used as the dpkg data directory.\n\nDPKGCOLORS\nSets the color mode (since dpkg 1.19.1).  The currently accepted values are: auto\n(default), always and never.\n\n### SEE ALSO\n\ndhinstalldeb(1).\n\n\n\n1.21.1                                       2025-09-09                   dpkg-maintscript-helper(1)\n\n"
        }
    ],
    "structuredContent": {
        "command": "dpkg-maintscript-helper",
        "section": "1",
        "mode": "man",
        "summary": "dpkg-maintscript-helper - works around known dpkg limitations in maintainer scripts",
        "synopsis": "dpkg-maintscript-helper command [parameter...] -- maint-script-parameter...",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "dhinstalldeb",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/dhinstalldeb/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COMMANDS AND PARAMETERS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "COMMON PARAMETERS",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "CONFFILE RELATED TASKS",
                "lines": 12,
                "subsections": [
                    {
                        "name": "Removing a conffile",
                        "lines": 23
                    },
                    {
                        "name": "Renaming a conffile",
                        "lines": 20
                    }
                ]
            },
            {
                "name": "SYMLINK AND DIRECTORY SWITCHES",
                "lines": 3,
                "subsections": [
                    {
                        "name": "Switching a symlink to directory",
                        "lines": 22
                    },
                    {
                        "name": "Switching a directory to symlink",
                        "lines": 27
                    }
                ]
            },
            {
                "name": "INTEGRATION IN PACKAGES",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "ENVIRONMENT",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}