1 This file documents things you should know to write a new debhelper program.
6 There are lots of debhelper commands. To make the learning curve shallower,
7 I want them all to behave in a standard manner:
9 All debhelper programs have names beginning with "dh_". This is so we don't
10 pollute the name space too much.
12 Debhelper programs should never output anything to standard output except
13 error messages, important warnings, and the actual commands they run that
14 modify files under debian/ and debian/tmp, etc (this last only if they are
15 passed -v, and if you output the commands, you should indent them with 1 tab).
16 This is so we don't have a lot of noise output when all the debhelper commands
17 in a debian/rules are run, so the important stuff is clearly visible.
19 Debhelper programs should accept the options, -v, -i, -a, -p, --no-act, and
20 -P, and any long forms of these options, like --verbose . If necessary, the
21 options may be ignored.
23 If debhelper commands need config files, they should use
24 debian/package.filename as the name of the config file (replace filename
25 with whatever your command wants), and debian/filename should also be
26 checked for config information for the first binary package in
27 debian/control. Also, debhelper commands should accept the same sort of
28 information that appears in the config files, on their command lines, if
29 possible, and apply that information to the first package they act on.
31 Debhelper programs should never modify the debian/postinst, debian/prerm,
32 etc scripts, instead, they can add lines to debian/postinst.debhelper, etc.
33 The autoscript() function (see below) is one easy way to do this.
34 dh_installdeb is an exception, it will run after the other commands and
35 merge these modifications into the actual postinst scripts.
37 There are always exceptions. Just ask me.
42 All debhelper programs use the dh_lib library (actually it's a shell script)
43 to parse their arguments and set some useful variables. It's not mandatory
44 that your program use dh_lib, but it will make it a lot easier to keep it in
45 sync with the rest of debhelper if it does, so this is highly encouraged.
47 Typically, you invoke dh_lib like this:
49 PATH=debian:$PATH:/usr/lib/debhelper
52 The path statement is there to make your program look first in debian/ for
53 dh_lib (so users can install a modified version there if necessary), then the
54 rest of the path, then the canonical location of dh_lib, /usr/lib/debhelper.
59 All debhelper programs should respond to certain arguments, such as -v, -i,
60 -a, and -p. To help you make this work right, dh_lib handles argument
63 As soon as dh_lib loads, it processes any arguments that have been passed to
64 your program. The following variables may be set during this stage; your
65 program can use them later:
67 switch variable description
68 -v DH_VERBOSE should the program verbosely output what it is
70 --no-act DH_NO_ACT should the program not actually do anything?
71 -i,-a,-p DH_DOPACKAGES a space delimited list of the binary packages
73 -i,-p DH_DOINDEP a space delimited list of the binary independent
75 -a,-p DH_DOARCH a space delimited list of the binary dependent
77 -n DH_NOSCRIPTS if set, do not make any modifications to the
78 package's postinst, postrm, etc scripts.
79 -x DH_EXCLUDE exclude a something from processing (you
80 decide what this means for your program)
81 -d DH_D_FLAG you decide what this means to your program
82 -r DH_R_FLAG you decide what this means to your program
83 -k DH_K_FLAG you decide what this means to your program
84 -P DH_TMPDIR package build directory (implies only one
85 package is being acted on)
86 -u DH_U_PARAMS will be set to a string, that is typically
87 parameters your program passes on to some
89 -m DH_M_PARAMS will be set to a string, you decide what it
91 -V DH_V_FLAG will be set to a string, you decide what it
93 -V DH_V_FLAG_SET will be 1 if -V was specified, even if no
94 parameters were passed along with the -V
95 -A DH_PARAMS_ALL generally means that additional command line
96 parameters passed to the program (other than
97 those processed here), will apply to all
98 binary packages the program acts on, not just
100 --init-script DH_INIT_SCRIPT will be set to a string, which specifies an
101 init script name (probably only
102 dh_installinit will ever use this)
104 Any additional command line parameters that do not start with "-" will be
105 ignored, and you can access them later just as you normally would ($1, $2,
108 If you need a new command line option, just ask me, and I will add it.
113 The following variables are also set, you can use any of them:
115 MAINPACKAGE the name of the first binary package listed in
117 DH_FIRSTPACKAGE the first package we were instructed to act on. This package
118 typically gets special treatment, additional arguments
119 specified on the command line may effect it.
124 Dh_lib also contains a number of functions you may find useful.
127 Pass this function a string that is a shell command. It will run the
128 command (unless DH_NO_ACT is set), and if DH_VERBOSE is set, it will
129 also output the command to stdout. You should use this function for
130 almost all commands your program performs that manipulate files in
131 the package build directories.
133 This is the same as doit(), except you can pass more complicated
134 commands to it (ie, commands involving piping redirection)
136 Pass this command a string, and it will echo it if DH_VERBOSE is set.
138 Pass this command a string, it will output it to standard error and
141 Pass this command the name of a binary package, it will return the
142 name of the tmp directory that will be used as this package's
143 package build directory. Typically, this will be "debian/tmp" or
146 Pass this command the name of a binary package, and the base name of a
147 file, and it will return the actual filename to use. This is used
148 for allowing debhelper programs to have configuration files in the
149 debian/ directory, so there can be one config file per binary
150 package. The convention is that the files are named
151 debian/package.filename, and debian/filename is also allowable for
152 the MAINPACKAGE. If the file does not exist, nothing is returned.
154 Pass this command the name of a binary package, and it will return
155 the name to prefix to files in debian/ for this package. For the
156 MAINPACKAGE, it returns nothing (there is no prefix), for the other
157 packages, it returns "package.".
159 Pass this command the name of a package, it returns 1 if the package
160 is a native debian package.
161 As a side effect, VERSION is set to the version number of the
166 2: filename of snippet
167 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
169 This command automatically adds shell script snippets to a debian
170 maintainer script (like the postinst or prerm).
175 Dh_lib is still evolving.
176 There will probably be a perl version too, in the future.
178 -- Joey Hess <joeyh@master.debian.org>