.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "dpkg-maintscript-helper 1" .TH dpkg-maintscript-helper 1 2024-01-24 1.22.4 "dpkg suite" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME dpkg\-maintscript\-helper \- works around known dpkg limitations in maintainer scripts .SH SYNOPSIS .IX Header "SYNOPSIS" \&\fBdpkg-maintscript-helper\fR \&\fIcommand\fR [\fIparameter\fR...] \fB\-\-\fR \fImaint-script-parameter\fR... .SH "COMMANDS AND PARAMETERS" .IX Header "COMMANDS AND PARAMETERS" .IP "\fBsupports\fR \fIcommand\fR" 4 .IX Item "supports command" .PD 0 .IP "\fBrm_conffile\fR \fIconffile\fR [\fIprior-version\fR [\fIpackage\fR]]" 4 .IX Item "rm_conffile conffile [prior-version [package]]" .IP "\fBmv_conffile\fR \fIold-conffile\fR \fInew-conffile\fR [\fIprior-version\fR [\fIpackage\fR]]" 4 .IX Item "mv_conffile old-conffile new-conffile [prior-version [package]]" .IP "\fBsymlink_to_dir\fR \fIpathname\fR \fIold-target\fR [\fIprior-version\fR [\fIpackage\fR]]" 4 .IX Item "symlink_to_dir pathname old-target [prior-version [package]]" .IP "\fBdir_to_symlink\fR \fIpathname\fR \fInew-target\fR [\fIprior-version\fR [\fIpackage\fR]]" 4 .IX Item "dir_to_symlink pathname new-target [prior-version [package]]" .PD .SH DESCRIPTION .IX Header "DESCRIPTION" This program is designed to be run within maintainer scripts to achieve some tasks that \fBdpkg\fR can't (yet) handle natively either because of design decisions or due to current limitations. .PP Many of those tasks require coordinated actions from several maintainer scripts (\fBpreinst\fR, \fBpostinst\fR, \fBprerm\fR, \fBpostrm\fR). To avoid mistakes the same call simply needs to be put in all scripts and the program will automatically adapt its behavior based on the environment variable \fBDPKG_MAINTSCRIPT_NAME\fR and on the maintainer scripts arguments that you have to forward after a double hyphen. .PP This program was introduced in dpkg 1.15.7. .SH "COMMON PARAMETERS" .IX Header "COMMON PARAMETERS" .IP \fIprior-version\fR 4 .IX Item "prior-version" Defines the latest version of the package whose upgrade should trigger the operation. It is important to calculate \fIprior-version\fR correctly so that the operations are correctly performed even if the user rebuilt the package with a local version. If \fIprior-version\fR is empty or omitted, then the operation is tried on every upgrade (note: it's safer to give the version and have the operation tried only once). .Sp If the conffile has not been shipped for several versions, and you are now modifying the maintainer scripts to clean up the obsolete file, \&\fIprior-version\fR 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. This applies to all other actions in the same way. .Sp For example, for a conffile removed in version \fB2.0\-1\fR of a package, \&\fIprior-version\fR should be set to \fB2.0\-1~\fR. This will cause the conffile to be removed even if the user rebuilt the previous version \&\fB1.0\-1\fR as \fB1.0\-1local1\fR. Or a package switching a path from a symlink (shipped in version \fB1.0\-1\fR) to a directory (shipped in version \fB2.0\-1\fR), but only performing the actual switch in the maintainer scripts in version \fB3.0\-1\fR, should set \fIprior-version\fR to \fB3.0\-1~\fR. .IP \fIpackage\fR 4 .IX Item "package" The package name owning the pathname(s). When the package is \(lqMulti\-Arch: same\(rq this parameter must include the architecture qualifier, otherwise it should \fBnot\fR usually include the architecture qualifier (as it would disallow cross-grades, or switching from being architecture specific to architecture \fBall\fR or vice versa). If the parameter is empty or omitted, the \fBDPKG_MAINTSCRIPT_PACKAGE\fR and \fBDPKG_MAINTSCRIPT_ARCH\fR environment variables (as set by \fBdpkg\fR when running the maintainer scripts) will be used to generate an arch-qualified package name. .IP \fB\-\-\fR 4 .IX Item "--" All the parameters of the maintainer scripts have to be forwarded to the program after \fB\-\-\fR. .SH "CONFFILE RELATED TASKS" .IX Header "CONFFILE RELATED TASKS" When upgrading a package, \fBdpkg\fR will not automatically remove a conffile (a configuration file for which \fBdpkg\fR should preserve user changes) if it is not present in the newer version. There are two principal reasons for this; 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. 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. .PP This means that if a package is intended to rename or remove a conffile, it must explicitly do so and \fBdpkg-maintscript-helper\fR can be used to implement graceful deletion and moving of conffiles within maintainer scripts. .SS "Removing a conffile" .IX Subsection "Removing a conffile" \&\fBNote\fR: This can be replaced in most cases by the \f(CW\*(C`remove\-on\-upgrade\*(C'\fR flag in \fIDEBIAN/conffiles\fR (since dpkg 1.20.6), see \fBdeb\-conffiles\fR\|(5). .PP If a conffile is completely removed, it should be removed from disk, unless the user has modified it. If there are local modifications, they should be preserved. If the package upgrade aborts, the newly obsolete conffile should not disappear. .PP All of this is implemented by putting the following shell snippet in the \&\fBpreinst\fR, \fBpostinst\fR and \fBpostrm\fR maintainer scripts: .Sp .RS 4 dpkg-maintscript-helper rm_conffile \e \fIconffile\fR \fIprior-version\fR \fIpackage\fR \-\- "$@" .RE .PP \&\fIconffile\fR is the filename of the conffile to remove. .PP Current implementation: in the \fBpreinst\fR, it checks if the conffile was modified and renames it either to \fIconffile\fR\fB.dpkg\-remove\fR (if not modified) or to \fIconffile\fR\fB.dpkg\-backup\fR (if modified). In the \&\fBpostinst\fR, the latter file is renamed to \fIconffile\fR\fB.dpkg\-bak\fR and kept for reference as it contains user modifications but the former will be removed. If the package upgrade aborts, the \fBpostrm\fR reinstalls the original conffile. During purge, the \fBpostrm\fR will also delete the \&\fB.dpkg\-bak\fR file kept up to now. .SS "Renaming a conffile" .IX Subsection "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 \fBpreinst\fR script at first, however that will result in the user being prompted by \fBdpkg\fR to approve the conffile edits even though they are not responsible of them. .PP Graceful renaming can be implemented by putting the following shell snippet in the \fBpreinst\fR, \fBpostinst\fR and \fBpostrm\fR maintainer scripts: .Sp .RS 4 dpkg-maintscript-helper mv_conffile \e \fIold-conffile\fR \fInew-conffile\fR \fIprior-version\fR \fIpackage\fR \-\- "$@" .RE .PP \&\fIold-conffile\fR and \fInew-conffile\fR are the old and new name of the conffile to rename. .PP Current implementation: the \fBpreinst\fR checks if the conffile has been modified, if yes it's left on place otherwise it's renamed to \&\fIold-conffile\fR\fB.dpkg\-remove\fR. On configuration, the \fBpostinst\fR removes \fIold-conffile\fR\fB.dpkg\-remove\fR and renames \fIold-conffile\fR to \fInew-conffile\fR if \fIold-conffile\fR is still available. On abort\-upgrade/abort\-install, the \fBpostrm\fR renames \&\fIold-conffile\fR\fB.dpkg\-remove\fR back to \fIold-conffile\fR if required. .SH "SYMLINK AND DIRECTORY SWITCHES" .IX Header "SYMLINK AND DIRECTORY SWITCHES" When upgrading a package, \fBdpkg\fR will not automatically switch a symlink to a directory or vice-versa. Downgrades are not supported and the path will be left as is. .PP \&\fBNote\fR: The symlinks and directories created during these switches need to be shipped in the new packages, or \fBdpkg\fR will not be able to remove them on purge. .SS "Switching a symlink to directory" .IX Subsection "Switching a symlink to directory" 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 \fBpreinst\fR script at first, however that will result in some problems in case of admin local customization of the symlink or when downgrading the package. .PP Graceful renaming can be implemented by putting the following shell snippet in the \fBpreinst\fR, \fBpostinst\fR and \fBpostrm\fR maintainer scripts: .Sp .RS 4 dpkg-maintscript-helper symlink_to_dir \e \fIpathname\fR \fIold-target\fR \fIprior-version\fR \fIpackage\fR \-\- "$@" .RE .PP \&\fIpathname\fR is the absolute name of the old symlink (the path will be a directory at the end of the installation) and \fIold-target\fR is the target name of the former symlink at \fIpathname\fR. It can either be absolute or relative to the directory containing \fIpathname\fR. .PP Current implementation: the \fBpreinst\fR checks if the symlink exists and points to \fIold-target\fR, if not then it's left in place, otherwise it's renamed to \fIpathname\fR\fB.dpkg\-backup\fR. On configuration, the \fBpostinst\fR removes \fIpathname\fR\fB.dpkg\-backup\fR if \&\fIpathname\fR\fB.dpkg\-backup\fR is still a symlink. On abort\-upgrade/abort\-install, the \fBpostrm\fR renames \&\fIpathname\fR\fB.dpkg\-backup\fR back to \fIpathname\fR if required. .SS "Switching a directory to symlink" .IX Subsection "Switching a directory to symlink" 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 \fBpreinst\fR 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. .PP Graceful switching can be implemented by putting the following shell snippet in the \fBpreinst\fR, \fBpostinst\fR and \fBpostrm\fR maintainer scripts: .Sp .RS 4 dpkg-maintscript-helper dir_to_symlink \e \fIpathname\fR \fInew-target\fR \fIprior-version\fR \fIpackage\fR \-\- "$@" .RE .PP \&\fIpathname\fR is the absolute name of the old directory (the path will be a symlink at the end of the installation) and \fInew-target\fR is the target of the new symlink at \fIpathname\fR. It can either be absolute or relative to the directory containing \fIpathname\fR. .PP Current implementation: the \fBpreinst\fR 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 \fIpathname\fR\fB.dpkg\-backup\fR, and an empty staging directory named \fIpathname\fR is created, marked with a file so that dpkg can track it. On configuration, the \fBpostinst\fR finishes the switch if \fIpathname\fR\fB.dpkg\-backup\fR is still a directory and \&\fIpathname\fR is the staging directory; it removes the staging directory mark file, moves the newly created files inside the staging directory to the symlink target \fInew-target\fR/, replaces the now empty staging directory \fIpathname\fR with a symlink to \fInew-target\fR, and removes \fIpathname\fR\fB.dpkg\-backup\fR. On abort\-upgrade/abort\-install, the \fBpostrm\fR renames \&\fIpathname\fR\fB.dpkg\-backup\fR back to \fIpathname\fR if required. .SH "INTEGRATION IN PACKAGES" .IX Header "INTEGRATION IN PACKAGES" When using a packaging helper, please check if it has native \&\fBdpkg-maintscript-helper\fR integration, which might make your life easier. See for example \fBdh_installdeb\fR\|(1). .PP Given that \fBdpkg-maintscript-helper\fR is used in the \fBpreinst\fR, using it unconditionally requires a pre-dependency to ensure that the required version of \fBdpkg\fR has been unpacked before. The required version depends on the command used, for \fBrm_conffile\fR and \fBmv_conffile\fR it is 1.15.7.2, for \fBsymlink_to_dir\fR and \fBdir_to_symlink\fR it is 1.17.14: .Sp .Vb 1 \& Pre\-Depends: dpkg (>= 1.17.14) .Ve .PP 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 \fBdpkg\fR: .Sp .RS 4 if dpkg-maintscript-helper supports \fIcommand\fR; then dpkg-maintscript-helper \fIcommand\fR ... fi .RE .PP The command \fBsupports\fR will return 0 on success, 1 otherwise. The \&\fBsupports\fR command will check if the environment variables as set by dpkg and required by the script are present, and will consider it a failure in case the environment is not sufficient. .SH ENVIRONMENT .IX Header "ENVIRONMENT" .IP \fBDPKG_ROOT\fR 4 .IX Item "DPKG_ROOT" If set, it will be used as the filesystem root directory. .IP \fBDPKG_ADMINDIR\fR 4 .IX Item "DPKG_ADMINDIR" If set, it will be used as the \fBdpkg\fR data directory. .IP \fBDPKG_COLORS\fR 4 .IX Item "DPKG_COLORS" Sets the color mode (since dpkg 1.19.1). The currently accepted values are: \fBauto\fR (default), \fBalways\fR and \&\fBnever\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBdh_installdeb\fR\|(1).