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 DH_EXCLUDE_GREP same as DH_EXCLUDE, except all items are
82 separated by '|' characters, instead of spaces,
84 -x DH_INCLUDE_CONFFILES
85 include conffiles. It's -x for obscure
87 -d DH_D_FLAG you decide what this means to your program
88 -r DH_R_FLAG you decide what this means to your program
89 -k DH_K_FLAG you decide what this means to your program
90 -P DH_TMPDIR package build directory (implies only one
91 package is being acted on)
92 -u DH_U_PARAMS will be set to a string, that is typically
93 parameters your program passes on to some
95 -m DH_M_PARAMS will be set to a string, you decide what it
97 -V DH_V_FLAG will be set to a string, you decide what it
99 -V DH_V_FLAG_SET will be 1 if -V was specified, even if no
100 parameters were passed along with the -V
101 -A DH_PARAMS_ALL generally means that additional command line
102 parameters passed to the program (other than
103 those processed here), will apply to all
104 binary packages the program acts on, not just
106 --init-script DH_INIT_SCRIPT will be set to a string, which specifies an
107 init script name (probably only
108 dh_installinit will ever use this)
110 Any additional command line parameters that do not start with "-" will be
111 ignored, and you can access them later just as you normally would ($1, $2,
114 If you need a new command line option, just ask me, and I will add it.
119 The following variables are also set, you can use any of them:
121 MAINPACKAGE the name of the first binary package listed in
123 DH_FIRSTPACKAGE the first package we were instructed to act on. This package
124 typically gets special treatment, additional arguments
125 specified on the command line may effect it.
130 Dh_lib also contains a number of functions you may find useful.
133 Pass this function a string that is a shell command. It will run the
134 command (unless DH_NO_ACT is set), and if DH_VERBOSE is set, it will
135 also output the command to stdout. You should use this function for
136 almost all commands your program performs that manipulate files in
137 the package build directories.
139 This is the same as doit(), except you can pass more complicated
140 commands to it (ie, commands involving piping redirection)
142 Pass this command a string, and it will echo it if DH_VERBOSE is set.
144 Pass this command a string, it will output it to standard error and
147 Pass this command a string, and it will output it to standard error
148 as a warning message.
150 Pass this command the name of a binary package, it will return the
151 name of the tmp directory that will be used as this package's
152 package build directory. Typically, this will be "debian/tmp" or
155 Pass this command the name of a binary package, and the base name of a
156 file, and it will return the actual filename to use. This is used
157 for allowing debhelper programs to have configuration files in the
158 debian/ directory, so there can be one config file per binary
159 package. The convention is that the files are named
160 debian/package.filename, and debian/filename is also allowable for
161 the MAINPACKAGE. If the file does not exist, nothing is returned.
163 Pass this command the name of a binary package, and it will return
164 the name to prefix to files in debian/ for this package. For the
165 MAINPACKAGE, it returns nothing (there is no prefix), for the other
166 packages, it returns "package.".
168 Pass this command the name of a package, it returns 1 if the package
169 is a native debian package.
170 As a side effect, VERSION is set to the version number of the
175 2: filename of snippet
176 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
178 This command automatically adds shell script snippets to a debian
179 maintainer script (like the postinst or prerm).
184 Dh_lib is still evolving.
185 There will probably be a perl version too, in the future.
187 -- Joey Hess <joeyh@master.debian.org>